【问题标题】:How to create sklearn random forest model identical to R randomForest?如何创建与 R randomForest 相同的 sklearn 随机森林模型?
【发布时间】:2016-01-03 17:44:29
【问题描述】:

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

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

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

【问题讨论】:

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


    【解决方案1】:
    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)
    

    看看那个代码。

    【讨论】:

      猜你喜欢
      • 2019-08-02
      • 2018-01-18
      • 2020-02-25
      • 2020-06-24
      • 2017-12-25
      • 2017-05-14
      • 2016-07-23
      • 2019-11-08
      • 1970-01-01
      相关资源
      最近更新 更多