Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Scikit learn contrib Imbalanced learn BorderlineSMOTE

From Leeroopedia


Knowledge Sources
Domains Machine_Learning, Data_Preprocessing, Imbalanced_Learning
Last Updated 2026-02-09 03:00 GMT

Overview

Concrete tool for borderline-focused synthetic oversampling provided by the imbalanced-learn library.

Description

The BorderlineSMOTE class implements the Borderline-SMOTE algorithm. It extends BaseSMOTE and adds a danger-detection phase that identifies minority samples near the class boundary using m_neighbors. Only these borderline instances are used for SMOTE interpolation. Supports both borderline-1 and borderline-2 variants via the kind parameter.

Usage

Import this class when you want oversampling focused on the decision boundary region. Choose kind='borderline-1' for conservative interpolation among minority neighbors only, or kind='borderline-2' to also interpolate toward majority neighbors.

Code Reference

Source Location

  • Repository: imbalanced-learn
  • File: imblearn/over_sampling/_smote/filter.py
  • Lines: L28-234

Signature

class BorderlineSMOTE(BaseSMOTE):
    def __init__(
        self,
        *,
        sampling_strategy="auto",
        random_state=None,
        k_neighbors=5,
        m_neighbors=10,
        kind="borderline-1",
    ):
        """
        Args:
            sampling_strategy: str, dict, or callable - Resampling ratio.
            random_state: int, RandomState, or None - Seed.
            k_neighbors: int or NearestNeighbors - Neighbors for SMOTE
                interpolation (default: 5).
            m_neighbors: int or NearestNeighbors - Neighbors for borderline
                detection (default: 10).
            kind: {'borderline-1', 'borderline-2'} - Variant selection.
        """

Import

from imblearn.over_sampling import BorderlineSMOTE

I/O Contract

Inputs

Name Type Required Description
X {array-like, sparse matrix} of shape (n_samples, n_features) Yes Feature matrix
y array-like of shape (n_samples,) Yes Target labels
k_neighbors int or NearestNeighbors No Neighbors for interpolation (default: 5)
m_neighbors int or NearestNeighbors No Neighbors for danger detection (default: 10)
kind str No 'borderline-1' or 'borderline-2' (default: 'borderline-1')

Outputs

Name Type Description
X_resampled ndarray of shape (n_samples_new, n_features) Feature matrix with borderline synthetic samples
y_resampled ndarray of shape (n_samples_new,) Target array with labels

Usage Examples

Basic Borderline SMOTE

from collections import Counter
from sklearn.datasets import make_classification
from imblearn.over_sampling import BorderlineSMOTE

X, y = make_classification(
    n_classes=2, weights=[0.1, 0.9], n_samples=1000, random_state=10
)
print(f"Original: {Counter(y)}")

bsmote = BorderlineSMOTE(random_state=42, kind="borderline-1")
X_res, y_res = bsmote.fit_resample(X, y)
print(f"Resampled: {Counter(y_res)}")

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment