使用sklearn在随机森林中自动超参数调整?

是否有一种使用GridSearch自动调整随机森林分类器的方法。我们没有提供这些值,而是有任何方法可以找到最佳的最佳参数值。使用sklearn在随机森林中自动超参数调整?

rfc = RandomForestClassifier(n_jobs=-1, max_features='sqrt', oob_score = True) 

# Use a grid over parameters of interest

param_grid = {

"n_estimators" : [9, 18, 27, 36, 45, 54, 63],

"max_depth" : [1, 5, 10, 15, 20, 25, 30],

"min_samples_leaf" : [1, 2, 4, 6, 8, 10]}

CV_rfc = GridSearchCV(estimator=rfc, param_grid=param_grid, cv= 10)

CV_rfc.fit(train_x, train_y)

print CV_rfc.best_params_

回答:

是的,你几乎在那里。您已使用您的print CV_rfc.best_params_系列确定了最佳的RF参数集。

您的CV_rfc对象在运行CV_rfc.fit(train_x, train_y)后,已经在您的所有列车数据中重新安装了RF模型,并找到了最佳的RF参数集。您可以使用CV_rfc.best_estimator_访问“最佳模型”(除非在适合Gridsearch对象时设置refit=False)。

所以,你可以用你的测试数据是最好的估计新的预测与 CV_rfc.best_estimator_.predict(test_x),或作为一种方便甚至CV_rfc.predict(test_x)

这是值得花更多的时间与documentation

以上是 使用sklearn在随机森林中自动超参数调整? 的全部内容, 来源链接: utcz.com/qa/262214.html

回到顶部