F1 ignores true negatives entirely, so it can look good on a model that is mostly wrong about the negatives. The Matthews correlation coefficient (MCC) uses all four cells of the confusion matrix. It is the correlation between predictions and truth: +1 means perfect agreement, 0 means no better than chance, and -1 means every prediction is inverted.
Implement matthews_corrcoef(y_true, y_pred, positive=1) for binary labels.
MCC = (TP · TN − FP · FN) / sqrt((TP + FP)(TP + FN)(TN + FP)(TN + FN))
If any factor in the denominator is zero, return 0.0.
ValueError.positive counts as negative.Open one at a time. Each gives away a little more than the last.
Build the four counts from boolean masks on positive, using the same pattern as F-beta.
Compute the product of the four marginal sums under a single square root, and check for zero before dividing.
No results yet
Run your code to check it against the examples, or submit to run every test.