NearMiss is a data-level method for handling class imbalance that reduces the size of the majority class by selecting a subset of its instances. Unlike random under-sampling, which discards data arbitrarily, NearMiss uses a distance metric to keep majority examples that are most informative for classification. The algorithm calculates the average distance between each majority instance and its k nearest minority class neighbors, then selects the majority instances with the smallest distances, effectively focusing the model on the ambiguous region where classes overlap.
Glossary
NearMiss

What is NearMiss?
NearMiss is a family of heuristic under-sampling algorithms that selects majority class instances based on their average distance to the nearest minority class examples, retaining only those closest to the decision boundary.
The NearMiss family includes three distinct heuristics. NearMiss-1 selects majority instances with the smallest average distance to the three closest minority examples. NearMiss-2 selects majority instances with the smallest average distance to the three farthest minority examples, providing broader coverage. NearMiss-3 is a two-step process that selects a fixed number of the closest majority instances for each minority example. This technique is often paired with SMOTE or Edited Nearest Neighbors in hybrid resampling pipelines to clarify the decision boundary.
NearMiss Variants
The NearMiss family comprises three distinct heuristic algorithms that select majority class instances based on their average distance to minority class examples, each designed to preserve different characteristics of the original data distribution.
NearMiss-1
Selects majority class samples whose average distance to the three closest minority class instances is the smallest.
- Mechanism: For each majority sample, compute the mean distance to its
knearest minority neighbors. Keep themmajority samples with the lowest mean distances. - Effect: Retains majority examples that are closest to the minority class, effectively focusing the classifier on the most ambiguous region near the decision boundary.
- Risk: Can amplify noise if the minority class contains outliers, as the algorithm will aggressively select majority points near those outliers.
- Use Case: When the minority class is compact and well-defined, and you want the model to learn a tight boundary.
NearMiss-2
Selects majority class samples whose average distance to the three farthest minority class instances is the smallest.
- Mechanism: For each majority sample, compute the mean distance to its
kfarthest minority neighbors. Keep themmajority samples with the lowest mean distances. - Effect: Retains majority examples that are closest to the periphery of the minority class distribution, providing a broader, more diverse selection of majority points around the minority class.
- Advantage: Less sensitive to minority class outliers compared to NearMiss-1, as it considers the farthest minority neighbors rather than the nearest.
- Use Case: When the minority class has scattered sub-clusters and you need wider coverage around each minority instance.
NearMiss-3
A two-stage algorithm that, for each minority class instance, selects a fixed number of the closest majority class neighbors.
- Mechanism: For each minority sample, keep its
mnearest majority neighbors. This directly balances the dataset by ensuring each minority example is surrounded by a controlled number of majority examples. - Effect: Guarantees that every minority instance is retained and paired with a local neighborhood of majority points, preserving the local density structure around each rare event.
- Contrast: Unlike NearMiss-1 and NearMiss-2, which select a global count of majority samples, NearMiss-3 makes a per-minority-instance selection, inherently linking the sampling to the minority class distribution.
- Use Case: When preserving the local topology around every fraud example is critical for the downstream classifier.
Distance Metric Selection
The choice of distance metric fundamentally alters which majority instances are selected by any NearMiss variant.
- Euclidean Distance: Default metric. Sensitive to feature scaling; requires normalization. Works well for continuous, normally distributed features.
- Manhattan Distance: Less sensitive to outliers in high-dimensional spaces. Preferable when features are sparse or have heavy-tailed distributions.
- Mahalanobis Distance: Accounts for feature covariance, making it scale-invariant. Critical when transaction features are highly correlated.
- Cosine Similarity: Focuses on angular separation rather than magnitude. Useful when the direction of a transaction vector matters more than its absolute value.
- Best Practice: Always standardize features before applying any NearMiss variant, and experiment with multiple distance metrics on a held-out validation set.
Heuristic Limitations
NearMiss algorithms rely on distance-based heuristics that make implicit assumptions about the data geometry, which can fail in practice.
- Curse of Dimensionality: In high-dimensional feature spaces common in fraud detection, pairwise distances become less meaningful. NearMiss may select uninformative majority samples.
- Noisy Minority Instances: NearMiss-1 is particularly vulnerable to selecting majority points near mislabeled or anomalous minority examples, degrading the decision boundary.
- No Statistical Guarantee: Unlike cost-sensitive learning or ensemble methods, NearMiss provides no theoretical guarantee on preserving the true underlying distribution.
- Mitigation: Combine NearMiss with Tomek Links or Edited Nearest Neighbors as a post-cleaning step to remove ambiguous majority instances retained near the boundary.
Integration with Ensemble Methods
NearMiss can be embedded within bagging and boosting frameworks to recover information lost during under-sampling.
- Bagging + NearMiss: Train multiple base classifiers, each on a different NearMiss-1 under-sampled subset of the majority class. Aggregate predictions via majority voting to reduce variance.
- Boosting + NearMiss: At each boosting iteration, apply NearMiss-2 to the majority class before training the next weak learner. This forces subsequent learners to focus on increasingly difficult boundary regions.
- Hybrid Pipeline: Apply NearMiss-3 for initial balancing, then use SMOTE to over-sample the minority class, followed by a gradient-boosted tree model with
scale_pos_weighttuning. - Library Support: The
imbalanced-learnlibrary providesNearMissas a scikit-learn compatible sampler, enabling seamless integration intoPipelineobjects withRandomUnderSampleror ensemble wrappers likeBalancedBaggingClassifier.
NearMiss vs. Other Under-Sampling Methods
A comparison of NearMiss variants against other common under-sampling techniques for handling imbalanced datasets in fraud detection.
| Feature | NearMiss-1 | NearMiss-2 | NearMiss-3 | Random Under-Sampling | Tomek Links | Edited Nearest Neighbors |
|---|---|---|---|---|---|---|
Selection Strategy | Selects majority samples with smallest average distance to 3 nearest minority samples | Selects majority samples with smallest average distance to 3 farthest minority samples | Selects majority samples closest to decision boundary using 2-step nearest neighbor rule | Randomly removes majority class samples | Removes majority sample in minimally distanced opposite-class pairs | Removes majority samples misclassified by k-nearest neighbors |
Preserves Decision Boundary | ||||||
Computational Complexity | O(n_maj * n_min * k) | O(n_maj * n_min * k) | O(n_maj * n_min * k) | O(n_maj) | O(n^2) | O(n * k) |
Risk of Information Loss | Moderate | High | Low | High | Low | Moderate |
Handles Class Overlap | ||||||
Sensitive to Noise | ||||||
Suitable for High-Dimensional Data | ||||||
Typical Minority Class Retention | 100% | 100% | 100% | 100% | 100% | 100% |
Frequently Asked Questions
Clear, technical answers to the most common questions about the NearMiss family of under-sampling algorithms for handling severe class imbalance in financial fraud detection.
NearMiss is a family of prototype selection under-sampling algorithms that reduces the majority class by selecting examples based on their average distance to the nearest minority class instances. Unlike random under-sampling, which discards data indiscriminately, NearMiss applies a heuristic to retain majority class examples that are closest to the decision boundary. The algorithm operates in three distinct variants: NearMiss-1 selects majority samples with the smallest average distance to the three closest minority samples; NearMiss-2 selects majority samples with the smallest average distance to the three farthest minority samples; and NearMiss-3 selects a fixed number of the closest majority samples for each minority sample. This distance-based selection ensures that the retained majority class examples are the most informative for defining the class boundary, making the algorithm particularly effective for imbalanced classification problems where fraudulent transactions are rare.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Explore the core algorithms and complementary techniques that form the foundation of under-sampling strategies for handling severe class imbalance in fraud detection.

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.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us