Class IQRClipper<T>
- Namespace
- AiDotNet.Preprocessing.OutlierHandling
- Assembly
- AiDotNet.dll
Clips outliers using the Interquartile Range (IQR) method.
public class IQRClipper<T> : TransformerBase<T, Matrix<T>, Matrix<T>>, IDataTransformer<T, Matrix<T>, Matrix<T>>
Type Parameters
TThe numeric type for calculations (e.g., float, double).
- Inheritance
-
IQRClipper<T>
- Implements
- Inherited Members
Remarks
IQRClipper identifies outliers using the IQR method: - Lower bound = Q1 - k * IQR - Upper bound = Q3 + k * IQR where IQR = Q3 - Q1 and k is the multiplier (default 1.5).
This is the same method used in box plots for identifying outliers. A multiplier of 1.5 identifies "mild" outliers, while 3.0 identifies "extreme" outliers.
For Beginners: The IQR is the range where the middle 50% of data falls. Values outside 1.5× this range are considered outliers: - Q1 (25th percentile): 25% of data is below this value - Q3 (75th percentile): 75% of data is below this value - IQR = Q3 - Q1: The spread of the middle 50% - Outliers: Values below Q1 - 1.5×IQR or above Q3 + 1.5×IQR
Constructors
IQRClipper(double, int[]?)
Creates a new instance of IQRClipper<T>.
public IQRClipper(double multiplier = 1.5, int[]? columnIndices = null)
Parameters
multiplierdoubleThe IQR multiplier (default 1.5 for mild outliers, 3.0 for extreme).
columnIndicesint[]The column indices to clip, or null for all columns.
Properties
IQRValues
Gets the IQR values for each feature.
public double[]? IQRValues { get; }
Property Value
- double[]
LowerBounds
Gets the fitted lower bounds for each feature.
public double[]? LowerBounds { get; }
Property Value
- double[]
Multiplier
Gets the IQR multiplier for determining outlier boundaries.
public double Multiplier { get; }
Property Value
Q1Values
Gets the Q1 (25th percentile) values for each feature.
public double[]? Q1Values { get; }
Property Value
- double[]
Q3Values
Gets the Q3 (75th percentile) values for each feature.
public double[]? Q3Values { get; }
Property Value
- double[]
SupportsInverseTransform
Gets whether this transformer supports inverse transformation.
public override bool SupportsInverseTransform { get; }
Property Value
UpperBounds
Gets the fitted upper bounds for each feature.
public double[]? UpperBounds { get; }
Property Value
- double[]
Methods
CountOutliersPerFeature(Matrix<T>)
Counts the number of outliers per feature.
public int[] CountOutliersPerFeature(Matrix<T> data)
Parameters
dataMatrix<T>The data to analyze.
Returns
- int[]
Array of outlier counts per feature.
FitCore(Matrix<T>)
Fits the clipper by computing IQR bounds for each feature.
protected override void FitCore(Matrix<T> data)
Parameters
dataMatrix<T>The training data matrix.
GetFeatureNamesOut(string[]?)
Gets the output feature names after transformation.
public override string[] GetFeatureNamesOut(string[]? inputFeatureNames = null)
Parameters
inputFeatureNamesstring[]
Returns
- string[]
GetOutlierMask(Matrix<T>)
Gets a mask indicating which values are outliers in the input data.
public bool[,] GetOutlierMask(Matrix<T> data)
Parameters
dataMatrix<T>The data to check for outliers.
Returns
- bool[,]
A boolean matrix where true indicates an outlier.
InverseTransformCore(Matrix<T>)
Inverse transformation is not supported.
protected override Matrix<T> InverseTransformCore(Matrix<T> data)
Parameters
dataMatrix<T>
Returns
- Matrix<T>
TransformCore(Matrix<T>)
Transforms the data by clipping values outside IQR bounds.
protected override Matrix<T> TransformCore(Matrix<T> data)
Parameters
dataMatrix<T>The data to transform.
Returns
- Matrix<T>
The transformed data with outliers clipped.