nirs4all.operators.models.sklearn.oplsda module
Orthogonal PLS Discriminant Analysis (OPLS-DA) classifier for nirs4all.
See pls.py for full documentation and usage examples.
- class nirs4all.operators.models.sklearn.oplsda.OPLSDA(n_components: int = 1, pls_components: int = 5, scale: bool = True)[source]
Bases:
BaseEstimator,ClassifierMixinOrthogonal PLS Discriminant Analysis (OPLS-DA) classifier.
# Explicitly declare estimator type for sklearn compatibility (e.g., StackingClassifier) _estimator_type = “classifier”
OPLS-DA combines OPLS filtering with PLS-DA classification. It removes Y-orthogonal variation from X before applying PLS-DA, improving class separation and model interpretability.
- Parameters:
- classes_
Unique class labels.
- Type:
ndarray of shape (n_classes,)
- opls_
Fitted OPLS transformer.
- Type:
pyopls.OPLS
Examples
>>> from nirs4all.operators.models.sklearn.pls import OPLSDA >>> from sklearn.datasets import make_classification >>> X, y = make_classification(n_samples=100, n_features=50, n_classes=2, ... n_informative=10, random_state=42) >>> model = OPLSDA(n_components=1, pls_components=5) >>> model.fit(X, y) OPLSDA(n_components=1, pls_components=5) >>> predictions = model.predict(X)
Notes
Requires the pyopls package:
pip install pyoplsSee also
PLSDAStandard PLS-DA without orthogonal filtering.
OPLSOPLS for regression tasks.
References
Bylesjö, M., et al. (2006). OPLS discriminant analysis: combining the strengths of PLS-DA and SIMCA classification. Journal of Chemometrics, 20(8-10), 341-351.
- fit(X, y)[source]
Fit the OPLS-DA model.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Training data.
y (array-like of shape (n_samples,)) – Target class labels.
- Returns:
self – Fitted estimator.
- Return type:
- Raises:
ImportError – If pyopls package is not installed.
- predict(X)[source]
Predict class labels for samples in X.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Samples to predict.
- Returns:
y_pred – Predicted class labels.
- Return type:
ndarray of shape (n_samples,)
- predict_proba(X)[source]
Return pseudo-probabilities (PLS responses).
- Parameters:
X (array-like of shape (n_samples, n_features)) – Samples.
- Returns:
proba – Pseudo-probability estimates.
- Return type:
ndarray of shape (n_samples, n_classes)
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') OPLSDA
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.