For the complete documentation index, see llms.txt. This page is also available as Markdown.

Sample Realistic Data

Create realistic synthetic data data that follows the same format and mathematical properties as the real data. In the multi-table setting, you can also scale up (or down) the sizes of all tables in your dataset.

Sampling prerequisites. In order to create synthetic data, make sure you have created a synthesizer and trained it on your data using the fit function. For more information, see the Modeling docs.

sample

Use this function to create synthetic data that mimics the real data. This function is available for single- and multi-table synthesizers. For sequential syntheizers, please see the sample_sequences function below.

from sdv.utils import load_synthesizer

synthesizer = load_synthesizer(filepath='my_synthesizer.pkl')

synthetic_data = synthesizer.sample(num_rows=100)

Parameters:

  • (required) num_rows: An integer >0 that specifies the number of rows to synthesize

  • (required for multi-table) main_table_name: A string containing the name of the main table from the dataset. This is require for multi-table datasets. In this case, the num_rows you specify will apply to the main table, and all the other table will be scaled up or down algorithmically in relation to this table.

  • batch_size: An integer >0, describing the number of rows to sample at a time. If you are sampling a large number of rows, setting a smaller batch size allows you to see and save incremental progress.

    • (default) Same as num_rows.

  • max_tries_per_batch: An integer >0, describing the number of sampling attempts to make per batch. If you have included constraints, it may take multiple batches to create valid data.

    • (default) 100.

  • output_folder_path: A string describing the name of a folder for writing the synthetic data. If provided, the synthetic data will be written as CSV files inside the folder. Each CSV file will correspond to a table, named as <table_name>.csv.

    • (deafult) None: Do not write the synthetic data to files.

sample_scale

Use this function to create synthetic data that is scaled up or down for multi-table datasets. This function is only available for multi-table synthesizers.

Parameters:

  • (required) scale: A float >0.0 that describes how much to scale the data by

    • (default) 1: Don't scale the data. The model will create synthetic data that is roughly the same size as the original data.

    • >1: Scale the data by the specified factor. For example, 2.5 will create synthetic data that is roughly 2.5x the size of the original data.

    • <1: Shrink the data by the specified percentage. For example, 0.9 will create synthetic data that is roughly 90% of the size of the original data.

Returns: Synthetic data. The synthetic data is the same format as the original data, which is dictionary mapping the table name to a pandas DataFrame containing the data for it.

How does scaling work for multi-table data? During the fitting process, your SDV synthesizer learns the size of each data table. This is assumed to be a scale of 1. Scaling the entire dataset up or down means that the size of each table will change proportionally based on the original data size.

Note that some synthesizers may perform small, additional algorithmic calculations to determine the final size of each table. However, you can still expect the final synthetic data to approximately follow the scale of the real data (with some minor deviations).

sample_sequences

Use this function to create synthetic data for sequential data. This function is only available for sequential synthesizers.

Parameters:

  • (required) num_sequences: An integer >0 describing the number of sequences to sample

  • sequence_length: An integer >0 describing the length of each sequence. If you provide None, the synthesizer will determine the lengths algorithmically, and the length may be different for each sequence. Defaults to None.

reset_sampling

Use this function to reset any randomization in sampling. After calling this, your synthesizer will generate the same data as before. For example in the code below, synthetic_data1 and synthetic_data2 are the same.

Parameters None

Returns None. Resets the synthesizer.

Last updated