TomekLinks<T>
Models & Types · AiDotNet.Preprocessing.ImbalancedLearning
Implements Tomek Links undersampling for handling imbalanced datasets.
Implements: IResamplingStrategy<T>
For Beginners
A Tomek link is a special relationship between two samples:
- Sample A (minority class) and Sample B (majority class)
- A’s nearest neighbor is B
- B’s nearest neighbor is A
- They are each other’s closest sample across classes!
Why Tomek links are important:
- They represent borderline or noisy samples
- Removing the majority sample from a Tomek link cleans the decision boundary
- It helps the classifier focus on clearer cases
Visual example:
Before: M . . . . m M . . . m . . . . M
^ ^
These two might be a Tomek link
After: . . . . . m . . . . m . . . . M
Majority sample removed, cleaner boundary
M = majority, m = minority
When to use:
- Data cleaning before training
- In combination with oversampling (SMOTE + Tomek)
- When you want minimal but targeted undersampling
References:
- Tomek (1976). “Two Modifications of CNN”
How It Works
Tomek Links removes majority class samples that form “Tomek links” with minority samples. A Tomek link is a pair of samples from different classes that are each other’s nearest neighbor.
Constructors
| Constructor | Summary |
|---|---|
TomekLinks() |
Initializes a new instance of the TomekLinks class. |
Properties
| Property | Summary |
|---|---|
string Name { get; } |
Gets the name of this undersampling strategy. |
Methods
| Method | Summary |
|---|---|
ResamplingStatistics<T> GetStatistics() |
Gets statistics about the last resampling operation. |
ValueTuple<Matrix<T>, Vector<T>> Resample(Matrix<T> x, Vector<T> y) |
Resamples the dataset by removing Tomek links. |