metabci.brainda.algorithms.decomposition.SKLDA module¶
Shrinkage Linear Discriminant Analysis (SKLDA) algorithm, through the optimization of local features to achieve the purpose ofreducing the dimensionality of the data, can improve the small sample problem of the LDA algorithm to some extent.
author: OrionHan
email: jinhan9165@gmail.com
Created on: date (e.g.2022-02-15)
- update log:
2023/12/08 by Yin ZiFan, promise010818@gmail.com, update code annotation
- Refer: [1] Blankertz, et al. “Single-trial analysis and classification of ERP components—a tutorial.”
NeuroImage 56.2 (2011): 814-825.
Application:
- class metabci.brainda.algorithms.decomposition.SKLDA.SKLDA[source]¶
Bases:
BaseEstimator,TransformerMixin,ClassifierMixinShrinkage Linear discriminant analysis (SKLDA) for BCI.
- avg_feats1¶
mean feature vector of class 1.
- Type:
ndarray of shape (n_features,)
- avg_feats2¶
mean feature vector of class 2.
- Type:
ndarray of shape (n_features,)
- sigma_c1¶
empirical covariance matrix of class 1.
- Type:
ndarray of shape (n_features, n_features)
- sigma_c2¶
empirical covariance matrix of class 2.
- Type:
ndarray of shape (n_features, n_features)
- D¶
the dimensionality of the feature space.
- Type:
int, (=n_features)
- nu_c1¶
for sigma penalty calculation in class 1.
- Type:
float
- nu_c2¶
for sigma penalty calculation in class 2.
- Type:
float
- classes_¶
Class labels.
- Type:
ndarray
- n_features¶
Number of features of the training data.
- Type:
int
- n_samples_c2¶
Number of samples in class 2.
- Type:
int
- n_samples_c1¶
Number of samples in class 1.
- Type:
int
Tip
A example using SKLDA¶import numpy as np from metabci.brainda.algorithms.decomposition import SKLDA Xtrain = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]]) y = np.array([1, 1, 1, 2, 2, 2]) Xtest = np.array([[-0.8, -1], [-1.2, -1], [1.2, 1], [0.5, 2]]) clf2 = SKLDA() clf2.fit(Xtrain, y) print(clf2.transform(Xtest))
- fit(X: ndarray, y: ndarray)[source]¶
Train the model, Fit SKLDA.
- Parameters:
X1 (ndarray of shape (n_samples, n_features)) – samples for class 1 (i.e. positive samples)
X2 (ndarray of shape (n_samples, n_features)) – samples for class 2 (i.e. negative samples)
X (array-like of shape (n_samples, n_features)) – Training data.
y (array-like of shape (n_samples,)) – Target values, {-1, 1} or {0, 1}.
- Returns:
self – Some parameters (sigma_c1, sigma_c2, D) of SKLDA.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') SKLDA¶
Request metadata passed to the
scoremethod.Note that this method is only relevant if
enable_metadata_routing=True(seesklearn.set_config()). Please see 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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter inscore.- Returns:
self – The updated object.
- Return type:
object
- set_transform_request(*, Xtest: bool | None | str = '$UNCHANGED$') SKLDA¶
Request metadata passed to the
transformmethod.Note that this method is only relevant if
enable_metadata_routing=True(seesklearn.set_config()). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed totransformif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it totransform.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline. Otherwise it has no effect.- Parameters:
Xtest (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
Xtestparameter intransform.- Returns:
self – The updated object.
- Return type:
object