MADDetector<T>
Models & Types · AiDotNet.AnomalyDetection.Statistical
Detects anomalies using Median Absolute Deviation (MAD).
Inheritance: ModelBase<T, Matrix<T>, Vector<T>> → AnomalyDetectorBase<T> → MADDetector<T>
Implements: IGeneratedParameterRegistrar<T>
For Beginners
MAD is a robust measure of spread that uses the median instead of the mean. Unlike standard deviation, MAD is resistant to outliers. Points far from the median (in terms of MAD units) are flagged as anomalies.
How It Works
The algorithm works by:
- Compute the median of each feature
- Compute MAD = median(|x - median|) for each feature
- Score points based on their deviation from median in MAD units
- High scores indicate anomalies
When to use:
- Data with heavy-tailed distributions
- When outliers may skew standard statistics
- As a robust alternative to Z-score
Industry Standard Defaults:
- Threshold: 3.5 MAD units
- Scale factor: 1.4826 (for Gaussian consistency)
- Contamination: 0.1 (10%)
Reference: Leys, C., et al. (2013). “Detecting outliers: Do not use standard deviation around the mean, use absolute deviation around the median.” Journal of Experimental Social Psychology.
Constructors
| Constructor | Summary |
|---|---|
MADDetector(double madThreshold, double scaleFactor, double contamination, int randomSeed) |
Creates a new MAD anomaly detector. |
Properties
| Property | Summary |
|---|---|
double MADThreshold { get; } |
Gets the MAD threshold for anomaly detection. |
Methods
| Method | Summary |
|---|---|
Vector<T> ScoreAnomalies(Matrix<T> X) |
|
void Fit(Matrix<T> X) |