skkda.base module#

Scikit-learn-compatible Kernel Discriminant Analysis.

Used in David Diaz-Vico, Jose R. Dorronsoro “Deep vs Kernel Fisher Discriminant Analysis”

Based on algorithm 5 in Zhihua Zhang, Guang Dai, Congfu Xu, Michael I. Jordan “Regularized Discriminant Analysis, Ridge Regression and Beyond” http://www.jmlr.org/papers/v11/zhang10b.html

@author: David Diaz Vico @license: MIT

class skkda.base.KernelDiscriminantAnalysis(lmb=0.001, kernel='rbf', degree=3, gamma=None, coef0=1)[source]#

Bases: BaseEstimator, ClassifierMixin, TransformerMixin

Kernel Discriminant Analysis.

Parameters:
  • lmb (float (>= 0.0), default=0.001) – Regularization parameter

  • kernel ({"chi2", "laplacian", "linear", "polynomial", "rbf", "sigmoid"},) – default=’rbf’ Kernel.

  • degree (integer, default=3)

  • gamma (float, default=None)

  • coef0 (integer, default=1)

fit(X, y)[source]#

Fit KFDA model.

Parameters:
  • X (numpy array of shape [n_samples, n_features]) – Training set.

  • y (numpy array of shape [n_samples]) – Target values. Only works for 2 classes.

Return type:

self

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') KernelDiscriminantAnalysis#

Configure whether metadata should be requested to be passed to the score method.

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 (see sklearn.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 to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

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

Parameters:

sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for sample_weight parameter in score.

Returns:

self – The updated object.

Return type:

object

transform(X)[source]#

Transform data with the trained KFDA model.

Parameters:

X (numpy array of shape [n_samples, n_features]) – The input data.

Returns:

y_pred – Transformations for X.

Return type:

array-like, shape (n_samples, targets_shape)