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.
Constructors
new KernelPCA()
new KernelPCA(
opts?):KernelPCA
Parameters
| Parameter | Type | Description |
|---|---|---|
opts? | object | - |
opts.alpha? | number | Hyperparameter of the ridge regression that learns the inverse transform (when fit_inverse_transform=true). |
opts.coef0? | number | Independent term in poly and sigmoid kernels. Ignored by other kernels. |
opts.copy_X? | boolean | If 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? | number | Degree 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? | boolean | Learn 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? | number | Kernel 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? | any | Parameters (keyword arguments) and values for kernel passed as callable object. Ignored by other kernels. |
opts.max_iter? | number | Maximum number of iterations for arpack. If undefined, optimal value will be chosen by arpack. |
opts.n_components? | number | Number of components. If undefined, all non-zero components are kept. |
opts.n_jobs? | number | The 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? | number | Used when eigen_solver == ‘arpack’ or ‘randomized’. Pass an int for reproducible results across multiple function calls. See Glossary. |
opts.remove_zero_eig? | boolean | If 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? | number | Convergence tolerance for arpack. If 0, optimal value will be chosen by arpack. |
Returns KernelPCA
Defined in generated/decomposition/KernelPCA.ts:31
Properties
| Property | Type | Default value | Defined in |
|---|---|---|---|
_isDisposed | boolean | false | generated/decomposition/KernelPCA.ts:29 |
_isInitialized | boolean | false | generated/decomposition/KernelPCA.ts:28 |
_py | PythonBridge | undefined | generated/decomposition/KernelPCA.ts:27 |
id | string | undefined | generated/decomposition/KernelPCA.ts:24 |
opts | any | undefined | generated/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
| Parameter | Type |
|---|---|
pythonBridge | PythonBridge |
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
| Parameter | Type | Description |
|---|---|---|
opts | object | - |
opts.X? | ArrayLike | Training vector, where n_samples is the number of samples and n_features is the number of features. |
opts.y? | any | Not 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
| Parameter | Type | Description |
|---|---|---|
opts | object | - |
opts.params? | any | Parameters (keyword arguments) and values passed to the fit_transform instance. |
opts.X? | ArrayLike | Training vector, where n_samples is the number of samples and n_features is the number of features. |
opts.y? | any | Not 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
| Parameter | Type | Description |
|---|---|---|
opts | object | - |
opts.input_features? | any | Only 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
| Parameter | Type | Description |
|---|---|---|
opts | object | - |
opts.routing? | any | A 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
| Parameter | Type |
|---|---|
py | PythonBridge |
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
| Parameter | Type | Description |
|---|---|---|
opts | object | - |
opts.X? | ArrayLike | Training 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
| Parameter | Type | Description |
|---|---|---|
opts | object | - |
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
| Parameter | Type | Description |
|---|---|---|
opts | object | - |
opts.X? | ArrayLike | Training 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