mojolearn.IsotonicRegression#

class mojolearn.IsotonicRegression(*, y_min=None, y_max=None, increasing=True, out_of_bounds='nan')[source]#

Bases: NumericModeMixin

Isotonic regression: the best monotone fit of one feature.

Follows scikit-learn’s IsotonicRegression: fits a non-decreasing (or non-increasing) step function by pool-adjacent-violators and predicts by linear interpolation between its thresholds. X is 1-D or of shape (n_samples, 1); rows with zero weight are ignored.

Parameters:
  • y_min (float or None, default None) – Lower bound on the fitted values.

  • y_max (float or None, default None) – Upper bound on the fitted values.

  • increasing (bool or ‘auto’, default True) – Direction of the fit; ‘auto’ uses the sign of Spearman’s rank correlation of X and y.

  • out_of_bounds ({‘nan’, ‘clip’, ‘raise’}, default ‘nan’) – Prediction outside the training range of X: NaN, the nearest end value, or a ValueError.

  • 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:
  • increasing_ (bool) – Direction used by the fit.

  • X_min_ (float) – Smallest training X.

  • X_max_ (float) – Largest training X.

  • X_thresholds_ (float32 array of shape (n_thresholds,)) – Increasing X values of the interpolation knots.

  • y_thresholds_ (float32 array of shape (n_thresholds,)) – Fitted values at X_thresholds_.

  • n_features_in_ (int) – Always 1.

Examples

>>> import numpy as np, mojolearn
>>> rng = np.random.default_rng(0)
>>> x = rng.random(1000, dtype=np.float32)
>>> y = x + 0.1 * rng.standard_normal(1000).astype(np.float32)
>>> model = mojolearn.IsotonicRegression(out_of_bounds="clip").fit(x, y)
>>> y_fit = model.predict(x)
__init__(*, y_min=None, y_max=None, increasing=True, out_of_bounds='nan')[source]#

Methods

fit(X, y[, sample_weight])

Fit the monotone function.

fit_transform(X, y[, sample_weight])

Fit, then return the fitted values at X.

get_params([deep])

numeric_mode_used()

The numeric mode this estimator runs in.

predict(T)

Predict by linear interpolation; same as transform.

set_params(**params)

Set constructor parameters.

transform(T)

Interpolate the fitted function at T.

vendor_used()

The GPU backend this estimator runs on.

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

Fit the monotone function.

Parameters:
  • X (array-like of shape (n_samples,) or (n_samples, 1)) – Training feature, converted to float32.

  • 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 (IsotonicRegression) – The fitted model.

Raises:

ValueError – If out_of_bounds is invalid, X is empty or not 1-D, or the weights are invalid.

predict(T)[source]#

Predict by linear interpolation; same as transform.

Parameters:

T (array-like of shape (n_samples,) or (n_samples, 1)) – Values to predict at.

Returns:

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

transform(T)[source]#

Interpolate the fitted function at T.

Parameters:

T (array-like of shape (n_samples,) or (n_samples, 1)) – Values to transform, converted to float32.

Returns:

y_pred (float32 array of shape (n_samples,)) – Interpolated fitted values; values outside the training range follow out_of_bounds.

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

  • ValueError – With out_of_bounds='raise', if a value of T is outside the training range.

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

Fit, then return the fitted values at X.

Parameters:
  • X (array-like of shape (n_samples,) or (n_samples, 1)) – Training feature.

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

y_fit (float32 array of shape (n_samples,)) – Fitted values.