The Synthetic Data Vault (SDV) provides a collection of models for generating high-quality synthetic tabular data. The GaussianCopulaSynthesizer uses statistical techniques based on copulas to learn the distribution and correlations from real data, then generate synthetic data that preserves these statistical properties whilst ensuring privacy.
This notebook demonstrates synthetic data generation using the Gaussian Copula model from SDV. We’ll generate 1000 synthetic samples and compare them visually with the original data to assess how well the synthetic data captures the underlying patterns.
import pandas as pd
data = pd.read_csv("_data/sdv/svm-hyperparameters-train-features.csv")
data.head()
data.describe(include="all")
We start by creating a GaussianCopulaSynthesizer which automatically
detects the metadata from our dataset. The Gaussian Copula model works
by:
- Modelling univariate distributions: Each column (Age, Fare, etc.) is fitted to an appropriate distribution
- Capturing correlations: A Gaussian copula models the dependencies between variables
- Generating samples: New synthetic data is drawn from the learned model
import warnings
warnings.filterwarnings('ignore')
from sdv.single_table import GaussianCopulaSynthesizer
from sdv.metadata import SingleTableMetadata
metadata = SingleTableMetadata()
metadata.detect_from_dataframe(data)
model = GaussianCopulaSynthesizer(metadata=metadata)
model.fit(data)
N_SAMPLES = 1000
new_df = model.sample(num_rows=N_SAMPLES)
new_df.head()
new_df.describe()
import warnings
warnings.filterwarnings('ignore')
from sdv.single_table import GaussianCopulaSynthesizer
from sdv.metadata import SingleTableMetadata
metadata = SingleTableMetadata()
metadata.detect_from_dataframe(data)
metadata.update_column('Pclass', sdtype='categorical')
metadata.update_column('Sex', sdtype='categorical')
model = GaussianCopulaSynthesizer(metadata=metadata)
model.fit(data)
new_df = model.sample(num_rows=N_SAMPLES)
new_df.head()
data.Fare.describe()
from sdv.single_table import GaussianCopulaSynthesizer
from sdv.metadata import SingleTableMetadata
metadata = SingleTableMetadata()
metadata.detect_from_dataframe(data)
metadata.update_column('Pclass', sdtype='categorical')
metadata.update_column('Sex', sdtype='categorical')
model = GaussianCopulaSynthesizer(metadata=metadata)
model.fit(data)
new_df = model.sample(num_rows=N_SAMPLES)
new_df.Fare.describe()