Documentation
Classes
KernelPCA

KernelPCA

Kernel Principal component analysis (KPCA) [1].

Non-linear dimensionality reduction through the use of kernels (see Pairwise metrics, Affinities and Kernels).

It uses the scipy.linalg.eigh (opens in a new tab) LAPACK implementation of the full SVD or the scipy.sparse.linalg.eigsh (opens in a new tab) 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.

Read more in the User Guide.

Python Reference (opens in a new tab)

Constructors

constructor()

Signature

new KernelPCA(opts?: object): KernelPCA;

Parameters

NameTypeDescription
opts?object-
opts.alpha?numberHyperparameter of the ridge regression that learns the inverse transform (when fit_inverse_transform=true). Default Value 1
opts.coef0?numberIndependent term in poly and sigmoid kernels. Ignored by other kernels. Default Value 1
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. Default Value true
opts.degree?numberDegree for poly kernels. Ignored by other kernels. Default Value 3
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]. Default Value 'auto'
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]. Default Value false
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. Default Value 'auto'
opts.kernel?"sigmoid" | "precomputed" | "linear" | "poly" | "rbf" | "cosine"Kernel used for PCA. Default Value 'linear'
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 (opens in a new tab) 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. Default Value false
opts.tol?numberConvergence tolerance for arpack. If 0, optimal value will be chosen by arpack. Default Value 0

Returns

KernelPCA

Defined in: generated/decomposition/KernelPCA.ts:27 (opens in a new tab)

Properties

_isDisposed

boolean = false

Defined in: generated/decomposition/KernelPCA.ts:25 (opens in a new tab)

_isInitialized

boolean = false

Defined in: generated/decomposition/KernelPCA.ts:24 (opens in a new tab)

_py

PythonBridge

Defined in: generated/decomposition/KernelPCA.ts:23 (opens in a new tab)

id

string

Defined in: generated/decomposition/KernelPCA.ts:20 (opens in a new tab)

opts

any

Defined in: generated/decomposition/KernelPCA.ts:21 (opens in a new tab)

Accessors

X_fit_

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.

Signature

X_fit_(): Promise<ArrayLike[]>;

Returns

Promise<ArrayLike[]>

Defined in: generated/decomposition/KernelPCA.ts:539 (opens in a new tab)

X_transformed_fit_

Projection of the fitted data on the kernel principal components. Only available when fit\_inverse\_transform is true.

Signature

X_transformed_fit_(): Promise<ArrayLike[]>;

Returns

Promise<ArrayLike[]>

Defined in: generated/decomposition/KernelPCA.ts:514 (opens in a new tab)

dual_coef_

Inverse transform matrix. Only available when fit\_inverse\_transform is true.

Signature

dual_coef_(): Promise<ArrayLike[]>;

Returns

Promise<ArrayLike[]>

Defined in: generated/decomposition/KernelPCA.ts:491 (opens in a new tab)

eigenvalues_

Eigenvalues of the centered kernel matrix in decreasing order. If n\_components and remove\_zero\_eig are not set, then all values are stored.

Signature

eigenvalues_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/decomposition/KernelPCA.ts:441 (opens in a new tab)

eigenvectors_

Eigenvectors of the centered kernel matrix. If n\_components and remove\_zero\_eig are not set, then all components are stored.

Signature

eigenvectors_(): Promise<ArrayLike[]>;

Returns

Promise<ArrayLike[]>

Defined in: generated/decomposition/KernelPCA.ts:466 (opens in a new tab)

feature_names_in_

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

Signature

feature_names_in_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/decomposition/KernelPCA.ts:587 (opens in a new tab)

n_features_in_

Number of features seen during fit.

Signature

n_features_in_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/decomposition/KernelPCA.ts:562 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/decomposition/KernelPCA.ts:132 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/decomposition/KernelPCA.ts:136 (opens in a new tab)

Methods

dispose()

Disposes of the underlying Python resources.

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

Signature

dispose(): Promise<void>;

Returns

Promise<void>

Defined in: generated/decomposition/KernelPCA.ts:200 (opens in a new tab)

fit()

Fit the model from data in X.

Signature

fit(opts: object): Promise<any>;

Parameters

NameTypeDescription
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:217 (opens in a new tab)

fit_transform()

Fit the model from data in X and transform X.

Signature

fit_transform(opts: object): Promise<ArrayLike[]>;

Parameters

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

Returns

Promise<ArrayLike[]>

Defined in: generated/decomposition/KernelPCA.ts:255 (opens in a new tab)

get_feature_names_out()

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"\].

Signature

get_feature_names_out(opts: object): Promise<any>;

Parameters

NameTypeDescription
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:302 (opens in a new tab)

init()

Initializes the underlying Python resources.

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

Signature

init(py: PythonBridge): Promise<void>;

Parameters

NameType
pyPythonBridge

Returns

Promise<void>

Defined in: generated/decomposition/KernelPCA.ts:145 (opens in a new tab)

inverse_transform()

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.

Signature

inverse_transform(opts: object): Promise<ArrayLike[]>;

Parameters

NameTypeDescription
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:340 (opens in a new tab)

set_output()

Set output container.

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

Signature

set_output(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.transform?"default" | "pandas"Configure output of transform and fit\_transform.

Returns

Promise<any>

Defined in: generated/decomposition/KernelPCA.ts:375 (opens in a new tab)

transform()

Transform X.

Signature

transform(opts: object): Promise<ArrayLike[]>;

Parameters

NameTypeDescription
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:408 (opens in a new tab)