why is it showing failed to converge?

Viewed 1234

i am getting this error while processing for titanic dataset as I was implementing logistic regression. I cannot resolve the issue.

    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 n_iter_i = _check_optimize_result( LogisticRegression()

2 Answers

This means that you need to increase your maximum iterations. I will show you where

class sklearn.linear_model.LogisticRegression(solver='lbfgs', max_iter=100)

Increase your max_iter to let's say 1000 and try running ur model.

Also, make sure your data is scaled because LogReg does not work well when your data has lots of scale difference between columns.

In case of mine, even after changing the max_iter to 1000000 didn't work. so, I changed the solver from lbfgs to liblinear and it worked.

LogisticRegression(solver='liblinear')
Related