Matthews Correlation Coefficient

MediumMachine LearningStatisticsMatrix

Description

Given the confusion-matrix counts true positives, true negatives, false positives, and false negatives, return the Matthews correlation coefficient: (TP*TN - FP*FN) / sqrt((TP+FP)(TP+FN)(TN+FP)(TN+FN)). Return 0 when the denominator is 0. Round the result to 4 decimal places.

Examples

Input:50, 40, 5, 5
Output:0.798
Explanation:

The coefficient summarizes the full confusion matrix into a single balanced score that runs from minus one for total disagreement to plus one for perfect prediction.

Input:10, 10, 0, 0
Output:1
Explanation:

The coefficient summarizes the full confusion matrix into a single balanced score that runs from minus one for total disagreement to plus one for perfect prediction.

Input:5, 5, 5, 5
Output:0
Explanation:

The coefficient summarizes the full confusion matrix into a single balanced score that runs from minus one for total disagreement to plus one for perfect prediction.

Constraints

  • 0 ≤ each count
  • at least one count positive

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.