Skip to main content

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

# Generate 'Double circle' dataset with imbalance
X_circles, y_circles = make_circles(n_samples=(500, 100), noise=0.05, random_state=42)

X_oversampled, y_oversampled = SONA(X_circles, y_circles, min_label= 1, new_label=1)

## Visualization part
# Original Majority (label 0)
mask_maj = (y_oversampled == 0)
# Original Minority (label 1)
mask_min_orig = (y_oversampled == 1)
# Synthetic Minority (label 1 + new_label 1 = 2)
mask_min_syn = (y_oversampled == 2)

# 3. Create the plot
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("SONA Oversampling: Double Circle 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') # Keeps the circles looking like circles

plt.show()

Output Double circle

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

sona_oversampling-0.1.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

sona_oversampling-0.1.1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file sona_oversampling-0.1.1.tar.gz.

File metadata

  • Download URL: sona_oversampling-0.1.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sona_oversampling-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d5f8ff03a7a466caa663f121840983bc76f14913d1000431d34b4ef0bdcc60a9
MD5 09d2dfd3b5e774011b7ce81a702f0dd1
BLAKE2b-256 f11f11a8aefde8b3fe6f02c4753e2beb5e7fd38f0f2e2083880e4260799ee57b

See more details on using hashes here.

Provenance

The following attestation bundles were made for sona_oversampling-0.1.1.tar.gz:

Publisher: publish.yml on oakkao/sona-oversampling

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sona_oversampling-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for sona_oversampling-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 52f111b560d61a12c07f1229d6b87f95214fd03d03b1fb5db5849f4865c65f0a
MD5 f8dbb612cb8ddf1616cf1a9b9fa74305
BLAKE2b-256 72ca66d5e7002817d67c4dc09d82f280c8a7d1bab43ed221b7ac67ad4d4933ba

See more details on using hashes here.

Provenance

The following attestation bundles were made for sona_oversampling-0.1.1-py3-none-any.whl:

Publisher: publish.yml on oakkao/sona-oversampling

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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