V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
acone2003
V2EX  ›  Python

如何求预测值为 1 且预测正确的样本个数?

  •  
  •   acone2003 · 2018-08-15 19:20:34 +08:00 · 2024 次点击
    这是一个创建于 2073 天前的主题,其中的信息可能已经有所发展或是发生改变。
    有一个二分类问题,predict 为预测值,labels 为实际标签,请问一下如何显示预测值为 1 且预测正确的样本个数?
    5 条回复    2018-08-16 16:51:17 +08:00
    acone2003
        1
    acone2003  
    OP
       2018-08-15 21:35:43 +08:00
    np.sum(predict == 1 and labels==1 )这样写不对,该怎么写呀?求助
    nekota
        2
    nekota  
       2018-08-16 00:42:03 +08:00 via iPhone
    result 是二维数组,[predict, label]
    len(np.where(result==(1,1))[0])
    diggerdu
        3
    diggerdu  
       2018-08-16 01:02:15 +08:00 via iPhone
    np.sum(predict > 0.5 == label)
    ivechan
        4
    ivechan  
       2018-08-16 10:32:12 +08:00
    没必要非得一条命令写吧?
    在预测正确里,统计预测值为 1 的数量就行了。

    或者你用 sklearn 之类的库的话,可以用库函数算出 confusion matrix。
    这样 TP, TN, FP, FN 都有了。
    acone2003
        5
    acone2003  
    OP
       2018-08-16 16:51:17 +08:00
    谢谢楼上三位,楼上的每个建议我都要查半天资料,长了不少知识----我是个初学者。
    回 diggerdu: 用 np.sum(predict > 0.5 == label)这条语句怎么出现这个警告呀?
    ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   983 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 20:16 · PVG 04:16 · LAX 13:16 · JFK 16:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.