Python作图-精确率与召回率间关系

Precision与Recall的关系图,下面贴出原代码:

下图的Precision与Recall是自已实验的数据,作图时将它替换成自己的数据即可.

import matplotlib.pyplot as plt
import numpy as np


# draw the picture
def draw(Curve_one, Curve_two, Curve_three, Curve_four):

    plt.figure()
    
    plot1, = plt.plot(Curve_one[0], Curve_one[1],     'co-', linewidth=2.0, markersize=10.0)
    plot2, = plt.plot(Curve_two[0], Curve_two[1],     'bx-', linewidth=2.0, markersize=10.0)
    plot3, = plt.plot(Curve_three[0], Curve_three[1], 'rh-', linewidth=2.0, markersize=10.0)
    plot4, = plt.plot(Curve_four[0], Curve_four[1],   'k^-', linewidth=2.0, markersize=10.0)
    
    # set X axis
    plt.xlim( [0.5, 1.05] )
    plt.xticks( np.linspace(0.5, 1.0, 6) )
    plt.xlabel("Precision", fontsize="x-large")
    
    # set Y axis
    plt.ylim( [0.1, 1.05] )
    plt.yticks( np.linspace(0.1, 1.0, 10) )
    plt.ylabel("Recall",    fontsize="x-large")
    
    # set figure information
    plt.title("Precision --- Recall", fontsize="x-large")
    plt.legend([plot1, plot2, plot3, plot4], ("Curve_one", "Curve_two", "Curve_three", "Curve_four"), loc="lower left", numpoints=1)
    plt.grid(True)

    # draw the chart
    plt.show()


# main function
def main():
    # Curve one
    Curve_one = [ (0.999200, 0.998067, 0.995260, 0.989679, 0.976811, 0.937295, 0.849400, 0.751620, 0.667903, 0.599113, 0.542607), 
                  (0.107668, 0.262707, 0.436613, 0.607831, 0.771336, 0.904606, 0.968826, 0.989191, 0.996214, 0.998741, 0.999759) ]

    # Curve two
    Curve_two  = [ (0.998300, 0.994883, 0.990090, 0.981757, 0.963972, 0.918909, 0.835273, 0.744247, 0.664585, 0.597868, 0.542286), 
                   (0.107589, 0.261869, 0.434345, 0.602966, 0.761198, 0.886861, 0.952713, 0.979487, 0.991266, 0.996666, 0.999166) ]

    # Curve three
    Curve_three = [ (0.997050, 0.992867, 0.987220, 0.977600, 0.957650, 0.912350, 0.833100, 0.743753, 0.664700, 0.598011, 0.542317),
                    (0.103480, 0.239338, 0.411086, 0.578412, 0.734205, 0.858531, 0.928235, 0.956837, 0.979437, 0.984903, 0.997224) ]

    # Curve four
    Curve_four = [ (0.995750, 0.982433, 0.960270, 0.928964, 0.887517, 0.835059, 0.775115, 0.713273, 0.652159, 0.594189, 0.541702),
                   (0.107366, 0.258592, 0.421263, 0.570542, 0.700825, 0.805936, 0.884097, 0.938723, 0.972731, 0.990533, 0.998092) ]

    # Call the draw function
    draw(Curve_one, Curve_two, Curve_three, Curve_four)


# function entrance
if __name__ == "__main__":
    main()

效果图:


  • 2
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
Python中,精确召回是用于衡量分类模型性能的评价指标之一。精确衡量了模型预测为正类的样本中真正为正类的比例,而召回衡量了模型能够正确预测为正类的比例。 在给定的代码中,精确召回是在评价函数`evaluation`中计算得出的。在`evaluation`函数中,使用了`classification_report`函数计算了多个评价指标,包括精确召回等。精确通过`classification_report`函数返回的字典中的`weighted avg`部分进行提取,而召回同样也是通过`classification_report`函数返回的字典中的`weighted avg`部分进行提取。 因此,如果你想获取精确召回的值,你可以调用`evaluation`函数,并将预测结果和真实标签作为参数传入该函数。函数将返回一个元组,其中包含精确召回等评价指标的值。 请注意,这些函数的具体实现可能依赖于`sklearn`库中的版本和函数的参数设置。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Python计算分类问题的评价指标(准确精确度、召回和F1值,Kappa指标)](https://blog.csdn.net/weixin_46277779/article/details/129338660)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值