Gridsearchcv For Multi-label Classification For Each Label Separately
I am doing multi-label classification using scikit learn. I am using RandomForestClassifier as the base estimator. I want to optimize the parameters of it for each label using Grid
Solution 1:
It's not hard to do that, though it is not built-in and I'm not sure I understand why you would want to.
Simply pre-process your data like so:
for a_class in list_of_unique_classes:
y_this_class = (y_all_class==a_class)
model_to_tune = RandomForestClassifier(random_state=0,class_weight='auto')
model_tuned = GridSearchCV(model_to_tune, param_grid=params, scoring='f1',n_jobs=2)
model_tuned.fit( X, y_this_class )
# Save the best parameters for this class
(Also, beware f1 score, it does not do a good job of describing performance of a classifier for skewed data sets. You want to use ROC curves and/or informedness).
Post a Comment for "Gridsearchcv For Multi-label Classification For Each Label Separately"