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)#

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' 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)

See also

User guide: Linear models

Choosing an estimator

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)#

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.

numeric_mode_used()#

The numeric mode this estimator runs in.

Returns:

str – 'identical' or 'fast', read from the compiled binary the estimator uses, not from the argument it was given.

predict(X)#

Predict targets for X.

Returns X @ coef_ + intercept_; models with a log link (Poisson, Gamma and Tweedie with power > 0) return its exponential.

Parameters:

X (array-like of shape (n_samples, n_features)) – Samples, converted to float32. The feature count must match the one seen in fit.

Returns:

y_pred (float32 array of shape (n_samples,)) – Predicted values.

Raises:
  • RuntimeError – If the model is not fitted.

  • ValueError – If X has a different number of features than in fit.

score(X, y)#

Coefficient of determination R^2 of predict(X) against y.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Test samples.

  • y (array-like of shape (n_samples,)) – True targets.

Returns:

score (float) – R^2; 1.0 is a perfect fit.

set_params(**params)#

Set constructor parameters. The estimator is rebuilt through its constructor, so every constructor check runs again and any fitted state is dropped, as a new setting invalidates it.

vendor_used()#

The GPU backend this estimator runs on.

Returns:

str – 'metal', 'cuda' or 'hip', read from the compiled binary the estimator uses.