6
$\begingroup$

I am getting:

AttributeError: 'RandomForestClassifier' object has no attribute 'oob_score_'. But I can see the attribute oob_score_ in sklearn random forest classifier documentation.

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)

ERROR

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_'
$\endgroup$
3
  • 4
    $\begingroup$ You have not used fit method. How can it return oob_score_? $\endgroup$ – Ankit Seth Aug 28 '18 at 10:59
  • $\begingroup$ Thanks! It worked.. oob_score_ is for Generalization accuracy but wat if i want to check the performance metric other than accuracy on cross validation data? $\endgroup$ – Harika M Aug 28 '18 at 11:05
  • $\begingroup$ @HarikaM Depends on your task. Choose that metric which best describes the output of your task. $\endgroup$ – Ankit Seth Aug 30 '18 at 5:41
2
$\begingroup$

This kaggle guide explains Random Forest.

Setting warm_start to True might give you a solution to your problem. The default value is False.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.