Skip to content

OPLS-DA

Bases: ClassifierMixin, BaseEstimator

Binary OPLS Discriminant Analysis.

Parameters mirror :class:~scikit_opls.OPLS. decision_function returns the raw signed OPLS regression output (positive favours classes_[1]) and predict returns class labels from its sign. For class probabilities, wrap in :class:~sklearn.calibration.CalibratedClassifierCV (cross-fitted, robust) when each class has enough samples for the chosen calibration CV split.

Attributes:

Name Type Description
classes_ ndarray

The two class labels seen during fit.

opls_ OPLS

The fitted underlying OPLS regressor against a -1/+1 dummy response.

vip_, ortho_vip_ ndarray of shape (n_features,)

Predictive / orthogonal Variable Importance in Projection scores computed by the inner :attr:opls_. Use with :class:~sklearn.feature_selection.SelectFromModel via importance_getter="vip_".

vip_ property

vip_: NDArray[float64]

Predictive VIP per feature, delegated to the inner OPLS.

ortho_vip_ property

ortho_vip_: NDArray[float64]

Orthogonal VIP per feature, delegated to the inner OPLS.

fit

fit(X: ArrayLike, y: ArrayLike) -> OPLSDA

Fit the binary OPLS-DA classifier.

Parameters:

Name Type Description Default
X array-like of shape (n_samples, n_features)

Training predictors.

required
y array-like of shape (n_samples,)

Binary class labels.

required

Returns:

Name Type Description
self OPLSDA

The fitted estimator.

decision_function

decision_function(X: ArrayLike) -> NDArray[np.float64]

Raw signed OPLS regression output; positive favours classes_[1].

Parameters:

Name Type Description Default
X array-like of shape (n_samples, n_features)

Samples to score.

required

Returns:

Name Type Description
scores ndarray of shape (n_samples,)

Signed confidence; > 0 predicts classes_[1]. Scores equal to zero are assigned to classes_[0] by :meth:predict.

predict

predict(X: ArrayLike) -> NDArray

Predict class labels.

Parameters:

Name Type Description Default
X array-like of shape (n_samples, n_features)

Samples to classify.

required

Returns:

Name Type Description
y_pred ndarray of shape (n_samples,)

Predicted labels drawn from classes_.

score_distance

score_distance(
    X: ArrayLike, *, kind: str = "predictive"
) -> NDArray[np.float64]

Return Hotelling-like score distances from the inner OPLS model.

Parameters:

Name Type Description Default
X array-like of shape (n_samples, n_features)

Samples in raw feature space. Pass raw X. Do not manually center or scale before calling diagnostics. The outer classifier validates feature names and feature counts before delegating to the fitted inner OPLS model.

required
kind ('predictive', 'orthogonal', 'all')

Which coordinate space to use.

"predictive"

Returns:

Name Type Description
score_dist ndarray of shape (n_samples,)

Computed Hotelling-like distance per sample.

q_residuals

q_residuals(
    X: ArrayLike, *, space: str = "full"
) -> NDArray[np.float64]

Return Q residuals from the inner OPLS model.

Parameters:

Name Type Description Default
X array-like of shape (n_samples, n_features)

Samples in raw feature space. Pass raw X. Do not manually center or scale before calling diagnostics. The outer classifier validates feature names and feature counts before delegating to the fitted inner OPLS model.

required
space ('full', 'predictive')

Which model reconstruction space to use.

"full"

Returns:

Name Type Description
q ndarray of shape (n_samples,)

Squared residual norm per sample.