Reputation: 31
I am getting an error
AttributeError: 'RandomForestClassifier' object has no attribute 'fit_transform'
However, there is a method named fit_transform(X,y) in sklearn.ensemble.RandomForestClassifier. This can be seen here I don't understand why I am getting this error and how do I resolve it. Here is the code snippet-
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)
Upvotes: 3
Views: 23219
Reputation: 399
There's no such method in the scikit-learn API documentation
To train your model and get predictions, you need to do like this
rf = RandomForestClassifier()
# train the model
rf.fit(X_train, y_train)
# get predictions
predictions = rf.predict(X_test)
Upvotes: 3