我正在运行分类问题的特征选择过程,使用嵌入式方法(L1 - 套索)和 LogisticRegression。
我正在运行以下代码:
from sklearn.linear_model import Lasso, LogisticRegression
from sklearn.feature_selection import SelectFromModel
# using logistic regression with penalty l1.
selection = SelectFromModel(LogisticRegression(C=1, penalty='l1'))
selection.fit(x_train, y_train)
但是我遇到异常(在 fit
命令上):
selection.fit(x_train, y_train)
File "C:\Python37\lib\site-packages\sklearn\feature_selection_from_model.py", line 222, in fit
self.estimator_.fit(X, y, **fit_params)
File "C:\Python37\lib\site-packages\sklearn\linear_model_logistic.py", line 1488, in fit
solver = _check_solver(self.solver, self.penalty, self.dual)
File "C:\Python37\lib\site-packages\sklearn\linear_model_logistic.py", line 445, in _check_solver
"got %s penalty." % (solver, penalty))
ValueError: Solver lbfgs supports only 'l2' or 'none' penalties, got l1 penalty.
我在 python 3.7.6
和 s scikit-learn version is 0.22.2.post1
下运行
出了什么问题,我该如何解决?
原文由 user3668129 发布,翻译遵循 CC BY-SA 4.0 许可协议
这在 文档 中得到了澄清。
像这样称呼它: