Skip to content


ydata-synthetic is equipped to handle both tabular (comprising numeric and categorical features) and sequential, time-series data. In this section we explain how you can quickstart the synthesization of tabular and time-series datasets.

Synthesizing a Tabular Dataset

The following example showcases how to synthesize the Adult Census Income dataset with CTGAN:

    # Import the necessary modules
    from pmlb import fetch_data
    from ydata_synthetic.synthesizers.regular import RegularSynthesizer
    from ydata_synthetic.synthesizers import ModelParameters, TrainParameters

    # Load data
    data = fetch_data('adult')
    num_cols = ['age', 'fnlwgt', 'capital-gain', 'capital-loss', 'hours-per-week']
    cat_cols = ['workclass','education', 'education-num', 'marital-status',
                'occupation', 'relationship', 'race', 'sex', 'native-country', 'target']

    # Define model and training parameters
    ctgan_args = ModelParameters(batch_size=500, lr=2e-4, betas=(0.5, 0.9))
    train_args = TrainParameters(epochs=501)

    # Train the generator model
    synth = RegularSynthesizer(modelname='ctgan', model_parameters=ctgan_args), train_arguments=train_args, num_cols=num_cols, cat_cols=cat_cols)

    # Generate 1000 new synthetic samples
    synth_data = synth.sample(1000) 

Synthesizing a Time-Series Dataset

The following example showcases how to synthesize the Yahoo Stock Price dataset with TimeGAN:

    # Import the necessary modules
    import pandas as pd
    from ydata_synthetic.synthesizers.timeseries import TimeSeriesSynthesizer
    from ydata_synthetic.synthesizers import ModelParameters, TrainParameters

    # Define model parameters
    gan_args = ModelParameters(batch_size=128,

    train_args = TrainParameters(epochs=50000,

    # Read the data
    stock_data = pd.read_csv("stock_data.csv")

    # Training the TimeGAN synthesizer
    synth = TimeSeriesSynthesizer(modelname='timegan', model_parameters=gan_args), train_args, num_cols=list(stock_data.columns))

    # Generating new synthetic samples
    synth_data = synth.sample(n_samples=500)

Running the Streamlit App

Once the package is installed with the "streamlit" extra, the app can be launched as:

    from ydata_synthetic import streamlit_app

The console will then output the URL from which the app can be accessed.

Here's a quick example of how to synthesize data with the Streamlit App – 5min