mojolearn.HuberRegressor#

class mojolearn.HuberRegressor(*, epsilon=1.35, max_iter=100, alpha=0.0001, warm_start=False, fit_intercept=True, tol=1e-05)[source]#

Bases: _LinearRegressorMixin, NumericModeMixin

Linear regression with the Huber loss, robust to outliers.

Follows scikit-learn’s HuberRegressor: an L2-regularized linear model whose scale is estimated jointly with the weights, solved by L-BFGS.

Parameters:
  • epsilon (float, default 1.35) – Residuals larger than epsilon * scale_ count as outliers; must be >= 1.0.

  • max_iter (int, default 100) – Maximum number of L-BFGS iterations.

  • alpha (float, default 0.0001) – L2 regularization strength.

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

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

  • tol (float, default 1e-05) – Stopping tolerance.

  • 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:
  • coef_ (float32 array of shape (n_features,)) – Weights.

  • intercept_ (float) – Intercept.

  • scale_ (float) – Estimated scale of the residuals.

  • n_iter_ (int) – Number of iterations run.

  • outliers_ (list of bool) – For each training row, whether its absolute residual exceeds epsilon * scale_.

  • 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 @ np.arange(8, dtype=np.float32)
>>> model = mojolearn.HuberRegressor().fit(X, y)
__init__(*, epsilon=1.35, max_iter=100, alpha=0.0001, warm_start=False, fit_intercept=True, tol=1e-05)[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) 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,)) – Targets.

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

Returns:

self (HuberRegressor) – The fitted model.

Raises:

ValueError – If epsilon < 1, warm_start is True or the weights are invalid.