nde*_*mir 3 python numpy scikit-learn
lr = lm.LogisticRegression(penalty='l2', dual=True, tol=0.0001,
C=1, fit_intercept=True, intercept_scaling=1.0,
class_weight=None, random_state=None)
rd = AdaBoostClassifier( base_estimator=lr,
learning_rate=1,
n_estimators=20,
algorithm="SAMME")
##here, i am deleting unnecesseary objects
##print X.shape
##(7395, 412605)
print "20 Fold CV Score: ", np.mean(cross_validation.cross_val_score(rd, X, y, cv=20, scoring='roc_auc'))
Run Code Online (Sandbox Code Playgroud)
当我运行这个我得到这个错误:
TypeError:传递了稀疏矩阵,但需要密集数据.使用X.toarray()转换为密集的numpy数组.
然后,我改变了我的代码:
print "20 Fold CV Score: ", np.mean(cross_validation.cross_val_score(rd, X.toarray(), y, cv=20, scoring='roc_auc'))
Run Code Online (Sandbox Code Playgroud)
现在,我有以下例外:
File "/usr/lib/python2.7/dist-packages/scipy/sparse/compressed.py", line 559, in toarray
return self.tocoo(copy=False).toarray(order=order, out=out)
File "/usr/lib/python2.7/dist-packages/scipy/sparse/coo.py", line 235, in toarray
B = self._process_toarray_args(order, out)
File "/usr/lib/python2.7/dist-packages/scipy/sparse/base.py", line 628, in _process_toarray_args
return np.zeros(self.shape, dtype=self.dtype, order=order)
MemoryError
Run Code Online (Sandbox Code Playgroud)
有什么建议可以解决这个问题?
Dou*_*gal 12
MemoryError表示系统上没有足够的RAM可用于分配矩阵.为什么?好吧,7395 x 412605矩阵有3,051,213,975个元素.如果它们是默认的float64(通常double是C)数据类型,则为22.7GB.如果转换为低精度float32s(通常float在C中),则为11.4GB; 也许这可以在你的机器上操作.不过,它仍然会很慢.
它似乎AdaBoostClassifier不支持稀疏输入(正如您在此处的代码中所见).我不知道算法是否需要密集表示,或者只是实现假设.
| 归档时间: |
|
| 查看次数: |
7162 次 |
| 最近记录: |