python机器学习使用逻辑回归LogisticRegression()提示FutureWarning: Default solver will be changed to 'lbfgs' in

在Python中利用Logistic回归算法进行数据建模
使用python的sklearn.linear_model.LogisticRegression进行实例化时model=LogisticRegression(),就提示了以下警告信息:

FutureWarning: Default solver will be changed to ‘lbfgs’ in 0.22. Specify a solver to silence this warning。

问题分析:

FutureWarning是语言或者库中将来可能改变的有关警告。

根据报警信息和参考相关文档,“Default will change from ‘liblinear’ to ‘lbfgs’ in 0.22.”,默认的solver参数在0.22版本中,将会由“liblinear”变为“lbfgs”,且指定solver参数可以消除该warning。

这是代码在发出警告,将来代码运行时如果没有及时关注到版本的问题,可能solver的参数会发生改变。所以,最安全的方法并不是通过ignore消除警告,而是指定一个solver参数。

参阅官方文档:

solver : str, {‘newton-cg’, ‘lbfgs’, ‘liblinear’, ‘sag’, ‘saga’}, \default: ‘liblinear’.

    Algorithm to use in the optimization problem.

    - For small datasets, 'liblinear' is a good choice, whereas 'sag' and

      'saga' are faster for large ones.

    - For multiclass problems, only 'newton-cg', 'sag', 'saga' and 'lbfgs'

      handle multinomial loss; 'liblinear' is limited to one-versus-rest

      schemes.

    - 'newton-cg', 'lbfgs' and 'sag' only handle L2 penalty, whereas

      'liblinear' and 'saga' handle L1 penalty.

LogisticRegerssion算法的solver仅支持以下几个参数’liblinear’, ‘newton-cg’, ‘lbfgs’, ‘sag’, ‘saga’。

解决方法:

传入参数后即可消除警告。
将model=LogisticRegression()改为:
model=LogisticRegression(solver=’liblinear’) 。

扩展

其他消除警告的方法:

import warnings

warnings.filterwarnings(“ignore”)
————————————————
版权声明:本文为CSDN博主「linzhjbtx」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/linzhjbtx/article/details/85331200

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值