2015-10-06 2 views
1

В R я обычно определяют случайный лес следующим образом (пример):Как создать случайную модель леса sklearn, идентичную R randomForest?

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

Теперь я начал изучать Python, и мне интересно, как установить ту же модель с теми же параметрами настройки в Python? Я знаю о sklearn RandomForestClassifier, но, похоже, он определен с очень различным набором параметров.

ответ

3
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) 

Посмотрите на этот код.