Class: KernelPCA

Kernel Principal component analysis (KPCA).

Non-linear dimensionality reduction through the use of kernels [1], see also Pairwise metrics, Affinities and Kernels.

It uses the scipy.linalg.eigh LAPACK implementation of the full SVD or the scipy.sparse.linalg.eigsh ARPACK implementation of the truncated SVD, depending on the shape of the input data and the number of components to extract. It can also use a randomized truncated SVD by the method proposed in [3], see eigen_solver.

For a usage example and comparison between Principal Components Analysis (PCA) and its kernelized version (KPCA), see Kernel PCA.

For a usage example in denoising images using KPCA, see Image denoising using kernel PCA.

Read more in the User Guide.

Python Reference

Constructors

new KernelPCA()

new KernelPCA(opts?): KernelPCA

Parameters

ParameterTypeDescription
opts?object-
opts.alpha?numberHyperparameter of the ridge regression that learns the inverse transform (when fit_inverse_transform=true).
opts.coef0?numberIndependent term in poly and sigmoid kernels. Ignored by other kernels.
opts.copy_X?booleanIf true, input X is copied and stored by the model in the X_fit_ attribute. If no further changes will be done to X, setting copy_X=False saves memory by storing a reference.
opts.degree?numberDegree for poly kernels. Ignored by other kernels.
opts.eigen_solver?"auto" | "randomized" | "arpack" | "dense"Select eigensolver to use. If n_components is much less than the number of training samples, randomized (or arpack to a smaller extent) may be more efficient than the dense eigensolver. Randomized SVD is performed according to the method of Halko et al [3].
opts.fit_inverse_transform?booleanLearn the inverse transform for non-precomputed kernels (i.e. learn to find the pre-image of a point). This method is based on [2].
opts.gamma?numberKernel coefficient for rbf, poly and sigmoid kernels. Ignored by other kernels. If gamma is undefined, then it is set to 1/n_features.
opts.iterated_power?"auto"Number of iterations for the power method computed by svd_solver == ‘randomized’. When ‘auto’, it is set to 7 when n_components < 0.1 \* min(X.shape), other it is set to 4.
opts.kernel?"sigmoid" | "precomputed" | "linear" | "poly" | "rbf" | "cosine"Kernel used for PCA.
opts.kernel_params?anyParameters (keyword arguments) and values for kernel passed as callable object. Ignored by other kernels.
opts.max_iter?numberMaximum number of iterations for arpack. If undefined, optimal value will be chosen by arpack.
opts.n_components?numberNumber of components. If undefined, all non-zero components are kept.
opts.n_jobs?numberThe number of parallel jobs to run. undefined means 1 unless in a joblib.parallel_backend context. \-1 means using all processors. See Glossary for more details.
opts.random_state?numberUsed when eigen_solver == ‘arpack’ or ‘randomized’. Pass an int for reproducible results across multiple function calls. See Glossary.
opts.remove_zero_eig?booleanIf true, then all components with zero eigenvalues are removed, so that the number of components in the output may be < n_components (and sometimes even zero due to numerical instability). When n_components is undefined, this parameter is ignored and components with zero eigenvalues are removed regardless.
opts.tol?numberConvergence tolerance for arpack. If 0, optimal value will be chosen by arpack.

Returns KernelPCA

Defined in generated/decomposition/KernelPCA.ts:31

Properties

PropertyTypeDefault valueDefined in
_isDisposedbooleanfalsegenerated/decomposition/KernelPCA.ts:29
_isInitializedbooleanfalsegenerated/decomposition/KernelPCA.ts:28
_pyPythonBridgeundefinedgenerated/decomposition/KernelPCA.ts:27
idstringundefinedgenerated/decomposition/KernelPCA.ts:24
optsanyundefinedgenerated/decomposition/KernelPCA.ts:25

Accessors

dual_coef_

Get Signature

get dual_coef_(): Promise<ArrayLike[]>

Inverse transform matrix. Only available when fit_inverse_transform is true.

Returns Promise<ArrayLike[]>

Defined in generated/decomposition/KernelPCA.ts:505


eigenvalues_

Get Signature

get eigenvalues_(): Promise<ArrayLike>

Eigenvalues of the centered kernel matrix in decreasing order. If n_components and remove_zero_eig are not set, then all values are stored.

Returns Promise<ArrayLike>

Defined in generated/decomposition/KernelPCA.ts:455


eigenvectors_

Get Signature

get eigenvectors_(): Promise<ArrayLike[]>

Eigenvectors of the centered kernel matrix. If n_components and remove_zero_eig are not set, then all components are stored.

Returns Promise<ArrayLike[]>

Defined in generated/decomposition/KernelPCA.ts:480


feature_names_in_

Get Signature

get feature_names_in_(): Promise<ArrayLike>

Names of features seen during fit. Defined only when X has feature names that are all strings.

Returns Promise<ArrayLike>

Defined in generated/decomposition/KernelPCA.ts:601


gamma_

Get Signature

get gamma_(): Promise<number>

Kernel coefficient for rbf, poly and sigmoid kernels. When gamma is explicitly provided, this is just the same as gamma. When gamma is undefined, this is the actual value of kernel coefficient.

Returns Promise<number>

Defined in generated/decomposition/KernelPCA.ts:626


n_features_in_

Get Signature

get n_features_in_(): Promise<number>

Number of features seen during fit.

Returns Promise<number>

Defined in generated/decomposition/KernelPCA.ts:576


py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/decomposition/KernelPCA.ts:136


X_fit_

Get Signature

get X_fit_(): Promise<ArrayLike[]>

The data used to fit the model. If copy_X=False, then X_fit_ is a reference. This attribute is used for the calls to transform.

Returns Promise<ArrayLike[]>

Defined in generated/decomposition/KernelPCA.ts:553


X_transformed_fit_

Get Signature

get X_transformed_fit_(): Promise<ArrayLike[]>

Projection of the fitted data on the kernel principal components. Only available when fit_inverse_transform is true.

Returns Promise<ArrayLike[]>

Defined in generated/decomposition/KernelPCA.ts:528

Methods

dispose()

dispose(): Promise<void>

Disposes of the underlying Python resources.

Once dispose() is called, the instance is no longer usable.

Returns Promise<void>

Defined in generated/decomposition/KernelPCA.ts:187


fit()

fit(opts): Promise<any>

Fit the model from data in X.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLikeTraining vector, where n_samples is the number of samples and n_features is the number of features.
opts.y?anyNot used, present for API consistency by convention.

Returns Promise<any>

Defined in generated/decomposition/KernelPCA.ts:204


fit_transform()

fit_transform(opts): Promise<ArrayLike[]>

Fit the model from data in X and transform X.

Parameters

ParameterTypeDescription
optsobject-
opts.params?anyParameters (keyword arguments) and values passed to the fit_transform instance.
opts.X?ArrayLikeTraining vector, where n_samples is the number of samples and n_features is the number of features.
opts.y?anyNot used, present for API consistency by convention.

Returns Promise<ArrayLike[]>

Defined in generated/decomposition/KernelPCA.ts:241


get_feature_names_out()

get_feature_names_out(opts): Promise<any>

Get output feature names for transformation.

The feature names out will prefixed by the lowercased class name. For example, if the transformer outputs 3 features, then the feature names out are: \["class_name0", "class_name1", "class_name2"\].

Parameters

ParameterTypeDescription
optsobject-
opts.input_features?anyOnly used to validate feature names with the names seen in fit.

Returns Promise<any>

Defined in generated/decomposition/KernelPCA.ts:285


get_metadata_routing()

get_metadata_routing(opts): Promise<any>

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Parameters

ParameterTypeDescription
optsobject-
opts.routing?anyA MetadataRequest encapsulating routing information.

Returns Promise<any>

Defined in generated/decomposition/KernelPCA.ts:321


init()

init(py): Promise<void>

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Parameters

ParameterType
pyPythonBridge

Returns Promise<void>

Defined in generated/decomposition/KernelPCA.ts:149


inverse_transform()

inverse_transform(opts): Promise<ArrayLike[]>

Transform X back to original space.

inverse_transform approximates the inverse transformation using a learned pre-image. The pre-image is learned by kernel ridge regression of the original data on their low-dimensional representation vectors.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLikeTraining vector, where n_samples is the number of samples and n_features is the number of features.

Returns Promise<ArrayLike[]>

Defined in generated/decomposition/KernelPCA.ts:357


set_output()

set_output(opts): Promise<any>

Set output container.

See Introducing the set_output API for an example on how to use the API.

Parameters

ParameterTypeDescription
optsobject-
opts.transform?"default" | "pandas" | "polars"Configure output of transform and fit_transform.

Returns Promise<any>

Defined in generated/decomposition/KernelPCA.ts:391


transform()

transform(opts): Promise<ArrayLike[]>

Transform X.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLikeTraining vector, where n_samples is the number of samples and n_features is the number of features.

Returns Promise<ArrayLike[]>

Defined in generated/decomposition/KernelPCA.ts:423