简体   繁体   English

随机森林提高准确性

[英]Random Forest Improve Accuracy

I'm using RandomForestClassifier method for object detection the problem is that even i know that my random state should be zero as default i got very bad accuracy, so is there anyway to know what is the best values for my n_estimators, random_state parameters?我正在使用 RandomForestClassifier 方法进行 object 检测问题是,即使我知道我的随机 state 默认应该为零,但我的准确度非常差,所以无论如何要知道我的 n_estimators、random_state 参数的最佳值是多少?

from sklearn.ensemble import RandomForestClassifier
RF_model = RandomForestClassifier(n_estimators = 250, random_state = 120)

To determine the best parameters for a model, you can use a process known as Grid Search.要确定 model 的最佳参数,您可以使用称为网格搜索的过程。 Sklearn provides a class for performing this, GridSearchCV . Sklearn 提供了一个 class 来执行此操作, GridSearchCV I've provided a code sample of how to use it for the Random Forest classifier.我提供了一个代码示例,说明如何将它用于随机森林分类器。

from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import GridSearchCV

# provide iterables of values to be tested each parameter
parameters = {'n_estimators': [100, 250, 500, 750]}
clf = GridSearchCV(RandomForestClassifier(), parameters)
clf.fit(X, y)  # X and y are your training data and targets

It is worth noting that in your question you mention specifically looking for the best values for the n_estimators and random_state parameters.值得注意的是,在您的问题中,您提到专门寻找n_estimatorsrandom_state参数的最佳值。 I have not included the random_state as part of the GridSearch as that parameter is typically present for the reproducibility of results.我没有将random_state作为 GridSearch 的一部分包括在内,因为该参数通常用于结果的可重复性。 Here's someadditonal reading from Sklearns Glossary on that parameter.这是 Sklearns Glossary 关于该参数的一些附加读物

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM