Linear baseline
Build a fast linear baseline for supervised classification.
Scikit-Learn · Class
Perceptron is a linear classifier backed by SGDClassifier. It uses perceptron loss with a constant learning rate and supports optional regularization, early stopping, and incremental fitting.
Perceptron is a linear classifier implemented through SGDClassifier with perceptron loss and a constant learning rate. It learns coefficients and, when enabled, an intercept by repeatedly passing over training data until the iteration limit or stopping criterion is reached.
class sklearn.linear_model.Perceptron(*, penalty=None, alpha=0.0001, l1_ratio=0.15, fit_intercept=True, max_iter=1000, tol=0.001, shuffle=True, verbose=0, eta0=1.0, n_jobs=None, random_state=0, early_stopping=False, validation_fraction=0.1, n_iter_no_change=5, class_weight=None, warm_start=False)| Name | Type | Description |
|---|---|---|
penalty | str or None, default=None | Regularization choice: None, l2, l1, or elasticnet. |
alpha | float, default=0.0001 | Multiplier for the regularization term. |
l1_ratio | float, default=0.15 | Elastic-net mixing value between 0 and 1. |
fit_intercept | bool, default=True | Whether to estimate an intercept. |
max_iter | int, default=1000 | Maximum passes over the training data for fit. |
tol | float or None, default=0.001 | Stopping threshold based on loss improvement. |
shuffle | bool, default=True | Whether to shuffle training data each epoch. |
verbose | int, default=0 | Verbosity level. |
eta0 | float, default=1.0 | Constant learning-rate multiplier. |
n_jobs | int or None, default=None | Number of CPU cores used for prediction, where applicable. |
random_state | int, RandomState instance, or None, default=0 | Controls pseudo-randomness. |
early_stopping | bool, default=False | Whether to use an internal validation split for early stopping. |
A fitted Perceptron estimator from fit; predictions or scores from its estimator methods.
from sklearn.datasets import load_iris
from sklearn.linear_model import Perceptron
X, y = load_iris(return_X_y=True)
model = Perceptron(random_state=0)
model.fit(X, y)
print(model.predict(X[:3]))This trains a perceptron classifier on the Iris data and predicts the first three samples.
Build a fast linear baseline for supervised classification.
Train on data that arrives in batches.
Classify sparse, high-dimensional feature vectors.
Perceptron is a linear classification algorithm. Its implementation fixes SGDClassifier to perceptron loss and a constant learning rate.
Follow-up: How can it be expressed with SGDClassifier? Use SGDClassifier(loss="perceptron", eta0=1, learning_rate="constant", penalty=None).
max_iter is the maximum number of passes over the training data, also called epochs, when using fit. tol can stop training when the loss improvement is too small.
Follow-up: Does max_iter constrain partial_fit? No; the documentation says it affects fit, not partial_fit.
The estimator supports regularization through penalty, with options such as l2, l1, and elasticnet. alpha scales the regularization term, while l1_ratio controls the L1/L2 mixture for elastic net.
Follow-up: What do the extreme l1_ratio values mean? Zero corresponds to L2 and one corresponds to L1.
SGDClassifierLogisticRegressionRidgeClassifierPassiveAggressiveClassifier