关于使用Jupyter Notebook做逻辑回归建模(LogisticRegressionCV)时遇到的问题
报错
C:\Users\taytay-POI\AppData\Roaming\Python\Python36\site-packages\sklearn\linear_model_logistic.py:939: ConvergenceWarning: lbfgs failed to converge (status=1):
STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.
Increase the number of iterations (max_iter) or scale the data as shown in:
https://scikit-learn.org/stable/modules/preprocessing.html.
Please also refer to the documentation for alternative solver options:
https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression
extra_warning_msg=_LOGISTIC_SOLVER_CONVERGENCE_MSG)
解决办法
意思是达到限制的迭代总数,只需要增加迭代次数(最大值)或缩放数据就可以。
将代码改为(增加迭代次数):
model = LogisticRegressionCV(multi_class='multinomial',max_iter=3000).fit(x_train, y_train)
最大迭代次数默认值为1000,把它改为3000即可。但这样会增加运行时间,等了好一会儿才运行完这一行。
解决Logistic Regression迭代次数达到限制的问题
在使用Python的sklearn库进行逻辑回归时遇到迭代次数达到限制的警告,可以增加最大迭代次数(max_iter)或对数据进行缩放以解决此问题。通过将max_iter设置为3000,虽然会增加运行时间,但能成功完成迭代过程。
4万+

被折叠的 条评论
为什么被折叠?



