【问题标题】:How to implement L1 logistic regression?如何实现 L1 逻辑回归?
【发布时间】:2020-05-09 21:20:57
【问题描述】:

作为学习课程的一部分,我尝试在 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 Logistic 回归?

【问题讨论】:

    标签: python machine-learning scikit-learn data-science logistic-regression


    【解决方案1】:

    你可以像在第一个代码 sn-p 中那样做,但你必须定义另一个求解器。使用“liblinear”或“saga”,check more in the documentation

    【讨论】:

    • 感谢您的回答。我认为它解决了这个问题。所以,我必须使用 clf, pred = fit_and_plot_classifier(LogisticRegression(solver='saga', 惩罚 = 'l1', C=1000000)) - 如果求解器是 'saga' - 否?
    • 由于某种原因,上面带有惩罚的代码,“l2”也产生了完全相同的情节。
    • 我认为情节相同的原因是由于 C 非常高。对于默认值 C=1,这些图肯定不同。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-06
    • 2013-05-02
    • 2021-04-10
    • 2020-09-23
    • 1970-01-01
    • 2014-02-19
    相关资源
    最近更新 更多