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.

from sdv.utils import load_synthesizer

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

# for multi-table synthesizers: scale the dataset up using the scale parameter
synthetic_data = synthesizer.sample(scale=1.5)

# for single-table synthesizers: input the number of row to sample
synthetic_data = synthesizer.sample(num_rows=100)

# for sequential synthesizers: input the number of sequences to generate
synthetic_data = synthesizer.sample(num_sequences=10)

Parameters: The sampling parameters and output depends on the type of data and synthesizer you have.

Parameters:

  • 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. This will be a single pandas DataFrame for single table data, or a dictionary of pandas DataFrames for multi-table data.

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).

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