美文网首页
MCC 小结

MCC 小结

作者: yoyo9999 | 来源:发表于2021-04-20 19:51 被阅读0次

MCC

1. 定义

MCC ——Matthews correlation coefficient , 马修斯相关系数。sklearn.metrics.matthews_corrcoef

The Matthews correlation coefficient is used in machine learning as a measure of the quality of binary and multiclass classifications. It takes into account true and false positives and negatives and is generally regarded as a balanced measure which can be used even if the classes are of very different sizes. The MCC is in essence a correlation coefficient value between -1 and +1. A coefficient of +1 represents a perfect prediction, 0 an average random prediction and -1 an inverse prediction. The statistic is also known as the phi coefficient. [source: Wikipedia]

马修斯相关系数在机器学习中被用来衡量二分类和多分类。它考虑真和假阳性和阴性,通常被认为是一种平衡的测量,即使类别的数目非常不同,也可以使用。其本质是一个介于-1到+1之间的相关系数。

  • 1代表完美预测
  • 0代表平均随机预测
  • -1代表相反的预测

也叫phi 系数。

2. 计算公式

MCC可以直接用混淆矩阵计算 MCC WiKi
{\displaystyle {\text{MCC}}={\frac {{\mathit {TP}}\times {\mathit {TN}}-{\mathit {FP}}\times {\mathit {FN}}}{\sqrt {({\mathit {TP}}+{\mathit {FP}})({\mathit {TP}}+{\mathit {FN}})({\mathit {TN}}+{\mathit {FP}})({\mathit {TN}}+{\mathit {FN}})}}}}
至于TP,FP, TN, FN跟TPR, FPR中计算是一样的

Matthew原本给出的公式:
{\displaystyle {\begin{aligned}N&={\mathit {TN}}+{\mathit {TP}}+{\mathit {FN}}+{\mathit {FP}}\\S&={\frac {{\mathit {TP}}+{\mathit {FN}}}{N}}\\P&={\frac {{\mathit {TP}}+{\mathit {FP}}}{N}}\\{\text{MCC}}&={\frac {{\mathit {TP}}/N-S\times P}{\sqrt {PS(1-S)(1-P)}}}\end{aligned}}}

3. 用法

用法:matthews_corrcoef(y_true, y_pred)

还有个参数 :样本权重sample_weight:array-like of shape (n_samples,), default=None
返回float 常数

from sklearn.metrics import matthews_corrcoef

y_true = [+1, +1, +1, -1]
y_pred = [+1, -1, +1, +1]
matthews_corrcoef(y_true, y_pred)
======================================
-0.3333333333333333

相关文章

网友评论

      本文标题:MCC 小结

      本文链接:https://www.haomeiwen.com/subject/fkxolltx.html