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?
That is, a random forest averages a number of decision tree classifiers predicting multiple labels.
Difference between multi-class classification & multi-label classification is that in multi-class problems the classes are mutually exclusive, whereas for multi-label problems each label represents a different classification task, but the tasks are somehow related.
OneVsRestClassifier(estimator, *, n_jobs=None, verbose=0)[source] One-vs-the-rest (OvR) multiclass strategy. Also known as one-vs-all, this strategy consists in fitting one classifier per class. For each classifier, the class is fitted against all the other classes.
Classification is a predictive modeling problem that involves outputting a class label given some input. It is different from regression tasks that involve predicting a numeric value. Typically, a classification task involves predicting a single label.
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_
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With