NearMiss<T>

Models & Types · AiDotNet.Preprocessing.ImbalancedLearning

Implements NearMiss undersampling for handling imbalanced datasets.

Inheritance: UndersamplingBase<T> → NearMiss<T>

For Beginners

Instead of randomly removing majority samples, NearMiss intelligently selects which ones to keep based on how close they are to minority samples.

Three versions:

NearMiss-1: Keep majority samples closest to nearest minority samples

  • For each majority sample, find the average distance to its k closest minority samples
  • Keep majority samples with smallest such distances
  • Focuses on boundary samples

NearMiss-2: Keep majority samples closest to farthest minority samples

  • For each majority sample, find the average distance to its k farthest minority samples
  • Keep majority samples with smallest such distances
  • Keeps samples that are “in between” the minority class

NearMiss-3: Keep majority samples closest to each minority sample

  • For each minority sample, find k nearest majority neighbors (the short list)
  • Of the short list, keep the samples with the largest average distance to their k closest minority samples
  • Ensures every minority sample has nearby majority examples

Visual intuition:

m m m . . . M M M M M M M M M
^ ^
Boundary Far from boundary

NearMiss-1: Keeps M's near the m's (boundary)
NearMiss-2: Keeps M's that are somewhat near m's but not too far
NearMiss-3: Keeps specific M's nearest to each m

References:

  • Mani & Zhang (2003). “kNN Approach to Unbalanced Data Distributions”

How It Works

NearMiss selects majority class samples based on their distance to minority class samples. It comes in three versions with different selection strategies.

Constructors

Constructor Summary
NearMiss(double samplingStrategy, NearMissVersion version, int kNeighbors, int? seed) Initializes a new instance of the NearMiss class.

Properties

Property Summary
string Name { get; } Gets the name of this undersampling strategy.