我正在使用lib UnbalancedDataset來執行一些過採樣。asindices(x)中的scipy sparse csr.pyc獲取IndexError:無效索引
我有X_train_features.shape
(30962,15637)和y_train.shape
(30962)
type(X_train_features)
是scipy.sparse.csr.csr_matrix
GET指數錯誤:
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
行,不是嗎?如何克服這個錯誤?
有已經是一個[問題](https://github.com/fmfn/UnbalancedDataset/issues/26)開放這一點。等待維護者,或者嘗試自己調試它。 –
@toasted_flakes問題是我打開了......我發佈這個問題試圖解決它我的自我。問題只是告訴老闆,他的lib有一個bug。 – Mithril
哦,我沒有意識到這是你。祝你好運然後:) –