This repository contains the official implementation of the paper "Approximate Borderline Sampling using Granular-Ball for Classification Tasks". GBABS is a novel boundary sampling algorithm that utilizes granular balls to identify and sample boundary points in classification tasks.
GBABS leverages the concept of granular balls to perform approximate boundary sampling in data. The algorithm consists of the following steps:
- Constructing granular balls: Dividing the data space into multiple granular balls, each containing data points of the same class
- Identifying boundary regions: Finding adjacent balls of different classes along feature dimensions
- Boundary point sampling: Extracting samples from boundary balls that are close to the decision boundary
This method effectively reduces the training data size while preserving the boundary information crucial for classification decisions.
The implementation consists of three main files:
- RD_GBG.py: Granular ball generation module, implementing the construction and management of granular balls
- GBABS.py: Implementation of the granular ball-based boundary sampling approach
- main.py: Experiment runner and evaluation script
This module implements the construction and management of granular balls:
GranularBallclass: Represents a single granular ball with attributes like data points, center, radius, and labelGranularBallManagerclass: Manages the generation, manipulation, and retrieval of granular balls- Helper functions: Distance calculation, outlier detection, ball generation, etc.
Implements the granular ball-based approximate boundary sampling method:
- GBABS class: Main implementation class containing the core logic for boundary point sampling
bound_sampling: Main sampling method that analyzes boundary relationships between granular balls of different classesextract_boundary_samples: Extracts boundary samples from balls based on specific feature dimensions
Experiment and evaluation script:
- Data loading and preprocessing
- Experiment setup (cross-validation, parameter settings)
- Comparison with other sampling methods (random sampling, SMOTE variants, other boundary sampling methods)
- Result statistics and output
numpy
pandas
scikit-learn
imbalanced-learn
xgboost
lightgbm
# Load your dataset
data = load_your_dataset()
# Create GBABS instance
gbabs = GBABS.GBABS(data, rho=5) # rho is the density parameter for granular ball construction
# Perform boundary sampling
boundary_samples = gbabs.bound_sampling()
# Train a classifier using the sampled data
X = boundary_samples[:, 1:] # Features
y = boundary_samples[:, 0] # Labels
classifier = train_your_classifier(X, y)You can run the experiments from the paper by executing main.py:
python main.pyParameters can be adjusted in main.py, including:
rho: Density parameter for granular ball constructionNoise_ratio: Noise ratio in the datarepetitions: Number of experiment repetitionsbaseline: Classifier type to use
The comparison between GBABS and other sampling methods is based on the following metrics:
- Sampling rate
- Accuracy
- Geometric mean (G-mean)
Experiments show that GBABS can achieve comparable or even better classification performance than using the full dataset while maintaining a lower sampling rate on most datasets.
If you use the GBABS algorithm or this code in your research, please cite the original paper:
tbc