Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Scikit-Learn · Class

PassiveAggressiveClassifier

PassiveAggressiveClassifier is a linear online classifier using passive-aggressive updates. It supports hinge loss for PA-I and squared hinge loss for PA-II, but the class is deprecated in scikit-learn 1.8 and planned for removal in 1.10.

How it works

The estimator learns a linear decision boundary with an online passive-aggressive update rule: it leaves the model unchanged for correctly classified samples with sufficient margin and updates it when the margin is violated. The hinge loss gives PA-I, while squared hinge gives PA-II; fitting can proceed in epochs, and partial_fit supports incremental batches.

Syntax

class sklearn.linear_model.PassiveAggressiveClassifier(*, C=1.0, fit_intercept=True, max_iter=1000, tol=0.001, early_stopping=False, validation_fraction=0.1, n_iter_no_change=5, shuffle=True, verbose=0, loss='hinge', n_jobs=None, random_state=None, warm_start=False, class_weight=None, average=False)

Parameters

NameTypeDescription
Cfloat, default=1.0Aggressiveness parameter for the passive-aggressive algorithm.
fit_interceptbool, default=TrueWhether to fit the intercept.
max_iterint, default=1000Maximum number of passes over the training data.
tolfloat, default=0.001Stopping criterion tolerance.
early_stoppingbool, default=FalseWhether to stop early using a validation fraction.
validation_fractionfloat, default=0.1Proportion of training data reserved for validation when early stopping is enabled.
n_iter_no_changeint, default=5Number of iterations without improvement before stopping.
shufflebool, default=TrueWhether to shuffle training data after each epoch.
verboseint, default=0Verbosity level.
lossstr, default='hinge'Loss function; 'hinge' corresponds to PA-I and 'squared_hinge' to PA-II.
n_jobsint, default=NoneNumber of CPUs used for one-vs-rest computation.
random_stateint, RandomState instance, or None, default=NoneControls pseudo-randomness for shuffling and related operations.

Returns

An estimator object; fit and partial_fit return self.

Key points

  • This class implements a linear passive-aggressive classifier.
  • max_iter sets the maximum number of training passes made by fit.
  • shuffle controls whether training examples are reordered after each epoch.
  • Using hinge loss selects the PA-I formulation.
  • Using squared_hinge selects the PA-II formulation.

Common mistakes

  • This class is deprecated in scikit-learn 1.8 and is scheduled for removal in 1.10; use the documented SGDClassifier replacement instead.
  • max_iter limits passes during fit, but it does not control partial_fit.
  • The loss choice selects the algorithm variant: hinge corresponds to PA-I, and squared_hinge corresponds to PA-II.

Example: Train and predict

from sklearn.datasets import make_classification
from sklearn.linear_model import PassiveAggressiveClassifier

X, y = make_classification(n_samples=100, n_features=4, random_state=0)
clf = PassiveAggressiveClassifier(max_iter=1000, random_state=0)
clf.fit(X, y)
print(clf.predict(X[:5]))

Creates a small binary dataset, trains the classifier, and predicts labels for five samples.

When to use it

Train a linear classifier on large datasets

Large-scale supervised classification

Update a model incrementally with partial_fit

Streaming or batch-at-a-time learning

Classify sparse feature vectors in successive batches

Online text classification

Interview questions

QWhat kind of model is PassiveAggressiveClassifier?

It is an online linear classifier based on the passive-aggressive algorithm. Its C parameter controls aggressiveness, and it supports hinge or squared-hinge loss.

Follow-up: How would you replace it? Use SGDClassifier with loss='hinge', penalty=None, learning_rate='pa1' or 'pa2', and eta0=1.0 for the corresponding C setting.

QHow do fit and partial_fit differ?

fit trains over the data for up to max_iter epochs, while partial_fit updates the model from an individual batch and does not use max_iter.

Follow-up: Why use partial_fit? It enables incremental learning when samples arrive in batches or the complete dataset cannot be held in memory.

QWhat do the loss options mean?

The hinge loss implements PA-I, and squared_hinge implements PA-II. The classifier is intended for large-scale learning and does not require a conventional learning-rate parameter.

Follow-up: What controls the update behavior? C is the aggressiveness parameter, while loss determines the PA-I versus PA-II update formulation.

  • SGDClassifier
  • PassiveAggressiveRegressor
  • Perceptron
  • sklearn.linear_model

Source: PassiveAggressiveClassifier — scikit-learn 1.9.1 documentation. Checked 2026-10-15.