Coder Social home page Coder Social logo

vlainic / matthews-correlation-coefficient Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 19 KB

MCC functions for ML

Python 100.00%
statistics machine-learning metrics matthews correlation-coefficient confusion-matrix keras loss-functions plotting curve-construction

matthews-correlation-coefficient's Introduction

Matthews Correlation Coefficient (MCC)

MCC function for ML

Here I would like to share my implementation of Matthews Correlation Coefficient (MCC) for various situations.

Inspiration from Kaggle kernel by Michal on "Best loss function for F1-score metric".

Intro on MCC

I encountered MCC while search for the "best multi-class classification metric".

Wikipedia has very nice explanation of MCC, while at stats.stackexchange you can find a very interesting discussion on the topic. Multi-class MCC is often called "R_K statistics" so I found the whole page devoted to it.

The most useful expression for computation was Eq.(8) from the original article by Gorodkin:

where N is the number of examples, \tilde{C}_k is the kth row of the confusion matrix C, \hat{C}_l the lth column of C, C^T is C transposed and Tr(C) is the trace of C.

Note: if you only need MCC value to be computed use sklearn.metrics.matthews_corrcoef !!!

binary_mcc_loss.py

Function that can be used as loss function for Keras training in the binary classification case.

multi_mcc_loss.py

Function that can be used as loss function for Keras training in the multi-class classification case.

plot_mcc_vs_tresh.py

Following the practice of plotting precision/recall vs tresholds, I wanted to see how MCC behaves.

matthews-correlation-coefficient's People

Contributors

vlainic avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.