如何实现L1逻辑回归?
How to implement L1 logistic regression?
作为学习课程的一部分,我试图在 Python 中使用 scikit-learn 实现 L1 逻辑回归。不幸的是代码
clf, pred = fit_and_plot_classifier(LogisticRegression(penalty = 'l1', C=1000000))
我收到错误消息
ValueError: Solver lbfgs supports only 'l2' or 'none' penalties, got l1 penalty.
我尝试设置 l1_ratio
clf, pred = fit_and_plot_classifier(LogisticRegression(l1_ratio = 1))
但收到错误消息
C:\Users\HP\Anaconda3\lib\site-packages\sklearn\linear_model\_logistic.py:1499: UserWarning: l1_ratio parameter is only used when penalty is 'elasticnet'. Got (penalty=l2)"(penalty={})".format(self.penalty))
那么,如何实现L1逻辑回归?
你可以像在第一个代码片段中那样做,但你必须定义另一个求解器。使用“liblinear”或“saga”,check more in the documentation.
作为学习课程的一部分,我试图在 Python 中使用 scikit-learn 实现 L1 逻辑回归。不幸的是代码
clf, pred = fit_and_plot_classifier(LogisticRegression(penalty = 'l1', C=1000000))
我收到错误消息
ValueError: Solver lbfgs supports only 'l2' or 'none' penalties, got l1 penalty.
我尝试设置 l1_ratio
clf, pred = fit_and_plot_classifier(LogisticRegression(l1_ratio = 1))
但收到错误消息
C:\Users\HP\Anaconda3\lib\site-packages\sklearn\linear_model\_logistic.py:1499: UserWarning: l1_ratio parameter is only used when penalty is 'elasticnet'. Got (penalty=l2)"(penalty={})".format(self.penalty))
那么,如何实现L1逻辑回归?
你可以像在第一个代码片段中那样做,但你必须定义另一个求解器。使用“liblinear”或“saga”,check more in the documentation.