AttributeError: 'str' object has no attribute 'decode' in fitting Logistic Regression Model AttributeError: 'str' object has no attribute 'decode' in fitting Logistic Regression Model python python

AttributeError: 'str' object has no attribute 'decode' in fitting Logistic Regression Model


I tried to upgrade my scikit-learn using the below command, still, that didn't solve the AttributeError: 'str' object has no attribute 'decode' issue

pip install scikit-learn  -U

Finally, below code snippet solved the issue, add the solver as liblinear

model = LogisticRegression(solver='liblinear')


In the most recent version of scikit-learn (now 0.24.1) the problem has been fixed enclosing a part of code in a try-catch block which I report below: the file is

optimize.py -> _check_optimize_result(solver, result, max_iter=None,                       extra_warning_msg=None)

and the code piece is

if solver == "lbfgs":    if result.status != 0:        try:            # The message is already decoded in scipy>=1.6.0            result_message = result.message.decode("latin1")        except AttributeError:            result_message = result.message            warning_msg = (                "{} failed to converge (status={}):\n{}.\n\n"                "Increase the number of iterations (max_iter) "                "or scale the data as shown in:\n"                "    https://scikit-learn.org/stable/modules/"                "preprocessing.html"            ).format(solver, result.status, result_message)

Which was just

if solver == "lbfgs":    if result.status != 0:        warning_msg = (            "{} failed to converge (status={}):\n{}.\n\n"            "Increase the number of iterations (max_iter) "            "or scale the data as shown in:\n"            "    https://scikit-learn.org/stable/modules/"            "preprocessing.html"        ).format(solver, result.status, result.message.decode("latin1"))

before.So upgrading scikit-learn solves the problem.


There is a bug with solver='lbfgs'.Changing to 'sag' works around it.