OutlierRemovalOperation<T>

Models & Types · AiDotNet.Preprocessing.DataPreparation

A row operation that removes or handles outliers using any anomaly detector.

Implements: IRowOperation<T>

For Beginners

Outliers are unusual data points that don’t follow the pattern of most of your data. They can confuse machine learning models and lead to poor predictions. This operation identifies outliers using statistical methods and either:

  • Removes them entirely (reduces your dataset size)
  • Replaces their values with typical values (median or mean)

How It Works

This operation wraps any IAnomalyDetector to identify outliers and either remove them or replace their values. When using Remove mode, both features (X) and labels (y) are modified together to maintain alignment.

When to Use Each Mode:

  • Remove: When you have plenty of data and outliers are likely errors
  • ReplaceWithMedian: When outliers are extreme but you need to preserve sample count
  • ReplaceWithMean: Similar to median, but more affected by other outliers

Constructors

Constructor Summary
OutlierRemovalOperation(IAnomalyDetector<T> detector, OutlierHandlingMode mode) Creates a new outlier removal operation.

Properties

Property Summary
IAnomalyDetector<T> Detector { get; } Gets the underlying anomaly detector.
OutlierHandlingMode Mode { get; } Gets the outlier handling mode.
bool IsFitted { get; }
string Description { get; }

Methods

Method Summary
ValueTuple<Matrix<T>, Vector<T>> FitResample(Matrix<T> X, Vector<T> y)
ValueTuple<Tensor<T>, Tensor<T>> FitResampleTensor(Tensor<T> X, Tensor<T> y)
bool[] GetOutlierMask(Matrix<T> X) Gets a mask indicating which rows were identified as outliers.