ChiSquareDetector<T>

Models & Types · AiDotNet.AnomalyDetection.Statistical

Detects anomalies using the Chi-Square test for multivariate data.

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

Implements: IGeneratedParameterRegistrar<T>

For Beginners

The Chi-Square (Mahalanobis distance) detector identifies outliers by measuring how far a point is from the center of the data, accounting for correlations between features. Points far from the center in Mahalanobis distance are anomalies.

How It Works

The algorithm computes: D^2 = (x - mean)’ * Cov^(-1) * (x - mean) This squared Mahalanobis distance follows a Chi-Square distribution with p degrees of freedom (where p = number of features) under the assumption of multivariate normality.

When to use:

  • Multivariate data (multiple correlated features)
  • Data is approximately multivariate normal
  • You want to account for correlations between features

Industry Standard Defaults:

  • Alpha (significance level): 0.05 (5%)

Constructors

Constructor Summary
ChiSquareDetector(double alpha, double contamination, int randomSeed) Creates a new Chi-Square anomaly detector.

Properties

Property Summary
T ChiSquareCritical { get; } Gets the Chi-Square critical value based on the fitted degrees of freedom (number of features) and alpha.
double Alpha { get; } Gets the significance level (alpha) for the test.

Methods

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