KernelPCADetector<T>

Models & Types · AiDotNet.AnomalyDetection.Linear

Detects anomalies using Kernel PCA reconstruction error.

Inheritance: ModelBase<T, Matrix<T>, Vector<T>> → AnomalyDetectorBase<T> → KernelPCADetector<T>

Implements: IGeneratedParameterRegistrar<T>

For Beginners

Kernel PCA extends PCA to capture non-linear patterns by mapping data to a higher-dimensional feature space using a kernel function. Anomalies have high reconstruction error when projected back from this space.

How It Works

The algorithm works by:

  1. Compute kernel matrix (e.g., RBF kernel)
  2. Center the kernel matrix
  3. Extract principal components in kernel space
  4. Compute reconstruction error for each point

When to use:

  • Non-linear relationships in data
  • When linear PCA doesn’t capture patterns well
  • Complex, curved cluster structures

Industry Standard Defaults:

  • Kernel: RBF (Gaussian)
  • Gamma: 1/n_features (auto)
  • Number of components: 0.95 (95% variance)
  • Contamination: 0.1 (10%)

Reference: Schölkopf, B., Smola, A., Müller, K.R. (1998). “Nonlinear Component Analysis as a Kernel Eigenvalue Problem.” Neural Computation.

Constructors

Constructor Summary
KernelPCADetector(double gamma, double varianceRatio, KernelType<T> kernel, double contamination, int randomSeed) Creates a new Kernel PCA anomaly detector.

Properties

Property Summary
KernelType<T> Kernel { get; } Gets the kernel type.
double Gamma { get; } Gets the gamma parameter for RBF kernel.

Methods

Method Summary
Vector<T> ScoreAnomalies(Matrix<T> X)
void Fit(Matrix<T> X)