Closed sunrisehang closed 5 years ago
You need to update to the latest development version of sklearn:
conda install scikit-learn=0.21.2
thanks
I had had the same problem so I updated the latest version of scikit-learn
(until now is 0.22) by pip
and the problem fixed:
pip install -U scikit-learn
-U
is upgrade option
Result:
pip show scikit-learn
Name: scikit-learn
Version: 0.22
Summary: A set of python modules for machine learning and data mining
Home-page: http://scikit-learn.org
Author: None
Author-email: None
License: new BSD
Location: /usr/local/lib/python3.6/dist-packages
Requires: joblib, scipy, numpy
Required-by: mlxtend
I upgrade but still the same error
Upgrading didn't work for me. I found out that the problem is with the solver. If you'll change to 'lbfgs', you'll be able to use penalty='none'.
The error message is the same no matter what non-default solver you use: "ValueError: Solver lbfgs supports only 'l2' or 'none' penalties, got l1 penalty."
I tried the followings:
1) LogisticRegression (solver='newton-cg',penalty='l2') 2) LogisticRegression (solver='newton-cg') 3) LogisticRegression (solver='lbfgs') 4) LogisticRegression (solver='lbfgs',penalty='l2') . .
This is pretty bad situation since you get same error no matter what solver you use.
Full error :
=================================
Traceback (most recent call last):
File "classifiers.py", line 224, in
from sklearn.linear_model import LogisticRegression lr_classifier = LogisticRegression(random_state = 51, penalty = 'l1') lr_classifier.fit(X_train, y_train) y_pred_lr = lr_classifier.predict(X_test) accuracy_score(y_test, y_pred_lr)
And Encountered this issue: ValueError Traceback (most recent call last)
The solver liblinear supports those panalties, so make sure to create your classifier object like this :
clf = LogisticRegression(C=0.01, penalty='l1',solver='liblinear');
I found changing penalty=None
worked with LogisticRegression
张建行:您的邮件我已收到。
你好,已收到,谢谢。
It will report the error: ValueError: Logistic Regression supports only penalties in ['l1', 'l2'], got none.
I dont know why i cant input parameter:penalty='none'