如何创建与R randomForest相同的sklearn随机森林模型?

时间:2015-10-06 17:40:55

标签: python r python-2.7 scikit-learn random-forest

在R中,我通常如下定义随机森林(一个例子):

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

现在我开始学习Python,我想知道如何在Python中使用相同的调整参数设置相同的模型?我知道sklearn RandomForestClassifier,但它似乎是用一组非常不同的参数定义的。

1 个答案:

答案 0 :(得分: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)

查看该代码。