FairSample
Fair sampling for imbalanced datasets with 14+ resampling techniques and 40+ complexity measures.
Why FairSample?
Most imbalanced learning packages only provide resampling techniques. FairSample adds complexity measures to help you understand why your dataset is difficult and which technique works best.
Installation
pip install fairsample
Quick Start
from fairsample import RFCL
from fairsample.complexity import ComplexityMeasures
import pandas as pd
# Load data
df = pd.read_csv('data.csv')
X = df.drop('target', axis=1)
y = df['target']
# Check complexity
cm = ComplexityMeasures(X, y)
complexity = cm.analyze_overlap()
print(f"Overlap (N3): {complexity['N3']:.4f}")
# Apply resampling
sampler = RFCL(random_state=42)
X_resampled, y_resampled = sampler.fit_resample(X, y)
# Use resampled data
from sklearn.ensemble import RandomForestClassifier
clf = RandomForestClassifier()
clf.fit(X_resampled, y_resampled)
Features
14+ Resampling Techniques:
- RFCL, NUS, URNS - Overlap-based undersampling
- SVDDWSMOTE, ODBOT, EHSO - Hybrid methods
- NBUS, KMeansUndersampling - Clustering-based (multiple variants)
- OSM - Comprehensive overlap handling
- RandomOverSampler, RandomUnderSampler - Baselines
40+ Complexity Measures:
- Feature Overlap: F1, F1v, F2, F3, F4, Input Noise
- Instance Overlap: N3, N4, kDN, CM, R-value, D3, SI, Borderline, Degree of Overlap
- Structural: N1, N2, T1, DBC, LSC, Clust, NSG, ICSV, ONB
- Multiresolution: Purity, Neighbourhood Separability, MRCA, C1, C2
Usage
Compare Multiple Techniques
from fairsample.utils import compare_techniques
results = compare_techniques(
X, y,
techniques=['RFCL', 'NUS', 'URNS'],
complexity_measures='basic'
)
print(results.sort_values('N3')) # Lower N3 = less overlap
Get All Complexity Measures
# All measures
all_measures = cm.get_all_complexity_measures(measures='all')
# By category
feature_measures = cm.get_all_complexity_measures(measures='feature')
# Specific measures
selected = cm.get_all_complexity_measures(measures=['N3', 'F1', 'N1'])
Compare Before/After
from fairsample.complexity import compare_pre_post_overlap
X_resampled, y_resampled = sampler.fit_resample(X, y)
comparison = compare_pre_post_overlap(X, y, X_resampled, y_resampled)
print(comparison['improvements'])
API
All techniques follow scikit-learn's API:
sampler = RFCL(random_state=42)
X_resampled, y_resampled = sampler.fit_resample(X, y)
Requirements
Python 3.8+ with numpy, scikit-learn, scipy, pandas, matplotlib, seaborn
Contributing
Contributions welcome! Submit a PR or open an issue.
License
MIT License
Citation
@software{fairsample,
author = {Mohd Uwaish},
title = {FairSample: Techniques for handling class overlapping problems},
year = {2026},
url = {https://github.com/mohdUwaish59/fairsample}
}
Metadata
Release files for fairsample 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fairsample-1.0.0.tar.gz | 43.3 kB | Without provenance | Details for fairsample-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fairsample-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for fairsample-1.0.0-py3-none-any.whl |
Total release size: 80.9 kB
Release files / fairsample-1.0.0.tar.gz
| Download URL | fairsample-1.0.0.tar.gz |
|---|---|
| Size | 43.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fa6864d322657530860c3291aa426b442e69745a95af488b1e1b1b3af4a28dfe
|
|
BLAKE2b-256 checksum How to use checksums |
b6a076dd16c7a8ac1fd2d93cb0402226df3f793cb90085ab41247bc1a328811d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / fairsample-1.0.0-py3-none-any.whl
| Download URL | fairsample-1.0.0-py3-none-any.whl |
|---|---|
| Size | 37.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2eb289b19b504c429548e83e521d9f619eb900ef73b7c36ee4e16282c1e8f291
|
|
BLAKE2b-256 checksum How to use checksums |
6ebfee5f11d9c2948411a890b0081b1086553ac05d442dd06c70ff87d85743fe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for fairsample 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.