1.lr.predict_proba(under_text_x)  获得的是正负的概率值

在sklearn逻辑回归的计算过程中,使用的是大于0.5的是正值,小于0.5的是负值,我们使用使用不同的概率结果判定来研究概率阈值对结果的影响

从图中我们可以看出,阈值越小,被判为正的越多,即大于阈值的就是为正,但是存在一个很明显的问题就是很多负的也被判为正值。

当阈值很小时,数据的召回率很大,但是整体数据的准确率很小

因此我们需要根据召回率和准确率的综合考虑选择一个合适的阈值

lr = LogisticRegression(C=best_c, penalty='l1')
lr.fit(under_train_x, under_train_y) pred_array = np.array(lr.predict_proba(under_text_x)) thresholds = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9] j = 1
for threshold in thresholds:
pred_y_new = np.zeros([len(under_text_x), 1])
pred_y_new[pred_array[:, 1] > threshold] = 1
# 获得矩阵
plt.subplot(3, 3, j)
conf = confusion_matrix(under_test_y, pred_y_new)
# 画图
plot_matrix(conf, classes=[0, 1], title='threshod is {}'.format(threshold))
accurracy = (conf[0, 0] + conf[1, 1]) / (conf[0, 0] + conf[0, 1] + conf[1, 0] + conf[1, 1])
# 召回率
recall = conf[1, 1] / (conf[1, 0] + conf[1, 1])
j = j + 1
plt.show()

最新文章

  1. rem 和 ::
  2. 【转】The difference between categorical(Nominal ), ordinal and interval variables
  3. nginx + fastDFS 设置开机自动启动
  4. Oracle 学习系列之一(表空间与表结构)
  5. 谈 DevOps 自动化时,也应该考虑到 SOX 等法案
  6. 2016多校第六场题解(hdu5793&hdu5794&hdu5795&hdu5800&hdu5802)
  7. FromHandle函数
  8. VMware vSphere 服务器虚拟化之二十七桌面虚拟化之View中使用Thinapp软件虚拟化
  9. centos7下引导win7
  10. Java基础语法<十二> 泛型程序设计
  11. 根据选中不同的图元来显示不同的属性面板changePropertyPane.html
  12. Python面向对象基础:设置对象属性
  13. centos6.8下安装matlab2009(图片转帖)
  14. Windows 2003 Server R2 x64 IIS6.0 eWebEditor无法显示的问题
  15. 一种比较简单的实现ping的方式
  16. python cook 2
  17. MySql数据库常用语句汇总
  18. Xilinx全局时钟
  19. windows下PIP安装模块编码错误解决
  20. shell 环境变量的知识小结

热门文章

  1. MySQL Disk--NAND Flash原理
  2. hive 分区表
  3. ZH奶酪:Python使用ElementTree解析XML【译】
  4. JUC集合之 ConcurrentHashMap
  5. C# 正则表达式 判断各种字符串(如手机号)
  6. Microsoft Dynamics CRM 如何修改域密码
  7. ASP.NET网站权限设计实现(二)——角色权限绑定
  8. 豆瓣源安装python包
  9. android设备唯一码的获取,cpu号,mac地址
  10. HDU 1116 Play on Words(并查集和欧拉回路)(有向图的欧拉回路)