3

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)
1
  • The documentation you are using is for a very old version of scikit. Seems like you dont have that version installed. Commented Mar 21, 2018 at 8:57

1 Answer 1

3

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.