Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Scikit learn Scikit learn KernelPCA

From Leeroopedia
Revision as of 16:35, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Scikit_learn_Scikit_learn_KernelPCA.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Dimensionality Reduction, Kernel Methods
Last Updated 2026-02-08 15:00 GMT

Overview

Concrete tool for non-linear dimensionality reduction through kernel principal component analysis provided by scikit-learn.

Description

KernelPCA performs non-linear dimensionality reduction by applying PCA in a high-dimensional feature space induced by a kernel function. It uses the LAPACK implementation of full SVD or the ARPACK implementation of truncated SVD, depending on the input data shape and number of components to extract. It also supports a randomized truncated SVD solver. Multiple kernel functions are available including linear, polynomial, RBF, sigmoid, and cosine, as well as precomputed kernel matrices.

Usage

Use KernelPCA when you need to capture non-linear relationships in your data that standard PCA would miss. It is ideal for non-linear feature extraction, manifold learning, and denoising applications where the underlying data structure is not well represented by linear projections.

Code Reference

Source Location

Signature

class KernelPCA(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstimator):
    def __init__(
        self,
        n_components=None,
        *,
        kernel="linear",
        gamma=None,
        degree=3,
        coef0=1,
        kernel_params=None,
        alpha=1.0,
        fit_inverse_transform=False,
        eigen_solver="auto",
        tol=0,
        max_iter=None,
        iterated_power="auto",
        remove_zero_eig=False,
        random_state=None,
        copy_X=True,
        n_jobs=None,
    ):

Import

from sklearn.decomposition import KernelPCA

I/O Contract

Inputs

Name Type Required Description
n_components int No Number of components. If None, all non-zero components are kept.
kernel str or callable No Kernel function: 'linear', 'poly', 'rbf', 'sigmoid', 'cosine', 'precomputed', or callable (default='linear').
gamma float No Kernel coefficient for rbf, poly, and sigmoid kernels. Defaults to 1/n_features.
degree float No Degree for poly kernels (default=3).
coef0 float No Independent term in poly and sigmoid kernels (default=1).
kernel_params dict No Parameters for callable kernel.
alpha float No Ridge regression hyperparameter for inverse transform (default=1.0).
fit_inverse_transform bool No Whether to learn the inverse transform (default=False).
eigen_solver str No Solver: 'auto', 'dense', 'arpack', or 'randomized' (default='auto').
tol float No Convergence tolerance for arpack solver (default=0).
max_iter int No Maximum number of iterations for arpack solver.
random_state int or RandomState No Random state for reproducibility.

Outputs

Name Type Description
eigenvalues_ ndarray of shape (n_components,) Eigenvalues of the centered kernel matrix in decreasing order.
eigenvectors_ ndarray of shape (n_samples, n_components) Eigenvectors of the centered kernel matrix.
dual_coef_ ndarray of shape (n_samples, n_features) Inverse transform matrix (only available when fit_inverse_transform=True).
X_fit_ ndarray of shape (n_samples, n_features) The data used to fit the model.
n_features_in_ int Number of features seen during fit.

Usage Examples

Basic Usage

import numpy as np
from sklearn.decomposition import KernelPCA

X = np.array([[1, 2], [3, 4], [5, 6], [7, 8]], dtype=float)
kpca = KernelPCA(n_components=2, kernel='rbf', gamma=0.1)
X_transformed = kpca.fit_transform(X)
print(X_transformed.shape)  # (4, 2)
print(kpca.eigenvalues_)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment