Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Random Forest feature_importances_ from OneVsRestClassifier for Multi-label classification

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?

like image 355
Joswin K J Avatar asked Jun 30 '15 11:06

Joswin K J


People also ask

Can random forest be used for multi label classification?

That is, a random forest averages a number of decision tree classifiers predicting multiple labels.

What is the difference between multi label and multiclass classification?

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.

What is OneVsRestClassifier?

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.

What is a Multilabel classification problem?

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.


1 Answers

OneVsRestClassifier has an attribute estimators_ : list of n_classes estimators

So to get the feature importance of the ith RandomForest

print clf.estimators_[i].feature_importances_
like image 135
yangjie Avatar answered Oct 26 '22 23:10

yangjie