Skip to main content

Geometry-preserving seed selection with Bhattacharyya Coefficient, circular oversampling (GVM-CO, LRE-CO, LS-CO), and degradation-recovery benchmark

Project description

circover

Geometry-preserving seed selection, circular oversampling, and controlled degradation benchmark for imbalanced classification.

From the thesis: "From Distributional Similarity to Causal Imbalance: Circular Oversampling, Seed Selection, and a Controlled Degradation Study" — Parsa Hajiannejad, Università degli Studi di Milano, 2025.

Install

pip install circover

Modules

Class Description
BhattacharyyaCoefficient / BC Bhattacharyya Coefficient for marginal distributional similarity
GeometricSeedSelector Geometry-preserving seed selection (BC + AGTP + JSD + Z)
GVMCO Gravity-biased Von Mises Circular Oversampling
LRECO Local Region Estimation Circular Oversampling (Voronoi-constrained)
LSCO Layered Segmental Circular Oversampling
DegradationBench Controlled degradation-and-recovery benchmark

Quick start

import circover as cc

# Bhattacharyya Coefficient: measure distributional similarity
bc = cc.BhattacharyyaCoefficient(n_bins=30)
bc.score(X_original, X_synthetic)              # scalar in [0, 1]
bc.score_per_feature(X_original, X_synthetic)  # per-feature array

# Geometry-preserving seed selection
selector = cc.GeometricSeedSelector(n_seeds=20, random_state=42)
seed_indices, score = selector.select(X_minority)

# Circular oversamplers — drop-in replacements for SMOTE
from imblearn.pipeline import Pipeline
from sklearn.ensemble import RandomForestClassifier

pipe = Pipeline([
    ("over", cc.GVMCO(random_state=42)),   # or LRECO, LSCO
    ("clf",  RandomForestClassifier()),
])
pipe.fit(X_train, y_train)

Degradation-and-Recovery Benchmark

Run any oversampler (or pipeline) through a controlled degradation protocol to measure its recovery power:

bench = cc.DegradationBench(steps=10, metric="f1", cv=5, random_state=42)
results = bench.run(pipe, X, y)          # DataFrame: degradation, score, n_minority
bench.plot(results)                      # recovery curve with ARI annotation
ari = cc.DegradationBench.area_recovery_index(results)   # scalar summary

The DegradationBench:

  1. Removes minority samples in steps equal increments (0% -> 100%)
  2. Evaluates the estimator via cross-validation at each level
  3. Computes the Area Recovery Index (ARI) = integral of score(delta) — higher = better recovery

Compare multiple methods by their ARI:

results_smote = bench.run(smote_pipe, X, y)
results_gvm   = bench.run(gvm_pipe,   X, y)

ari_smote = cc.DegradationBench.area_recovery_index(results_smote)
ari_gvm   = cc.DegradationBench.area_recovery_index(results_gvm)
print(f"SMOTE ARI: {ari_smote:.3f}   GVM-CO ARI: {ari_gvm:.3f}")

Key parameters

cc.GVMCO(
    n_clusters=5,       # K-Means clusters on minority class
    k_neighbors=5,      # k-NN graph for circle formation
    kappa_max=4.0,      # max Von Mises concentration
    use_pca=True,       # False = native-dimension mode
    random_state=42,
)

cc.BhattacharyyaCoefficient(n_bins=30)  # histogram bins B (default 30)

cc.DegradationBench(
    steps=10,           # number of degradation levels
    metric="f1",        # sklearn scoring string
    cv=5,               # cross-validation folds
    random_state=42,
)

All oversamplers are compatible with imbalanced-learn pipelines and sklearn cross-validation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

circover-0.3.0.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

circover-0.3.0-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file circover-0.3.0.tar.gz.

File metadata

  • Download URL: circover-0.3.0.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for circover-0.3.0.tar.gz
Algorithm Hash digest
SHA256 7aab5d877f3a9d139e0c87b9790809a43608439ce8db408538d9236f7d55a904
MD5 b5327876ac13a3166d858b6ae36762a2
BLAKE2b-256 d55c9af236858ce1ff61afe5f80be7d832da90833257f8dd886e5bdcf84c0b7b

See more details on using hashes here.

File details

Details for the file circover-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: circover-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for circover-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 05ad60343f80ea89aeeb0d0fe7f696e13a1fe0eadf5f0be217e4213fe94d3f13
MD5 8941e8bdab2f167d1d3b25c44ef78868
BLAKE2b-256 cc21f5ceb15362031f3e690dd8a3dd649d8fc628a72bdc43be3645c24514dbeb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page