KubiK888
KubiK888

Reputation: 4731

How to perform an unregularized logistic regression using scikit-learn?

From scikit-learn's documentation, the default penalty is "l2", and C (inverse of regularization strength) is "1". If I keep this setting penalty='l2' and C=1.0, does it mean the training algorithm is an unregularized logistic regression? In contrast, when C is anything other than 1.0, then it's a regularized logistic regression classifier?

Upvotes: 1

Views: 2345

Answers (2)

Code Learner
Code Learner

Reputation: 195

first, set C to a large value (relative to your expected coefficients).

If it does not work for you, also set penalty='l1'

Upvotes: 0

sascha
sascha

Reputation: 33542

No, it's not like that.

Let's have a look at the definitions within sklearn's user-guide:

enter image description here

We see:

  • C is multiplied with the loss while the left-term (regularization) is untouched

This means:

  • Without modifying the code you can never switch-off the regularization completely
  • But: you can approximately switch-off regularization by setting C to a huge number!
    • As the optimization tries to minimize the sum of regularization-penalty and loss, increasing C decreases the relevance of the regularization-penalty

Upvotes: 4

Related Questions