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'))
当我运行这个我得到这个错误:
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'))
现在,我有以下例外:
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
有什么建议可以解决这个问题吗?