MADClipper<T>
Models & Types · AiDotNet.Preprocessing.OutlierHandling
Clips outliers based on Median Absolute Deviation (MAD) bounds.
Inheritance: TransformerBase<T, Matrix<T>, Matrix<T>> → MADClipper<T>
For Beginners
Think of the median as the “middle value” when you sort your data. MAD measures how spread out your data is from this middle value. Unlike the average, the median isn’t pulled toward extreme values, so MAD gives a more reliable measure of spread when outliers are present.
How It Works
MADClipper identifies outliers using the Median Absolute Deviation, which is more robust to outliers than standard deviation-based methods. Values with modified Z-scores exceeding the threshold are clipped to the boundary values.
How It Works: For each feature:
- Calculate the median
- Calculate MAD = median(|x - median|)
- Calculate modified Z-score = 0.6745 * (x - median) / MAD
- Clip values where |modified Z-score| > threshold
Why MAD is Better Than Z-Score for Outliers: The traditional Z-score uses mean and standard deviation, which are themselves affected by outliers. MAD uses medians, which are resistant to extreme values. This makes MAD better at detecting outliers when your data already contains significant outliers.
Common Thresholds:
- 2.5: Aggressive (more values treated as outliers)
- 3.5: Standard (recommended default)
- 5.0: Conservative (only extreme outliers)
Constructors
| Constructor | Summary |
|---|---|
MADClipper(double threshold, int[] columnIndices) |
Creates a new instance of MADClipper. |
Properties
| Property | Summary |
|---|---|
Vector<T> LowerBounds { get; } |
Gets the computed lower bounds for each feature. |
Vector<T> MADs { get; } |
Gets the computed MAD values for each feature. |
Vector<T> Medians { get; } |
Gets the computed medians for each feature. |
Vector<T> UpperBounds { get; } |
Gets the computed upper bounds for each feature. |
bool SupportsInverseTransform { get; } |
Gets whether this transformer supports inverse transformation. |
double Threshold { get; } |
Gets the modified Z-score threshold for clipping. |
Methods
| Method | Summary |
|---|---|
Matrix<T> GetModifiedZScores(Matrix<T> data) |
Calculates the modified Z-scores for all values in the data. |
bool[] GetOutlierMask(Matrix<T> data) |
Gets a boolean mask indicating which values are outliers. |
string[] GetFeatureNamesOut(string[] inputFeatureNames) |
Gets the output feature names after transformation. |