Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sklearn LogisticRegression without regularization

Tags:

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 I can set C = large number but I don't think it is wise.

see for more details the documentation http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html#sklearn.linear_model.LogisticRegression

like image 500
Hanan Shteingart Avatar asked Aug 21 '14 13:08

Hanan Shteingart


People also ask

Does Sklearn use regularization?

Linear models are usually a good starting point for training a model. However, a lot of datasets do not exhibit linear relationships between the independent and the dependent variables. As a result, it is frequently necessary to create a polynomial model.

Is there a default regularization for logistic regression?

By default, logistic regression in scikit-learn runs w L2 regularization on and defaulting to magic number C=1.0.

How do you avoid overfitting in logistic regression Sklearn?

In order to avoid overfitting, it is necessary to use additional techniques (e.g. cross-validation, regularization, early stopping, pruning, or Bayesian priors).

What is penalty in logistic regression Sklearn?

Comparison of the sparsity (percentage of zero coefficients) of solutions when L1, L2 and Elastic-Net penalty are used for different values of C. We can see that large values of C give more freedom to the model. Conversely, smaller values of C constrain the model more.


2 Answers

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.

Update: In sklearn versions 0.21 and higher, you can disable regularization by passing in penalty='none'. Check out the documentation here.

like image 76
Yu Chen Avatar answered Sep 27 '22 22:09

Yu Chen


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.

like image 22
Phillip Chilton Adkins Avatar answered Sep 27 '22 21:09

Phillip Chilton Adkins