mojolearn.PLSRegression#

class mojolearn.PLSRegression(n_components=2, *, scale=True, max_iter=500, tol=1e-06, copy=True, numeric_mode=None)[source]#

Bases: _PLS

Partial least squares regression.

Follows scikit-learn’s PLSRegression (NIPALS algorithm). If Y’s residual becomes constant before n_components are found, a warning is issued and fewer components are kept.

Parameters:
  • n_components (int, default 2) – Number of components to keep, between 1 and n_features.

  • scale (bool, default True) – Scale X and Y to unit variance.

  • max_iter (int, default 500) – Maximum NIPALS iterations per component.

  • tol (float, default 1e-06) – NIPALS convergence tolerance.

  • copy (bool, default True) – Accepted for scikit-learn compatibility; inputs are never modified.

  • numeric_mode ({“identical”, “fast”} or None, default None) – Numeric mode for this estimator. None uses the package default ("identical" unless changed). "identical" gives the same bits on NVIDIA and AMD GPUs; "fast" applies on Apple GPUs.

Variables:
  • y_weights_ (x_weights_,)

  • y_loadings_ (x_loadings_,)

  • y_rotations_ (x_rotations_,)

  • coef_ (ndarray of shape (n_targets, n_features))

  • intercept_ (ndarray of shape (n_targets,))

  • n_iter_ (list of int) – NIPALS iterations for each component.

  • n_features_in_ (int)

  • y_scores_ (x_scores_,) – Scores of the training data.

Examples

>>> import numpy as np, mojolearn
>>> rng = np.random.default_rng(0)
>>> X = rng.random((1000, 8), dtype=np.float32)
>>> y = X @ rng.random(8, dtype=np.float32)
>>> pred = mojolearn.PLSRegression(n_components=2).fit(X, y).predict(X)
__init__(n_components=2, *, scale=True, max_iter=500, tol=1e-06, copy=True, numeric_mode=None)#

Methods

fit(X[, y, Y])

Fit the model to X and the targets (y or Y).

fit_transform(X[, y])

Fit the model, then return transform(X, y).

get_params([deep])

Return this estimator's constructor parameters.

inverse_transform(X[, y, Y])

Map scores back to the original X (and optionally Y) space.

predict(X[, copy])

Predict targets for X.

set_params(**params)

Set constructor parameters by keyword.

transform(X[, y, Y, copy])

Project X (and optionally Y) onto the fitted rotations.

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

Fit the model to X and the targets (y or Y).

Parameters:
  • X (array-like of shape (n_samples, n_features))

  • y, Y (array-like of shape (n_samples,) or (n_samples, n_targets)) – Targets (either name).

Returns:

self