NearMissUnderSampler<T>

Models & Types · AiDotNet.Augmentation.Tabular.Undersampling

Implements NearMiss undersampling for imbalanced datasets.

Implements: IUnderSampler<T>

For Beginners

NearMiss is a smarter undersampling method that selects majority class samples based on their distance to minority samples. Unlike random undersampling, it considers the spatial relationships between classes.

How It Works

NearMiss Variants:

  • NearMiss-1: Selects majority samples whose average distance to k nearest

minority samples is smallest. These are majority samples close to the minority class.

  • NearMiss-2: Selects majority samples whose average distance to k farthest

minority samples is smallest. These are majority samples close to all minority samples.

  • NearMiss-3: For each minority sample, keeps the k nearest majority samples.

This surrounds each minority sample with selected majority samples.

When to use:

  • NearMiss-1: When you want to keep majority samples near the decision boundary
  • NearMiss-2: When minority class has outliers you want to handle
  • NearMiss-3: When you want to preserve local structure around minority samples

Reference: Zhang & Mani, “kNN Approach to Unbalanced Data Distributions” (2003)

Constructors

Constructor Summary
NearMissUnderSampler(NearMissVersion<T> version, int nNeighbors, double samplingRatio) Creates a new NearMiss undersampler.

Properties

Property Summary
NearMissVersion<T> Version { get; } Gets the NearMiss version to use.
double SamplingRatio { get; } Gets the target ratio between minority and majority samples after undersampling.
int NNeighbors { get; } Gets the number of nearest neighbors to consider.

Methods

Method Summary
ValueTuple<Matrix<T>, Vector<T>> Undersample(Matrix<T> data, Vector<T> labels, T minorityLabel) Performs NearMiss undersampling on the majority class.