mojolearn.PassiveAggressiveClassifier#

class mojolearn.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, batch_size=256)[source]#

Bases: _LinearClassifierMixin, NumericModeMixin

Passive-aggressive classifier (PA-I or PA-II).

Follows scikit-learn’s PassiveAggressiveClassifier, one-vs-rest for more than two classes: loss='hinge' is PA-I and 'squared_hinge' is PA-II. Unlike scikit-learn, the default fit runs minibatches of batch_size=256 rows; batch_size=0 gives scikit-learn’s per-sample updates.

Parameters:
  • C (float, default 1.0) – Maximum step size (> 0).

  • fit_intercept (bool, default True) – Whether to fit an intercept.

  • max_iter (int, default 1000) – Maximum number of passes over the data.

  • tol (float or None, default 1e-3) – Stopping tolerance, as in scikit-learn; None disables it.

  • early_stopping (bool, default False) – Not supported: True raises ValueError.

  • validation_fraction (float, default 0.1) – Accepted for compatibility; ignored (early stopping is not supported).

  • n_iter_no_change (int, default 5) – Passes without improvement before stopping.

  • shuffle (bool, default True) – Whether to shuffle the rows each pass.

  • verbose (int, default 0) – Accepted for compatibility; ignored.

  • loss ({‘hinge’, ‘squared_hinge’}, default ‘hinge’) – PA-I (‘hinge’) or PA-II (‘squared_hinge’).

  • n_jobs (int or None, default None) – Accepted for compatibility; ignored.

  • random_state (int or None, default None) – Non-negative seed for shuffling. None means seed 0.

  • warm_start (bool, default False) – Not supported: True raises ValueError.

  • class_weight (dict, ‘balanced’ or None, default None) – Per-class weights; ‘balanced’ weighs classes inversely to their frequency.

  • average (bool, default False) – Not supported: True raises ValueError.

  • batch_size (int, default 256) – Rows per minibatch step; 0 runs per-sample updates.

  • numeric_mode (str or None, default None) – Numeric mode for this model ('identical', 'deterministic' or 'fast', which runs on Apple GPUs only); None uses the process default (see mojolearn.set_numeric_mode()).

Variables:
  • classes_ (array of shape (n_classes,)) – Class labels.

  • coef_ (float32 array of shape (1, n_features) or (n_classes, n_features)) – Weights; one row for a binary problem.

  • intercept_ (float32 array of shape (1,) or (n_classes,)) – Intercepts.

  • n_iter_ (int) – Number of passes run.

  • t_ (float) – Number of weight updates, n_iter_ * n_samples + 1.

  • n_features_in_ (int) – Number of features seen in fit.

Examples

>>> import numpy as np, mojolearn
>>> rng = np.random.default_rng(0)
>>> X = rng.random((1000, 8), dtype=np.float32)
>>> y = (X[:, 0] > X[:, 1]).astype(np.int32)
>>> model = mojolearn.PassiveAggressiveClassifier().fit(X, y)
__init__(*, 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, batch_size=256)[source]#

Methods

decision_function(X)

Signed distance of each sample to the separating hyperplane(s).

fit(X, y[, sample_weight])

Fit the model.

get_params([deep])

numeric_mode_used()

The numeric mode this estimator runs in.

predict(X)

Predict class labels.

score(X, y)

Mean accuracy of predict(X) against y.

set_params(**params)

Set constructor parameters.

vendor_used()

The GPU backend this estimator runs on.

fit(X, y, sample_weight=None)[source]#

Fit the model.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Training data, converted to float32; values must be finite.

  • y (array-like of shape (n_samples,)) – Class labels; at least two classes.

  • sample_weight (array-like of shape (n_samples,) or float, optional) – Non-negative weights with a positive sum.

Returns:

self (PassiveAggressiveClassifier) – The fitted model.

Raises:

ValueError – On an unsupported option or loss, C <= 0, a single class, invalid weights, or a floating-point overflow during training.