Skip to main content

Privacy-Preserving Synthetic Tabular Data Generation

Project description

๐Ÿ”จ TabularForge

TabularForge Logo

Privacy-Preserving Synthetic Tabular Data Generation

PyPI version Python versions License Tests Coverage


๐ŸŽฏ What is TabularForge?

TabularForge is a unified, production-ready Python library for generating high-quality synthetic tabular data with built-in privacy guarantees. It combines multiple state-of-the-art approaches (GANs, VAEs, Copulas) into a simple, one-line API.

Why Synthetic Data?

Organizations have valuable tabular data (patient records, financial transactions, customer data) but often can't share it due to:

  • Privacy regulations (GDPR, HIPAA, CCPA)
  • Competitive sensitivity
  • Data scarcity for ML development

Synthetic data solves this by generating realistic, statistically similar data that protects individual privacy while preserving analytical utility.


โœจ Key Features

Feature Description
๐Ÿค– Multiple Generators CTGAN, TVAE, Gaussian Copula, and more
๐Ÿ”’ Differential Privacy Formal privacy guarantees with configurable epsilon
๐Ÿ“Š Quality Metrics Statistical similarity, ML utility, privacy leakage tests
๐Ÿ”ง Auto Preprocessing Handles mixed types, missing values, imbalanced data
โšก One-Line API Generate synthetic data in a single line of code
๐Ÿ“ˆ Benchmarking Compare generators on your specific data

๐Ÿš€ Quick Start

Installation

# Install from PyPI
pip install tabularforge

# Or install from source
git clone https://github.com/ganeshreddy28/tabularforge.git
cd tabularforge
pip install -e .

Basic Usage

from tabularforge import TabularForge
import pandas as pd

# Load your real data
real_data = pd.read_csv("your_data.csv")

# Generate synthetic data in ONE line!
forge = TabularForge(real_data)
synthetic_data = forge.generate(n_samples=1000)

# That's it! synthetic_data is a pandas DataFrame
print(synthetic_data.head())

With Privacy Guarantees

from tabularforge import TabularForge

# Generate with differential privacy (epsilon=1.0)
forge = TabularForge(real_data, privacy_epsilon=1.0)
private_synthetic = forge.generate(n_samples=1000)

# Check privacy metrics
privacy_report = forge.evaluate_privacy()
print(privacy_report)

Compare Different Generators

from tabularforge import TabularForge

# Benchmark all available generators
forge = TabularForge(real_data)
benchmark_results = forge.benchmark(generators=['ctgan', 'tvae', 'copula'])

# See which generator works best for your data
print(benchmark_results)

๐Ÿ“– Detailed Usage

Choosing a Generator

TabularForge supports multiple synthetic data generators:

Generator Best For Speed Quality
copula Simple distributions, fast generation โšกโšกโšก โญโญโญ
ctgan Complex relationships, mixed types โšกโšก โญโญโญโญ
tvae High-dimensional data โšกโšก โญโญโญโญ
# Specify a generator
forge = TabularForge(real_data, generator='ctgan')
synthetic = forge.generate(n_samples=500)

Handling Different Data Types

TabularForge automatically detects and handles:

  • Numerical columns (continuous and discrete)
  • Categorical columns (including high-cardinality)
  • DateTime columns
  • Missing values
# Explicit column type specification (optional)
forge = TabularForge(
    real_data,
    categorical_columns=['gender', 'country', 'product_type'],
    numerical_columns=['age', 'income', 'score'],
    datetime_columns=['signup_date', 'last_purchase']
)

Evaluating Synthetic Data Quality

from tabularforge import TabularForge

forge = TabularForge(real_data)
synthetic = forge.generate(n_samples=1000)

# Get comprehensive quality report
quality_report = forge.evaluate_quality(synthetic)

print(quality_report)
# Output:
# {
#     'statistical_similarity': 0.92,
#     'column_correlations': 0.89,
#     'distribution_match': 0.94,
#     'ml_utility': 0.87
# }

Conditional Generation

Generate data satisfying specific conditions:

# Generate only high-income customers
synthetic = forge.generate(
    n_samples=500,
    conditions={'income': '>100000', 'country': 'UK'}
)

๐Ÿ”’ Privacy Features

Differential Privacy

TabularForge implements differential privacy to provide formal privacy guarantees:

# Lower epsilon = stronger privacy (but lower utility)
# Higher epsilon = weaker privacy (but higher utility)
forge = TabularForge(real_data, privacy_epsilon=0.1)  # Strong privacy
forge = TabularForge(real_data, privacy_epsilon=1.0)  # Balanced
forge = TabularForge(real_data, privacy_epsilon=10.0) # Weak privacy

Privacy Attack Simulation

Test your synthetic data against common privacy attacks:

# Simulate membership inference attack
attack_results = forge.simulate_attack(
    attack_type='membership_inference',
    synthetic_data=synthetic
)

print(f"Attack success rate: {attack_results['success_rate']:.2%}")
# A good synthetic dataset should have ~50% (random guess)

๐Ÿ“Š Use Cases

Healthcare

# Generate synthetic patient cohorts for research
patient_data = pd.read_csv("patient_records.csv")
forge = TabularForge(patient_data, privacy_epsilon=1.0)
synthetic_patients = forge.generate(n_samples=10000)
# Share with researchers without exposing real patients

Finance

# Create synthetic transactions for fraud detection R&D
transactions = pd.read_csv("transactions.csv")
forge = TabularForge(transactions)
synthetic_transactions = forge.generate(n_samples=50000)
# Develop ML models without sensitive financial data

ML Development

# Augment small datasets
small_dataset = pd.read_csv("rare_events.csv")  # Only 100 samples
forge = TabularForge(small_dataset)
augmented = forge.generate(n_samples=10000)
# Now you have enough data to train robust models

๐Ÿ—๏ธ Architecture

tabularforge/
โ”œโ”€โ”€ __init__.py              # Main API exports
โ”œโ”€โ”€ forge.py                 # TabularForge main class
โ”œโ”€โ”€ generators/              # Synthetic data generators
โ”‚   โ”œโ”€โ”€ base.py              # Abstract base generator
โ”‚   โ”œโ”€โ”€ copula.py            # Gaussian Copula generator
โ”‚   โ”œโ”€โ”€ ctgan.py             # CTGAN generator
โ”‚   โ””โ”€โ”€ tvae.py              # TVAE generator
โ”œโ”€โ”€ preprocessing/           # Data preprocessing
โ”‚   โ”œโ”€โ”€ encoder.py           # Column encoding/decoding
โ”‚   โ””โ”€โ”€ transformer.py       # Data transformations
โ”œโ”€โ”€ privacy/                 # Privacy mechanisms
โ”‚   โ”œโ”€โ”€ differential.py      # Differential privacy
โ”‚   โ””โ”€โ”€ attacks.py           # Privacy attack simulations
โ”œโ”€โ”€ metrics/                 # Quality & privacy metrics
โ”‚   โ”œโ”€โ”€ statistical.py       # Statistical similarity
โ”‚   โ”œโ”€โ”€ utility.py           # ML utility metrics
โ”‚   โ””โ”€โ”€ privacy.py           # Privacy metrics
โ””โ”€โ”€ utils/                   # Utilities
    โ”œโ”€โ”€ config.py            # Configuration management
    โ””โ”€โ”€ logging.py           # Logging utilities

๐Ÿงช Development

Setting Up Development Environment

# Clone the repository
git clone https://github.com/ganeshreddy28/tabularforge.git
cd tabularforge

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest tests/ -v

# Run linting
flake8 tabularforge/
black tabularforge/

Running Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=tabularforge --cov-report=html

# Run specific test file
pytest tests/test_generators.py -v

๐Ÿ“š Documentation


๐Ÿค Contributing

Contributions are welcome! Please see our Contributing Guide for details.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ™ Acknowledgments

  • SDV for inspiration on synthetic data APIs
  • CTGAN Paper for the CTGAN architecture
  • The differential privacy research community

๐Ÿ“ฌ Contact


Made with โค๏ธ for the data science community

โญ Star us on GitHub if you find this useful!

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

tabularforge_sgk-0.1.0.tar.gz (42.2 kB view details)

Uploaded Source

Built Distribution

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

tabularforge_sgk-0.1.0-py3-none-any.whl (44.1 kB view details)

Uploaded Python 3

File details

Details for the file tabularforge_sgk-0.1.0.tar.gz.

File metadata

  • Download URL: tabularforge_sgk-0.1.0.tar.gz
  • Upload date:
  • Size: 42.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for tabularforge_sgk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 960d2962aed236249ec1490d3c8717dbfb4e5e70365358422c01440a07f95f1b
MD5 342f993e2be182e9e103c2c613e75777
BLAKE2b-256 ed323159c0c723eb1c3d6ff5c6aca49c235b921ac3a311b4872e96dc7a698c12

See more details on using hashes here.

File details

Details for the file tabularforge_sgk-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tabularforge_sgk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 426dd93f2f4dd26f746d4e94701bcc15d10633478934b1810adcf9702387186c
MD5 5efb0aa553243aa8aa270e995f0a0671
BLAKE2b-256 cf7cb92b38a5762ffda8baa7185b838e3584818e4fe3dd0dc7ff60aee10f5c11

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