Minibatch or out-of-core classification
Large labeled datasets that can be processed in chunks.
Scikit-Learn · Class
SGDClassifier trains regularized linear classifiers with stochastic gradient descent. It supports configurable losses, sparse or dense floating-point features, and incremental learning through partial_fit.
SGDClassifier fits a regularized linear classification model by estimating each sample's loss gradient and updating parameters using a decreasing learning-rate schedule. The selected loss determines the model behavior; partial_fit supports incremental or out-of-core training, while suitable feature scaling can improve results with the default schedule.
SGDClassifier(loss='hinge', *, penalty='l2', alpha=0.0001, l1_ratio=0.15, fit_intercept=True, max_iter=1000, tol=0.001, shuffle=True, verbose=0, epsilon=0.1, n_jobs=None, random_state=None, learning_rate='optimal', eta0=0.0, power_t=0.5, early_stopping=False, validation_fraction=0.1, n_iter_no_change=5, class_weight=None, warm_start=False, average=False)| Name | Type | Description |
|---|---|---|
loss | str, default='hinge' | The loss function to use; the default is hinge. |
penalty | str, default='l2' | The penalty specification used for regularization. |
max_iter | int, default=1000 | The maximum number of passes over the training data for fit. |
learning_rate | str, default='optimal' | The learning-rate schedule. |
alpha | float, default=0.0001 | The coefficient used to multiply the regularization term. |
average | bool or int, default=False | Whether to use averaged SGD. |
fit_intercept | bool, default=True | Whether to fit the intercept. |
random_state | int, RandomState instance or None, default=None | The random seed used for shuffling and reproducibility. |
An SGDClassifier estimator object.
partial_fit to process data incrementally or in minibatches.loss setting.average=True when appropriate.from sklearn.linear_model import SGDClassifier
X = [[0., 0.], [1., 1.], [1., 0.], [0., 1.]]
y = [0, 1, 1, 0]
clf = SGDClassifier(loss="hinge", penalty="l2", max_iter=1000, random_state=0)
clf.fit(X, y)
print(clf.predict([[0.8, 0.8]]))Creates a regularized linear classifier, trains it on labeled samples, and predicts a class for a new sample.
Large labeled datasets that can be processed in chunks.
Sparse feature representations such as high-dimensional text features.
Tasks needing different linear classification objectives.
Models where a lower-variance online estimate is useful.
It is a linear classifier trained with regularized stochastic gradient descent. The gradient is estimated one sample at a time, and the parameters are updated under a decreasing learning-rate schedule.
Follow-up: How would you train when the full dataset cannot fit in memory? Use partial_fit for minibatch or out-of-core updates.
The loss parameter selects the classification objective; with the default loss, the estimator fits a linear support vector machine. Other supported losses can produce different linear-model behavior.
Follow-up: What is one practical choice for probability-like outputs? Select a probabilistic loss such as log_loss, then use the estimator's probability methods when supported.
fit trains for up to max_iter passes over the training data. partial_fit is intended for incremental updates and is not governed by max_iter.
Follow-up: What preprocessing is especially useful with the default schedule? Scale features to approximately zero mean and unit variance.
SGDRegressorLogisticRegressionLinearSVCsklearn.linear_model