mojolearn.QuantileRegressor#

class mojolearn.QuantileRegressor(*, quantile=0.5, alpha=1.0, fit_intercept=True, solver='highs', solver_options=None, max_iter=5000, tol=0.0001)[source]#

Bases: _LinearRegressorMixin, NumericModeMixin

Linear regression that predicts a conditional quantile.

Solves scikit-learn’s QuantileRegressor problem (the pinball loss plus an L1 penalty) with ADMM instead of a linear program, so results agree with scikit-learn up to the solver tolerance. solver accepts scikit-learn’s names but always runs ADMM; max_iter and tol are mojolearn’s own keywords.

Parameters:
  • quantile (float, default 0.5) – Quantile to predict, strictly between 0 and 1.

  • alpha (float, default 1.0) – L1 regularization strength (>= 0).

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

  • solver (str, default ‘highs’) – Accepted for compatibility; the fit always runs ADMM.

  • solver_options (dict or None, default None) – Accepted for compatibility; ignored.

  • max_iter (int, default 5000) – Maximum number of ADMM iterations.

  • tol (float, default 1e-4) – ADMM relative tolerance; the absolute tolerance is tol / 100.

  • 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.

  • n_iter_ (int) – Number of ADMM iterations run.

  • 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] + rng.standard_normal(1000).astype(np.float32)
>>> model = mojolearn.QuantileRegressor(quantile=0.9, alpha=0.0).fit(X, y)
__init__(*, quantile=0.5, alpha=1.0, fit_intercept=True, solver='highs', solver_options=None, max_iter=5000, tol=0.0001)[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 (QuantileRegressor) – The fitted model.

Raises:

ValueError – If quantile is not in (0, 1), alpha is negative or the weights are invalid.