PCADetector<T>
Models & Types · AiDotNet.AnomalyDetection.Linear
Detects anomalies using Principal Component Analysis (PCA) reconstruction error.
Inheritance: ModelBase<T, Matrix<T>, Vector<T>> → AnomalyDetectorBase<T> → PCADetector<T>
Implements: IGeneratedParameterRegistrar<T>
For Beginners
PCA-based anomaly detection works by projecting data onto the main directions of variation (principal components) and measuring how well points can be reconstructed. Anomalies have high reconstruction error.
How It Works
The algorithm works by:
- Fit PCA on training data to find principal components
- Project each point onto these components
- Reconstruct the point from the projection
- Measure reconstruction error (anomaly score)
When to use:
- Linear relationships in data
- When anomalies deviate from the main data structure
- High-dimensional data that can be compressed
Industry Standard Defaults:
- Components: min(n_samples, n_features) or specified
- Variance threshold: 0.95 (keep 95% of variance)
- Contamination: 0.1 (10%)
Constructors
| Constructor | Summary |
|---|---|
PCADetector(int? nComponents, double varianceThreshold, double contamination, int randomSeed) |
Creates a new PCA anomaly detector. |
Properties
| Property | Summary |
|---|---|
double VarianceThreshold { get; } |
Gets the variance threshold. |
int NComponents { get; } |
Gets the number of components used. |
Methods
| Method | Summary |
|---|---|
Vector<T> ScoreAnomalies(Matrix<T> X) |
|
void Fit(Matrix<T> X) |