我收到错误
AttributeError:'RandomForestClassifier'对象没有属性'fit_transform'
但是,sklearn.ensemble.RandomForestClassifier中有一个名为fit_transform(X,y)的方法。 This can be seen here 我不明白为什么我收到此错误,我该如何解决它。 这是代码段 -
from sklearn.ensemble import RandomForestClassifier
import pickle
import sys
import numpy as np
X1=np.array(pickle.load(open('X2g_train.p','rb')))
X2=np.array(pickle.load(open('X3g_train.p','rb')))
X3=np.array(pickle.load(open('X4g_train.p','rb')))
X4=np.array(pickle.load(open('Xhead_train.p','rb')))
X=np.hstack((X2,X1,X3,X4))
y = np.array(pickle.load(open('y.p','rb')))
rf=RandomForestClassifier(n_estimators=200)
Xr=rf.fit_transform(X,y)
答案 0 :(得分:2)
scikit-learn API documentation
中没有这样的方法要训练你的模型并获得预测,你需要这样做
rf = RandomForestClassifier()
# train the model
rf.fit(X_train, y_train)
# get predictions
predictions = rf.predict(X_test)