How can I use weighted log_loss as SCORING function for linear_model.SGDClassifier?

Viewed 831

I am using

linear_model.SGDClassifier(loss='log',class_weight='balanced')

for 10 classes classification (the classes are very unbalanced).

It looks like that class_weight is used only at training time (in the loss function). They are not used for scoring. Thus, I am using

GridSearchCV(test_model, my_hyperparameters, scoring='f1_macro')

since 'f1_macro' it calculates "metrics for each label, and find their unweighted mean. This does not take label imbalance into account."

I would like to use 'neg_log_loss' as scoring. So, I would have:

GridSearchCV(test_model, my_hyperparameters, scoring='neg_log_loss').

Is it possible to make it weighted?

In the docs I see:

sklearn.metrics.log_loss(y_true, y_pred, eps=1e-15, normalize=True, sample_weight=None, labels=None).

But how can I pass "sample_weight" in

GridSearchCV(test_model, my_hyperparameters, scoring='neg_log_loss')?

0 Answers
Related