sklearn LogisticRegression without regularization

前端 未结 3 2094
Happy的楠姐
Happy的楠姐 2021-02-05 06:49

Logistic regression class in sklearn comes with L1 and L2 regularization. How can I turn off regularization to get the \"raw\" logistic fit such as in glmfit in Matlab? I think

相关标签:
3条回答
  • 2021-02-05 07:02

    Go ahead and set C as large as you please. Also, make sure to use l2 since l1 with that implementation can be painfully slow.

    0 讨论(0)
  • 2021-02-05 07:06

    Yes, choose as large a number as possible. In regularization, the cost function includes a regularization expression, and keep in mind that the C parameter in sklearn regularization is the inverse of the regularization strength.

    C in this case is 1/lambda, subject to the condition that C > 0.

    Therefore, when C approaches infinity, then lambda approaches 0. When this happens, then the cost function becomes your standard error function, since the regularization expression becomes, for all intents and purposes, 0.

    0 讨论(0)
  • 2021-02-05 07:11

    I got the same question and tried out the answer in addition to the other answers:

    If set C to a large value does not work for you, also set penalty='l1'.

    0 讨论(0)
提交回复
热议问题