Stochastic directional Oversampling using Negative Anomalous scores (SONA)
Project description
SONA
Stochastic directional Oversampling using Negative Anomalous scores for imbalanced dataset
Installation
To install SONA, type the following command in the terminal
pip install sona-oversampling # normal install
pip install --upgrade sona-oversampling # or update if needed
Required Dependencies :
- Python 3.9 or higher
- numpy>=2.0.2
- scipy>=1.8.1
SONA
The SONA function generates synthetic samples for the minority class by identifying border areas between classes and creating new points within a calculated safety radius.
SONA(X,y, min_label, new_label = 0)
| Parameter | Type | Description |
|---|---|---|
| X | numpy.ndarray | The input feature matrix of shape $(n_{samples}, n_{features})$. |
| y | numpy.ndarray | The target labels. |
| min_label | int | The specific label identified as the minority class. |
| new_label | int | An offset added to min_label for the new synthetic samples (default is 0). |
Returns
| Parameter | Type | Description |
|---|---|---|
| X_augmented | numpy.ndarray | containing the original features plus the new synthetic samples. |
| y_augmented | numpy.ndarray | containing the original labels plus labels for the synthetic samples. |
Usage Example
from sona_oversampling import SONA
from sklearn.datasets import make_circles, make_moons, make_blobs
# Generate 'Double circle' dataset with imbalance
X_circles, y_circles = make_circles(n_samples=(500, 100), noise=0.05, random_state=42)
# Generate 'Blue-moons' dataset with imbalance
X_moons, y_moons = make_moons(n_samples=(500, 100), noise=0.1, random_state=42)
# Generate imbalanced 'Gaussian cluster' dataset
X_blobs, y_blobs = make_blobs(n_samples=[500, 50], cluster_std=0.5, centers=[[0, 0], [1, 1]], random_state=42)
synthetic_datasets = [
("Double circle", (X_circles, y_circles)),
("Blue-moons", (X_moons, y_moons)),
("Gaussian cluster", (X_blobs, y_blobs))
]
for name, (X_original, y_original) in synthetic_datasets:
X_oversampled, y_oversampled = SONA(X_original, y_original, min_label= 1, new_label=1)
mask_maj = (y_oversampled == 0)
mask_min_orig = (y_oversampled == 1)
mask_min_syn = (y_oversampled == 2)
plt.figure(figsize=(10, 8))
# Plot Majority Class
plt.scatter(X_oversampled[mask_maj, 0], X_oversampled[mask_maj, 1],
c='grey', label='Majority Class (0)', alpha=0.5, s=20)
# Plot Original Minority Class
plt.scatter(X_oversampled[mask_min_orig, 0], X_oversampled[mask_min_orig, 1],
c='blue', label='Original Minority (1)', s=30, edgecolors='k')
# Plot Synthetic Minority Class
plt.scatter(X_oversampled[mask_min_syn, 0], X_oversampled[mask_min_syn, 1],
c='red', label='Synthetic Samples (2)', marker='x', s=40, alpha=0.8)
plt.title(f"SONA Oversampling: {name} Dataset", fontsize=14)
plt.xlabel("Feature 1")
plt.ylabel("Feature 2")
plt.legend(loc='best')
plt.grid(True, linestyle='--', alpha=0.6)
plt.axis('equal')
plt.show()
Output
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sona_oversampling-0.1.3.tar.gz.
File metadata
- Download URL: sona_oversampling-0.1.3.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
873ffbdb97d9b9403f5b935a99ec6ac79cc2b9c23a26a7c1b98c7951287433b8
|
|
| MD5 |
566d57d82212ef46f13a0a222d17494e
|
|
| BLAKE2b-256 |
b0ee499967fc4d7d0a7cb6f05f70fd4c43d4b9b257892922bb42aa25e134bc56
|
Provenance
The following attestation bundles were made for sona_oversampling-0.1.3.tar.gz:
Publisher:
publish.yml on oakkao/sona-oversampling
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sona_oversampling-0.1.3.tar.gz -
Subject digest:
873ffbdb97d9b9403f5b935a99ec6ac79cc2b9c23a26a7c1b98c7951287433b8 - Sigstore transparency entry: 1065722465
- Sigstore integration time:
-
Permalink:
oakkao/sona-oversampling@50bc0d43fa8e22d6a762f86dd0137d639b73946e -
Branch / Tag:
refs/tags/0.1.3 - Owner: https://github.com/oakkao
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@50bc0d43fa8e22d6a762f86dd0137d639b73946e -
Trigger Event:
release
-
Statement type:
File details
Details for the file sona_oversampling-0.1.3-py3-none-any.whl.
File metadata
- Download URL: sona_oversampling-0.1.3-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5adfd004fdf0841d28f9383633c16960722c746007270c159b3404c2b347233f
|
|
| MD5 |
aa68deb95d6b2bc430251816b9070cab
|
|
| BLAKE2b-256 |
cd5643bb286b0f463d064a5630faa5096314ec4cc02e09191a0c598f8a57c3bf
|
Provenance
The following attestation bundles were made for sona_oversampling-0.1.3-py3-none-any.whl:
Publisher:
publish.yml on oakkao/sona-oversampling
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sona_oversampling-0.1.3-py3-none-any.whl -
Subject digest:
5adfd004fdf0841d28f9383633c16960722c746007270c159b3404c2b347233f - Sigstore transparency entry: 1065722469
- Sigstore integration time:
-
Permalink:
oakkao/sona-oversampling@50bc0d43fa8e22d6a762f86dd0137d639b73946e -
Branch / Tag:
refs/tags/0.1.3 - Owner: https://github.com/oakkao
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@50bc0d43fa8e22d6a762f86dd0137d639b73946e -
Trigger Event:
release
-
Statement type: