sklearn 评估指标auc和(归一化)基尼系数

auc的解释:

https://blog.csdn.net/u013385925/article/details/80385873

 

Gini和AUC的关系(Gini=2AUC-1真的成立吗?):

https://blog.csdn.net/dongweionly/article/details/83573878

 

gini原版测试代码(较长):

https://blog.csdn.net/u010665216/article/details/78528261 

 

sklearn 和 多分类上的auc例子:

注意,auc是计算曲线下的面积,曲线自己来定义。roc_auc_score 是专门计算roc曲线的面积。

https://www.pianshen.com/article/517880764/

 

import numpy as np

def gini(actual, pred):
    assert (len(actual) == len(pred))
    all = np.asarray(np.c_[actual, pred, np.arange(len(actual))], dtype=np.float)
    all = all[np.lexsort((all[:, 2], -1 * all[:, 1]))]
    totalLosses = all[:, 0].sum()
    giniSum = all[:, 0].cumsum().sum() / totalLosses

    giniSum -= (len(actual) + 1) / 2.
    return giniSum / len(actual)

def gini_norm(actual, pred):
    return gini(actual, pred) / gini(actual, actual)

predictions = [0.9, 0.3, 0.8, 0.75, 0.65, 0.6, 0.78, 0.7, 0.05, 0.4, 0.4, 0.05, 0.5, 0.1, 0.1]
actual = [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
k = gini_norm(actual, predictions)
k

 

posted @ 2020-12-15 16:57  qiezi_online  阅读(832)  评论(0编辑  收藏  举报