【发布时间】:2016-04-18 03:32:07
【问题描述】:
我正在使用 lib UnbalancedDataset 进行一些过采样。
我有 X_train_features.shape (30962, 15637) 和 y_train.shape (30962,)
type(X_train_features) 是scipy.sparse.csr.csr_matrix
获取索引错误:
IndexError Traceback (most recent call last)
<ipython-input-44-fa5e3a9ff626> in <module>()
5 os = OverSampler(ratio=ratio, verbose=verbose)
6
----> 7 osx, osy = os.fit_transform(X_train_features, y_train)
C:\Python27\lib\site-packages\unbalanceddataset-0.1-py2.7.egg\unbalanced_dataset\unbalanced_dataset.pyc in fit_transform(self, x, y)
260
261 self.fit(x, y)
--> 262 self.out_x, self.out_y = self.resample()
263
264 return self.out_x, self.out_y
C:\Python27\lib\site-packages\unbalanceddataset-0.1-py2.7.egg\unbalanced_dataset\over_sampling.pyc in resample(self)
52
53 # Start with the majority class
---> 54 overx = self.x[self.y == self.maxc]
55 overy = self.y[self.y == self.maxc]
56
C:\Python27\lib\site-packages\scipy\sparse\csr.pyc in __getitem__(self, key)
305 row, col = self._index_to_arrays(row, col)
306
--> 307 row = asindices(row)
308 col = asindices(col)
309 if row.shape != col.shape:
C:\Python27\lib\site-packages\scipy\sparse\csr.pyc in asindices(x)
224 x = x.astype(idx_dtype)
225 except:
--> 226 raise IndexError('invalid index')
227 else:
228 return x
IndexError: invalid index
我调试到lib中,发现self.x[self.y == self.maxc]等于
X_train_features[y_train == 1]
我猜这个语句是选择
X_train_features中的所有y_train == 1行,不是吗?如何克服这个错误?
【问题讨论】:
-
已经有一个issue 对此开放。等待维护者,或尝试自己调试。
-
@toasted_flakes 问题是我打开的......我发布这个问题是为了我自己解决这个问题。问题只是告诉所有者他的库可能有错误。
-
哦,我没想到是你。那么祝你好运:)
标签: python numpy scipy scikit-learn