SGDClassifier vs LogisticRegression with sgd solver in scikit-learn library

The scikit-learn library has the following classifiers that look the same:

  • Logistic regression classifier has different solvers and one of them is 'sgd'

http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html#sklearn.linear_model.LogisticRegression

  • It also has another classifier "SGDClassifier" and parameter loss can be specified as "log" for logistic regression.

http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.SGDClassifier.html#sklearn.linear_model.SGDClassifier

Are they essentially the same or different? If they are different, how different is the implementation between the two? And how do you decide which one to use given the logistic regression problem?

+3


source to share


2 answers


Sklearn's logistic regression, however, does not have a 'sgd' solver. It implements logarithmic logistic regression: it minimizes the log probability.

SGDClassifier is a generalized linear classifier that will use Stochastic Gradient Descent as a solver. As http://scikit-learn.org/stable/modules/sgd.html mentioned here : "While SGD has been around for a long time in the machine learning community, it has received considerable attention more recently in the context of large-scale learning." It is easy to implement and effective. For example, this is one of the solvers used for neural networks.

With SGDClassifier you can use many different loss functions (function to minimize or maximize to find the optimal solution) that allows you to "tune" your model and find the best sgd-based linear model for your data. Indeed, some data structures or some problems will require different loss functions.



In your example, the SGD classifier will have the same loss function as Logistic Regression, but a different solver. You may have different results depending on your data. You can try to find the best one with cross-validation, or even try grid cross-validation to find the best hyperparameters.

Hope that answers your questions.

+2


source


All linear classifiers (SVM, logistic regression, ao) can use sgd: Stochastic Gradient Descent



0


source







All Articles