我多次使用Random Forest但从未遇到过此错误: ValueError:使用序列设置数组元素。
我的train_x数据框采用以下格式:
我如何更改格式,以便运行分类器?
我认为问题是tfidf和lda是作为矩阵给出的,但我已经将这些值转换为列表,这没有帮助。
from sklearn.ensemble import RandomForestClassifier
clf2 = RandomForestClassifier(random_state=1)
clf2.fit(train_x, train_y)
以下完整错误:
ValueError Traceback (most recent call last)
<ipython-input-111-7ae6360c296b> in <module>()
----> 1 clf2.fit(train_x, train_y)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\ensemble\forest.py in fit(self, X, y, sample_weight)
245 """
246 # Validate or convert input data
--> 247 X = check_array(X, accept_sparse="csc", dtype=DTYPE)
248 y = check_array(y, accept_sparse='csc', ensure_2d=False, dtype=None)
249 if sample_weight is not None:
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\utils\validation.py in check_array(array, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)
431 force_all_finite)
432 else:
--> 433 array = np.array(array, dtype=dtype, order=order, copy=copy)
434
435 if ensure_2d:
ValueError: setting an array element with a sequence.