【问题标题】:Random Forest Classifier Batch Learning Python Dimension Error随机森林分类器批量学习 Python 维度错误
【发布时间】:2020-08-08 02:33:10
【问题描述】:

我有一个包含大约一百万条记录和 19 个特征(+1 个目标变量)的大型数据框。由于内存错误(它是一个包含大约 750 个类的多类分类),我无法训练我的 RF 分类器,因此我求助于批量学习。该模型训练良好,但是当我运行 model.predict 命令时,它给了我以下 ValueError

ValueError: operands could not be broadcast together with shapes (231106,628) (231106,620) (231106,628).

我的代码如下:

#Splitting into Dependent and Independent Variables

X= df.iloc[:,1:]
y= df.iloc[:,0]

#Train-test Split

train_X, test_X, train_y, test_y = train_test_split(X,y,test_size=0.25,random_state=1234) 

data_splits= zip(np.array_split(train_X,6),np.array_split(train_y,6))

rf_clf= RandomForestClassifier(warm_start=True, n_estimators=1,criterion='entropy',random_state=1234)

for i in range(10): #10 passes through the data
    for X,y in data_splits:
        rf_clf.fit(X,y)
        rf_clf.n_estimators +=1 # increment by one, so next will add 1 tree

y_preds= rf_clf.predict(test_X)

如果能提供任何帮助,我将不胜感激。也欢迎任何其他建议。

【问题讨论】:

  • 打印text_X的形状
  • test_X 形状为 (231106,19)
  • 为什么要在每个连续拆分中添加 1 个估算器?为什么不同时运行它们?

标签: python scikit-learn random-forest multiclass-classification


【解决方案1】:

找到了答案。这是由于数据批次中 y 变量类的不一致造成的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-24
    • 1970-01-01
    • 2016-10-20
    • 2019-06-23
    • 2017-01-05
    • 2013-12-12
    • 1970-01-01
    • 2014-08-19
    相关资源
    最近更新 更多