question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Macro-averaged MAE

See original GitHub issue

Describe the workflow you want to enable

For ordinal classification, we can use multiple metrics, for example: MAE, MSE… As we would use for regression. But when these classes are imbalanced, one way to deal with imbalance is to use macro-averaged MAE instead, as described here https://stats.stackexchange.com/questions/338904/measures-of-ordinal-classification-error-for-ordinal-regression and here https://www.computer.org/csdl/proceedings-article/2009/isda/3872a283/12OmNybfrbj .

The macro-averaged MAE is like the “classic” MAE, except we compute each MAE for each class and average them, giving equal weights to MAEs. Note that macro-averaged MAE == micro-averaged (or classic) MAE when class are balanced.

To illustrate this, let’s consider:

y_true_balanced = np.array([1, 1, 1, 2, 2, 2])
y_true_imbalanced = np.array([1, 1, 1, 1, 1, 2])
y_pred = np.array([1, 2, 1, 2, 1, 2])

mean_absolute_error(y_true_balanced, y_pred)
>> 0.33
mean_absolute_error(y_true_imbalanced, y_pred)
>> 0.33
macro_averaged_mean_absolute_error(y_true_balanced, y_pred)
>> 0.33
macro_averaged_mean_absolute_error(y_true_imbalanced, y_pred)
>> 0.2

Describe your proposed solution

I coded it, the natural way would be to modify sklearn.metrics.mean_absolute_error directly, by adding a parameter average='macro' for macro-averaged-MAE, and average='micro' for normal (=micro-averaged)MAE… But MAE is 99,9% of the time used for regression, not for ordinal classification, and as macro-averaged MAE is used only for ordinal classification, I am afraid that would be confusing.

That is why I would propose to add it in its own package, sklearn.metrics.macro_averaged_mean_absolute_error.

What do you think, before I propose the associated MR?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
glemaitrecommented, Nov 24, 2020

It might be confusing to introduce the metric in scikit-learn since MAE would refer to both classification and regression in some ways. However, it would be a perfect addition in imbalanced-learn because this the actual scope of the library and one will not use it without knowing its specificity. I would be really keen to get the implementation in the library there.

1reaction
glemaitrecommented, Nov 24, 2020

I am closing this issue then and making a review on the other side 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

macro_averaged_mean_absolut...
Compute Macro-Averaged MAE for imbalanced ordinal classification. This function computes each MAE for each class and average them, giving an equal weight to ......
Read more >
Micro Average vs Macro average Performance in a Multiclass ...
In macroaveraging, we compute the performance for each class, ... and shows the computation of microaveraged and macroaveraged precision.
Read more >
Performance curves in MAE (Mean Absolute Error). The ...
The vertical axis in graph (a) is the microaveraged MAE, and in graph (b) is the macro-averaged MAE. A lower value in MAE...
Read more >
3.3. Metrics and scoring: quantifying the quality of predictions
macro-averaged ... of the i -th sample, and y i is the corresponding true value, then the mean absolute error (MAE) estimated over...
Read more >
Recall_macro: Recall (macro averaged) in LqNoob/Machine ...
Compute the recall score of multi-class problem using the "macro" average. details: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found