Inferensys

Glossary

Edited Nearest Neighbors

Edited Nearest Neighbors (ENN) is an under-sampling algorithm that removes any majority class instance whose class label differs from the majority class of its k-nearest neighbors, eliminating noisy or ambiguous data points.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
DATA CLEANING UNDERSAMPLING

What is Edited Nearest Neighbors?

Edited Nearest Neighbors (ENN) is a data-level undersampling algorithm that cleans a dataset by removing majority class examples whose class label differs from the majority class of its k-nearest neighbors, effectively eliminating noisy or ambiguous instances near the decision boundary.

Edited Nearest Neighbors (ENN) is an undersampling technique that removes any majority class example whose predicted class, based on its k-nearest neighbors, differs from its actual class. The algorithm iterates through the dataset, classifies each instance using a k-NN rule (typically k=3), and discards misclassified majority samples. This process eliminates noisy instances and class overlap, clarifying the decision boundary without artificially generating new data points.

ENN is often used as a data cleaning step rather than a standalone balancing method, as it removes fewer examples than aggressive undersampling techniques. It is frequently combined with oversampling methods like SMOTE in hybrid approaches such as SMOTEENN, where ENN cleans the augmented dataset of overlapping or ambiguous synthetic samples. The result is a cleaner, more separable feature space that improves classifier generalization on imbalanced problems like financial fraud anomaly detection.

DATA CLEANING

Key Characteristics of ENN

Edited Nearest Neighbors (ENN) is a noise-removal under-sampling algorithm that refines the majority class by discarding instances that disagree with their local neighborhood, clarifying the decision boundary for downstream classifiers.

01

The Core Algorithm: k-NN Voting

ENN operates by iterating through every instance in the dataset. For each data point, it finds its k nearest neighbors (typically k=3). If the instance's actual class label does not match the majority vote of its neighbors, it is considered noisy or ambiguous and is removed. This process exclusively targets majority class examples for deletion, leaving minority class instances untouched to preserve rare event information.

02

Noise Elimination vs. Boundary Clarification

The primary goal of ENN is to smooth the decision boundary. By removing majority class points that intrude deeply into minority class space, ENN eliminates overlapping regions. This is distinct from simple random under-sampling:

  • Noise Removal: Deletes mislabeled or ambiguous majority instances.
  • Boundary Cleaning: Removes majority points surrounded by minority neighbors, making the class separation more distinct for algorithms like k-NN or SVM.
03

Integration in Hybrid Pipelines

ENN is rarely used in isolation. It is a critical component of combined resampling strategies designed to address severe class imbalance:

  • SMOTEENN: Applies SMOTE to oversample the minority class, then immediately uses ENN to clean the resulting dataset of any noisy synthetic or original majority points.
  • Neighborhood Cleaning Rule (NCR): Uses ENN as a first pass to clean the majority class, followed by a second pass that removes minority class examples misclassified by its three nearest neighbors.
04

Computational Considerations

The ENN algorithm requires calculating the k-nearest neighbors for every single instance in the dataset. This results in a computational complexity of O(n²) for a brute-force search, making it slow on large-scale financial transaction datasets. In practice, optimized spatial indexing structures like k-d trees or ball trees are used to accelerate the neighbor search, but the method remains more computationally intensive than simple random under-sampling.

05

Impact on Model Sensitivity

By removing ambiguous majority class examples, ENN typically increases the true positive rate (recall) for the minority class. The classifier is no longer confused by overlapping instances, allowing it to draw a more aggressive boundary. However, aggressive cleaning can also increase the false positive rate if the boundary becomes too tightly wrapped around the minority class. The choice of k is critical: a smaller k removes more instances, while a larger k is more conservative.

06

ENN vs. Tomek Links

Both are data cleaning methods, but they operate on different principles:

  • ENN: Removes a majority instance if its class differs from the plurality of its k neighbors. It can remove multiple majority points in a dense overlapping region.
  • Tomek Links: Identifies pairs of minimally distanced opposite-class instances and removes only the majority class instance in the pair. It is a more conservative, pair-wise cleaning strategy that focuses strictly on the borderline.
UNDERSTANDING EDITED NEAREST NEIGHBORS

Frequently Asked Questions

Clear, technical answers to the most common questions about the Edited Nearest Neighbors (ENN) algorithm, its mechanics, and its role in cleaning imbalanced datasets for robust fraud detection models.

Edited Nearest Neighbors (ENN) is a data cleaning algorithm that removes noisy or ambiguous majority class examples from a dataset. It works by evaluating each instance against its k-nearest neighbors (typically k=3). If the instance's actual class label differs from the class predicted by the majority vote of its neighbors, that instance is considered noisy or borderline and is removed from the dataset. The algorithm iterates through every example in the training set, retaining only those whose class label is consistent with their local neighborhood. This process effectively 'edits' the dataset, eliminating overlapping instances that blur the decision boundary between classes. In the context of financial fraud detection, ENN is primarily used as an under-sampling technique to clean the majority (non-fraud) class, removing legitimate transactions that look suspiciously like fraud, thereby sharpening the separation between the two classes.

COMPARATIVE ANALYSIS

ENN vs. Other Under-Sampling Methods

A feature-level comparison of Edited Nearest Neighbors against other common under-sampling and data cleaning techniques for imbalanced classification.

FeatureEdited Nearest NeighborsTomek LinksNearMissRandom Undersampling

Selection Strategy

Removes majority instances misclassified by k-NN

Removes majority instances in minimally distanced opposite-class pairs

Selects majority instances closest to minority class

Randomly removes majority instances

Preserves Decision Boundary

Removes Noisy Instances

Removes Redundant Instances

Computational Complexity

O(n^2) per iteration

O(n^2)

O(n * m * k)

O(n)

Risk of Information Loss

Low

Low

Moderate

High

Requires Hyperparameter Tuning

Suitable for Highly Overlapping Classes

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.