0
$\begingroup$

This post explains that micro precision is the same as weighted precision. (And the logic applies to recall and f-score as well.)

So why does sklearn.metrics list micro and weighted as separate options? For example at https://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_score.html#sklearn.metrics.precision_score

the possible values for the average argument are ‘micro’, ‘macro’, ‘samples’, ‘weighted’, ‘binary’}. How are micro and weighted any different?

$\endgroup$

1 Answer 1

1
$\begingroup$

I assume you mean why "macro" and "weighted" precision are same in the above example. "weighted" precision is actually a weighted version of "macro" precision. The above example illustrates the case where the classes are balanced (2 for each class: 0, 1, 2). However, if the classes are imbalanced (the code below), then the "macro" precision will be different for "weighted" one.

y_true = [2, 2, 2, 2, 1, 0]
y_pred = [2, 2, 1, 0, 2, 2]
print(precision_score(y_true, y_pred, average='macro')) #0.167
print(precision_score(y_true, y_pred, average='weighted')) #0.333

Basically, the function precision_score will first calculate the precision for each class. Then, it uses np.average() with the weight attribute to be the number of positive examples in each class. If the classes are well-balanced, meaning the number of examples in each class is exactly the same, then "macro" and "weighted" precision will be the same. Otherwise, "weighted" precision will be higher than "macro" precision.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.