【读书笔记】机器学习实战 第7章 7.7节非均衡分类问题

本文介绍了非均衡分类问题中的性能评估指标,包括混淆矩阵、查准率、查全率、真正确率、假正确率等,并提供了ROC曲线的绘制方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

机器学习实战

7.7节 非均衡分类问题


  • 分类性能指标:

错误率 指错分样本的比例,这样的度量掩盖了样例是如何被错分的事实。有一个普遍适用的称为混淆矩阵

-

(+1)(1)(+1)TPFP (1) FN TN

-

分类中,当某个类别的重要性高于其他类别时,可以利用混淆矩阵定义出比错误率更好的指标:


  1. 查准率/正确率

    P=TPTP+FP
  2. 查全率/召回率

    R=TPTP+FN
  3. P-R曲线/查准率-查全率曲线


  1. 真正确率/真阳率 TPR
    TPR=TPTP+FN
  2. 假正确率/假阳率 FPR
    FPR=FPTN+FP
  3. ROC曲线

机器学习实战 7.7 节

# ROC曲线绘制
def plotROC(predStrengths, classLabels):# 预测强度向量,样本标签
    import matplotlib.pyplot as plt  # 导入库
    cur = (1.0,1.0) #cursor
    ySum = 0.0 #variable to calculate AUC
    numPosClas = sum(array(classLabels)==1.0)
    yStep = 1/float(numPosClas); xStep = 1/float(len(classLabels)-numPosClas)
    sortedIndicies = predStrengths.argsort()#get sorted index, it's reverse
    fig = plt.figure()
    fig.clf()
    ax = plt.subplot(111)
    #loop through all the values, drawing a line segment at each point
    for index in sortedIndicies.tolist()[0]:
        if classLabels[index] == 1.0:
            delX = 0; delY = yStep;
        else:
            delX = xStep; delY = 0;
            ySum += cur[1]
        #draw line from cur to (cur[0]-delX,cur[1]-delY)
        ax.plot([cur[0],cur[0]-delX],[cur[1],cur[1]-delY], c='b')
        cur = (cur[0]-delX,cur[1]-delY)
    ax.plot([0,1],[0,1],'b--')
    plt.xlabel('False positive rate'); plt.ylabel('True positive rate')
    plt.title('ROC curve for AdaBoost horse colic detection system')
    ax.axis([0,1,0,1])
    plt.show()
    print "the Area Under the Curve is: ",ySum*xStep
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值