mojolearn.PassiveAggressiveRegressor#
- class mojolearn.PassiveAggressiveRegressor(*, 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='epsilon_insensitive', epsilon=0.1, random_state=None, warm_start=False, average=False, batch_size=256)[source]#
Bases:
_LinearRegressorMixin,NumericModeMixinPassive-aggressive regressor (PA-I or PA-II).
Follows scikit-learn’s PassiveAggressiveRegressor:
loss='epsilon_insensitive'is PA-I and'squared_epsilon_insensitive'is PA-II. Unlike scikit-learn, the default fit runs minibatches ofbatch_size=256rows;batch_size=0gives 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 ({‘epsilon_insensitive’, ‘squared_epsilon_insensitive’}, default ‘epsilon_insensitive’) – PA-I or PA-II.
epsilon (float, default 0.1) – Residuals smaller than this cause no update.
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.
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 (seemojolearn.set_numeric_mode()).
- Variables:
Examples
>>> import numpy as np, mojolearn >>> rng = np.random.default_rng(0) >>> X = rng.random((1000, 8), dtype=np.float32) >>> y = X @ np.arange(8, dtype=np.float32) >>> model = mojolearn.PassiveAggressiveRegressor().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='epsilon_insensitive', epsilon=0.1, random_state=None, warm_start=False, average=False, batch_size=256)[source]#
Methods
fit(X, y[, sample_weight])Fit the model.
get_params([deep])numeric_mode_used()The numeric mode this estimator runs in.
predict(X)Predict targets for
X.score(X, y)Coefficient of determination R^2 of
predict(X)againsty.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,)) – Targets.
sample_weight (array-like of shape (n_samples,) or float, optional) – Non-negative weights with a positive sum.
- Returns:
self (PassiveAggressiveRegressor) – The fitted model.
- Raises:
ValueError – On an unsupported option or loss,
C <= 0, invalid weights, or a floating-point overflow during training.