What is matthews correlation coefficient (MCC) ?

Maroua Wissem CHANBI
5 min readDec 13, 2022

--

Hellllooooo again guys^^

wish everything is great 🤗😍

SO , in the previous article, we’ve took an idea about some evaluation metrics, and the necessity of choosing them correctly to avoid any unexpected mistakes after deployment , but a small explanation remained about one of these metrics, ( the most neglected one btw ) . So I will complete the rest in this post

have an enjoyable read ! ✨

1 - Introduction :

With each new experiment in deep learning , practitioners and researchers keeps racing to find the most profitable and advantageous computations form which succeeds in finding the best relationship between the data they provide , this is done by selecting one or several models from among those experimented that their performance is as close as possible to that of humans , and this selection process is done using what are called evaluation metrics .

2 - what are evaluation metrics ?

evaluation metrics are measures that tells you how accurately each model can be expected to perform on a given data set , using them is critical for ensuring an optimal operating of the model .
yet , the choice of these metrics depends on the goal that the one is trying to achieve along with some conditions including volume , quality and availability of data , for example if you are interested in predicting both classes correctly and your dataset is sufficiently balanced , accuracy can be a good choice since it determines the proportion of the total number of predictions that were correct .

accuracy formula

However, you may know that the most adopted ones are f1score and accuracy , but despite their deep-rooted use, they tend to give overly optimistic results most of the time, especially on imbalanced datasets as we have already discussed in our previous article.

I suggest you check it out:
https://medium.com/@maroua.wissem.chanbi77/should-you-always-rely-on-accuracy-for-evaluating-your-model-33323df10726

So what metric should we use now ?

.

.

.

no worries …. here where it comes the icebreaker ❄❄❄ , the MCC metric .

The MCC (matthew correlation coefficient) is a statistical metric generally used for binary classification it ranges between -1 and +1 and it broadens its consideration to all the confusion matrix values , ie. It returns good results only if the outcome of all the four confusion matrix values ( tp , tn , fp , fn) are good contrary to accuracy and f1 score , in essence we can say that this is the metric of most reliable and truthful assessment , especially for biological applications.

here is its formula:

the mcc formula

we notice that in the numerator we find both CM diagonals (as illustrated in the img bellow) , the product of misclassified instances subtracted from the product of a well-classified ones , whereas the denominator will be just a positive constant value in the aim of normalizing the output Thus the result will ranges in between -1 ,and +1.

confusion matrix diagonals

3 - MCC limits :

the result of this metric can be divided into 3 case :

1 - MCC = +1 :

  • the result will be eqaul to +1 only if ( FP == FN == 0 / TP == TN == 1 )i.e all results are predicted correctly which is the best case .
from sklearn.metrics import matthews_corrcoef
y_true = [+1, +1, +1, +1 , +1,+1,-1,-1,-1,+1,+1,+1]
y_pred = [+1, +1, +1, +1 ,+1 ,+1,-1,-1,-1,+1,+1,+1]
matthews_corrcoef(y_true, y_pred)

1.0

2 - MCC = 0 :

  • only if the (TP * TN == FP * FP) which means that the model is not able to differentitate between the two classes , not far from being random .
from sklearn.metrics import matthews_corrcoef
y_true = [+1, +1, -1, +1 , -1,+1,-1,-1,+1,+1,+1,+1]
y_pred = [+1, +1, +1, +1 , +1,+1,-1,+1,-1,-1,+1,+1]
matthews_corrcoef(y_true, y_pred)

0.0

3 - MCC = -1 :

  • the result will be eqaul to -1 only if (TP == TN == 0 / FP == FN == 1 ) i.e all results are inverted and it’s the worst scenario .
from sklearn.metrics import matthews_corrcoef
y_true = [+1, +1, -1, +1 , -1 ,+1,-1,-1,+1,+1,+1,+1]
y_pred = [-1, -1, +1, -1 , +1 ,-1,+1,+1,-1,-1,-1,-1]
matthews_corrcoef(y_true, y_pred)

-1.0

4 - Why using MCC ? and not just f1 score ?

Well , This question has always been hovering on the horizon. Here are 2 advantages of using mcc over f1 score :

  • since its range begins from -1 , it enables you to recognize the extreme case of anti diagonal confusion matrix (the case of inverted results).
  • It is class invariant , this means that no matter which class you consider as negative or positive it won’t affect the outcome , whereas in the f1 score since it ignores the count of true negatives it will be class variant (results changes by changing the class type (negative or positive)).

5 - conclusion :

Finally , we have come to the end of our post 🎉🎉🎉✨✨✨✨🎆🎆

I really hope that you have benefited from the explanation and gain some new informations

all my thanks to you for your interest and read .

best wishes 🥰

References :

https://www.youtube.com/watch?v=u-Ez7trpNrM

https://deepai.org/machine-learning-glossary-and-terms/evalua

--

--

Maroua Wissem CHANBI
Maroua Wissem CHANBI

Written by Maroua Wissem CHANBI

Deep learning & computer vision engineer | Algeria | Data And Beyond Author | for research opporunities contact me at : marufoxyyy@gmail.com

No responses yet