Reputation: 710
I am using OneVsRestClassifier for a multi-label classification problem. I am passing RandomForestClassifier into it.
from sklearn.multiclass import OneVsRestClassifier
from sklearn.ensemble import RandomForestClassifier
clf = OneVsRestClassifier(RandomForestClassifier(random_state=0,class_weight='auto',min_samples_split=10,n_estimators=50))
clf.fit(train,dv_train)
print clf.feature_importances_
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'OneVsRestClassifier' object has no attribute 'feature_importances_'
How can I get the feature importance of each Random Forests in the OneVsRestClassifier?
Upvotes: 6
Views: 4127
Reputation: 6715
OneVsRestClassifier
has an attribute estimators_
: list of n_classes estimators
So to get the feature importance of the i
th RandomForest
print clf.estimators_[i].feature_importances_
Upvotes: 9