【发布时间】:2019-02-11 03:28:40
【问题描述】:
这是我在调用todense() 时出现的代码和内存错误,我使用的是 GBDT 模型,想知道是否有人对如何解决内存错误有好的想法?谢谢。
for feature_colunm_name in feature_columns_to_use:
X_train[feature_colunm_name] = CountVectorizer().fit_transform(X_train[feature_colunm_name]).todense()
X_test[feature_colunm_name] = CountVectorizer().fit_transform(X_test[feature_colunm_name]).todense()
y_train = y_train.astype('int')
grd = GradientBoostingClassifier(n_estimators=n_estimator, max_depth=10)
grd.fit(X_train.values, y_train.values)
详细的错误信息,
in _process_toarray_args
return np.zeros(self.shape, dtype=self.dtype, order=order)
MemoryError
...
问候, 林
【问题讨论】:
-
你得到的错误究竟是什么?
-
你尝试过不使用密集数组吗?
-
@LinMa:那是因为试图将稀疏矩阵分配给数据框列,就好像它是一个数组一样。
-
默认情况下
CountVectorizer.fit提供稀疏矩阵,但是当您尝试转换为密集数组时会占用大量内存,如果您的系统没有太多内存,则会出现内存错误 -
您的系统有多少内存?以及数组的理论大小是多少(即
X_train和X_test的尺寸是多少)?
标签: python machine-learning scikit-learn xgboost