Klausos Klausos
Klausos Klausos

Reputation: 16050

How to create sklearn random forest model identical to R randomForest?

In R I usually define Random Forest as follows (an example):

rf <- randomForest(train[,features], 
                   train$Y,
                   mtry=5,
                   ntree=15,
                   sampsize=50000,
                   do.trace=TRUE)

Now I started learning Python and I wonder how to set the same model with same tuning parameters in Python? I know about sklearn RandomForestClassifier, but it seems to be defined with a very different set of parameters.

Upvotes: 1

Views: 1663

Answers (1)

Nikos Epitropakis
Nikos Epitropakis

Reputation: 71

from sklearn.ensemble import RandomForestClassifier
#create the classifier and tune the parameters (more on the documentations)
rf = RandomForestClassifier(n_estimators= 25, max_depth= None,max_features = 0.4,random_state= 11 )
#fit the data
rf.fit(train, targets_train)
#make the prediction on the unseen data
prediction =rf.predict(test)

Have a look on that code.

Upvotes: 3

Related Questions