随机森林分类器批量学习 Python 维度误差
Random Forest Classifier Batch Learning Python Dimension Error
我有一个大型数据框,其中包含大约一百万条记录和 19 个特征(+1 个目标变量)。由于内存错误,我无法训练我的 RF classifier(这是一个 multi-class classification,大约有 750 classes)因此我求助于批量学习.该模型训练得很好,但是当我 运行 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)
如有任何帮助,我将不胜感激。也欢迎任何其他建议。
找到答案了。这是由于数据批次中 y 变量 类 的不一致而发生的。
我有一个大型数据框,其中包含大约一百万条记录和 19 个特征(+1 个目标变量)。由于内存错误,我无法训练我的 RF classifier(这是一个 multi-class classification,大约有 750 classes)因此我求助于批量学习.该模型训练得很好,但是当我 运行 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)
如有任何帮助,我将不胜感激。也欢迎任何其他建议。
找到答案了。这是由于数据批次中 y 变量 类 的不一致而发生的。