Class prediction and probabilities
Binary classification with calibrated class likelihoods
Scikit-Learn · Class
LogisticRegression is a regularized classifier for binary and multiclass problems. It supports dense or sparse features and several solvers with different penalty and multiclass capabilities.
The estimator learns a regularized logistic decision function from feature matrix X and target y. Its selected solver optimizes the applicable binary or multinomial loss, while the regularization strength is controlled inversely by C; after fitting, it can predict labels, decision scores, and probabilities.
sklearn.linear_model.LogisticRegression(penalty='l2', *, dual=False, tol=0.0001, C=1.0, fit_intercept=True, intercept_scaling=1, class_weight=None, random_state=None, solver='lbfgs', max_iter=100, multi_class='deprecated', verbose=0, warm_start=False, n_jobs=None, l1_ratio=None)| Name | Type | Description |
|---|---|---|
X | array-like or sparse matrix | Training feature matrix. |
y | array-like | Target values. |
C | float | Inverse of regularization strength; must be positive. Default: 1.0. |
solver | {'lbfgs', 'liblinear', 'newton-cg', 'newton-cholesky', 'sag', 'saga'} | Algorithm used for optimization. Default: 'lbfgs'. |
penalty | {'l1', 'l2', 'elasticnet', None} | Penalty specification. Default: 'l2'. |
max_iter | int | Maximum number of iterations. Default: 100. |
random_state | int, RandomState instance or None | Seed used by solvers whose behavior involves randomness. |
A fitted LogisticRegression estimator after fit; prediction methods return labels, decision scores, or class probabilities depending on the method used.
from sklearn.linear_model import LogisticRegression
X = [[0, 0], [0, 1], [1, 0], [1, 1]]
y = [0, 0, 0, 1]
model = LogisticRegression(random_state=0).fit(X, y)
print(model.predict([[1, 1]]))
print(model.predict_proba([[1, 1]]))Creates a regularized classifier, fits it to binary samples, then predicts a class and class probabilities.
Binary classification with calibrated class likelihoods
Sparse text or high-dimensional feature matrices
Multiclass classification using penalized multinomial loss
Sparse feature selection with zeroed coefficients
It is a classifier that fits regularized logistic regression. Regularization is enabled by default, and the available solvers determine which penalty and multiclass formulation can be used.
Follow-up: Which solver supports elastic-net regularization? The documentation specifies saga only.
C is the inverse regularization-strength parameter: smaller values impose stronger regularization, while larger values impose weaker regularization. The parameter is positive and defaults to 1.0.
Follow-up: What should be checked after changing C? Verify that the chosen solver and penalty combination remains supported.
For at least three classes, every solver except liblinear optimizes penalized multinomial loss. Liblinear is limited to binary classification unless used inside OneVsRestClassifier.
Follow-up: How can liblinear be used for multiclass data? Wrap the estimator with OneVsRestClassifier to train one binary model per class.
LogisticRegressionCVOneVsRestClassifierSGDClassifierRidgeClassifier