matthews_corrcoef#
- sklearn.metrics.matthews_corrcoef(y_true,y_pred,*,sample_weight=None)[source]#
Compute the Matthews correlation coefficient (MCC).
The Matthews correlation coefficient is used in machine learning as ameasure of the quality of binary and multiclass classifications. It takesinto account true and false positives and negatives and is generallyregarded as a balanced measure which can be used even if the classes are ofvery different sizes. The MCC is in essence a correlation coefficient valuebetween -1 and +1. A coefficient of +1 represents a perfect prediction, 0an average random prediction and -1 an inverse prediction. The statisticis also known as the phi coefficient. [source: Wikipedia]
Binary and multiclass labels are supported. Only in the binary case doesthis relate to information about true and false positives and negatives.See references below.
Read more in theUser Guide.
- Parameters:
- y_truearray-like of shape (n_samples,)
Ground truth (correct) target values.
- y_predarray-like of shape (n_samples,)
Estimated targets as returned by a classifier.
- sample_weightarray-like of shape (n_samples,), default=None
Sample weights.
Added in version 0.18.
- Returns:
- mccfloat
The Matthews correlation coefficient (+1 represents a perfectprediction, 0 an average random prediction and -1 and inverseprediction).
References
Examples
>>>fromsklearn.metricsimportmatthews_corrcoef>>>y_true=[+1,+1,+1,-1]>>>y_pred=[+1,-1,+1,+1]>>>matthews_corrcoef(y_true,y_pred)-0.33
