'RandomForestClassifier' 对象在 python 中没有属性'oob_score_

数据挖掘 Python scikit-学习 随机森林
2021-09-24 21:12:53

我正进入(状态:

AttributeError: 'RandomForestClassifier' object has no attribute 'oob_score_'.oob_score_但我可以在sklearn随机森林分类器文档 中看到该属性。

param = [10,15,20,25,30, 40]  
# empty list that will hold cv scores
cv_scores = []
# perform 10-fold cross validation
for i in tqdm(param):
    clf = RandomForestClassifier(n_estimators = i, max_depth = None,bootstrap = True, oob_score = True)
    scores = clf.oob_score_
    cv_scores.append(scores)

错误

AttributeError                            Traceback (most recent call last)
<ipython-input-37-d6c9c54f299e> in <module>()
     15 for i in tqdm(param):
     16     clf = RandomForestClassifier(n_estimators = i, max_depth = None,bootstrap = True, oob_score = True)
---> 17     scores = clf.oob_score_
     18     cv_scores.append(scores)
     19 

AttributeError: 'RandomForestClassifier' object has no attribute 'oob_score_'
1个回答

这个 kaggle指南解释了随机森林。

设置warm_startTrue可能会为您解决问题。默认值为False