Skip to main content

Biblioteca para balanceamento de dados tabulares com Deep SMOTE Optimize.

Project description

DSTO-GAN: Balancing Data with GAN

DSTO-GAN is a Python library that uses a Generative Adversarial Network (GAN) to generate synthetic samples and balance imbalanced datasets. It is beneficial for classification problems where classes are disproportionate.


Features

  1. Generating synthetic samples for class balancing.
  2. Training a custom GAN for tabular data.
  3. Saving the balanced dataset to a .csv file.

Prerequisites

  • Python 3.7 or higher.
  • pip package manager.

Installation

You can install the library directly via pip:

pip install dsto-gan

Dependencies

The dependencies will be installed automatically during the installation. If you prefer to install manually, run:

pip install numpy torch pandas scikit-learn xgboost scikit-optimize

How to Use

1. Import and Initialization

First, import the DSTO_GAN class and initialize the object:

from dsto_gan import DSTO_GAN

Initialize DSTO-GAN

dsto_gan = DSTO_GAN(dim_h=64, n_z=10, lr=0.0002, epochs=100, batch_size=64)

2. Balancing Data

Use the fit_resample method to balance the data:

# Imbalanced data
X = ... # Features (numpy array or pandas DataFrame)
y = ... # Labels (numpy array or pandas Series)

# Balance the data
X_resampled, y_resampled = dsto_gan.fit_resample(X, y)

print(f"Shape of the balanced data: {X_resampled.shape}, {y_resampled.shape}")

3. Integration with Scikit-Learn

DSTO_GAN is compatible with Scikit-Learn pipelines. You can use it as part of a preprocessing pipeline:

from sklearn.pipeline import Pipeline
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split

# Split the data into training and testing
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Create a pipeline with DSTO-GAN and a classifier
pipeline = Pipeline([
('dsto_gan', DSTO_GAN()), # Balancing with DSTO-GAN
('classifier', RandomForestClassifier()) # Classifier
])

# Train the model
pipeline.fit(X_train, y_train)

# Evaluate the model
accuracy = pipeline.score(X_test, y_test)
print(f"Model accuracy: {accuracy:.2f}")

---

## Usage Example

Here is a complete usage example of DSTO-GAN:

```bash
import pandas as pd
from sklearn.model_selection import train_test_split
from dsto_gan import DSTO_GAN

# 1. Load imbalanced data
file_path = "path/to/imbalanced.csv"
df = pd.read_csv(file_path)

# 2. Separate features (X) and labels (y)
X = df.iloc[:, :-1].values ​​# All columns except the last one
y = df.iloc[:, -1].values ​​# Last column is the class

# 3. Split data into training and testing
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# 4. Balance training data with DSTO-GAN
dsto_gan = DSTO_GAN()
X_train_resampled, y_train_resampled = dsto_gan.fit_resample(X_train, y_train)

print(f"Shape of balanced data: {X_train_resampled.shape}, {y_train_resampled.shape}")

Project Structure

dsto_gan/
│
├── dsto_gan/ # Main package
│ ├── __init__.py # Package initialization
│ ├── dsto_gan.py # Core code for data balancing
├── setup.py # Package configuration
├── README.md # Project documentation
└── LICENSE # Project license

Contribution

Contributions are welcome! If you encounter problems or have suggestions for improvements, feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the [LICENSE] file for more details.


Contact


Acknowledgements

This project was developed as part of research on data balancing using GANs. The open-source community provided the libraries used.

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

dsto_gan-0.1.7.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

dsto_gan-0.1.7-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file dsto_gan-0.1.7.tar.gz.

File metadata

  • Download URL: dsto_gan-0.1.7.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for dsto_gan-0.1.7.tar.gz
Algorithm Hash digest
SHA256 a1dfbac2134402ac9ce31e2529b89cd696759337dbf4f22d17d73e1ca4142e04
MD5 ff5730c9366a06bba7e8818fec9fd75e
BLAKE2b-256 1a84539fac10ce3bbbcce523721a4a8ba4d51ab6c1b8e6205e4e96e4caa6de76

See more details on using hashes here.

File details

Details for the file dsto_gan-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: dsto_gan-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for dsto_gan-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 8eb2d35bfa4173563ba73d50ac9ee22cbe7dc84e47e61c165b9207d03285f2f6
MD5 130dd22617a5ef86767727e20fef8b0a
BLAKE2b-256 6df77359a228c0f925cb105a8e382d1b31568b61779d0a4676c54dd40a22d87a

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