TransWikia.com

How I can compute Matthews Correlation Coefficient?

Data Science Asked by Vilanova on May 26, 2021

I want to calculate MCC, I have two CSV files: result.csv and true.csv

result.csv format:

                   id | prob_class1 | prob_class2 | prob_class3 | prob_class4
                    1 |0.34         | 0.4         | 0.32        |0.77
                    2 |0.84         | 0.4         | 0.2         |0.7

true.csv format:

                     id | prob_class1 | prob_class2 | prob_class3 | prob_class4
                     1 |0            | 0           | 1           |0
                     2 |0            | 1           | 0           |0
                     3 |0            | 0           | 0           |1

result.csv is the output of the multi-classification problem, true.csv is the true result. How I can calculate the Matthews Correlation Coefficient?

2 Answers

Here are the high-level steps:

  1. Load the .csv from disk into an array in memory.
  2. Threshold the probabilities to convert them to predicted target values.
  3. Call sklearn.metrics.matthews_corrcoef.

Answered by Brian Spiering on May 26, 2021

from sklearn.metrics import matthews_corrcoef
y_true = [+1, +1, +1, -1]
y_pred = [+1, -1, +1, +1]
matthews_corrcoef(y_true, y_pred)

Source:

https://scikit-learn.org/stable/modules/generated/sklearn.metrics.matthews_corrcoef.html

Answered by fuwiak on May 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP