mojolearn.PLSCanonical#

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

Bases: _PLS

Partial least squares in canonical form.

Follows scikit-learn’s PLSCanonical: finds paired directions in X and Y with maximal covariance, deflating both blocks symmetrically.

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

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

  • algorithm ({“nipals”, “svd”}, default “nipals”) – How the first singular vectors of each step are found. Any other value raises ValueError at construction.

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

Examples

>>> import numpy as np, mojolearn
>>> rng = np.random.default_rng(0)
>>> X, Y = rng.random((1000, 8), dtype=np.float32), rng.random((1000, 3), dtype=np.float32)
>>> xs, ys = mojolearn.PLSCanonical(n_components=2).fit(X, Y).transform(X, Y)
__init__(n_components=2, *, scale=True, algorithm='nipals', max_iter=500, tol=1e-06, copy=True, numeric_mode=None)[source]#

Methods

fit(X, Y)

Fit the model to X and 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.