Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Sdv dev SDV BaseSingleTableSynthesizer Sample

From Leeroopedia
Knowledge Sources
Domains Synthetic_Data, Data_Generation
Last Updated 2026-02-14 00:00 GMT

Overview

Concrete tool for generating synthetic rows from a fitted single-table synthesizer, provided by the SDV library.

Description

The BaseSingleTableSynthesizer.sample method generates synthetic data from a fitted model. It supports batch sampling, constraint enforcement, progress bars, and optional incremental file output.

Usage

Call this method after fitting a synthesizer. It returns a DataFrame with the same schema as the original data.

Code Reference

Source Location

  • Repository: SDV
  • File: sdv/single_table/base.py
  • Lines: L1185-1232

Signature

def sample(self, num_rows, max_tries_per_batch=100, batch_size=None, output_file_path=None):
    """Sample rows from this table.

    Args:
        num_rows (int): Number of rows to sample.
        max_tries_per_batch (int): Retry limit per batch. Defaults to 100.
        batch_size (int or None): Batch size. Defaults to num_rows.
        output_file_path (str or None): File for incremental output. Defaults to None.

    Returns:
        pandas.DataFrame: Sampled data.
    """

Import

from sdv.single_table import GaussianCopulaSynthesizer
# sample is called as: synthesizer.sample(num_rows)

I/O Contract

Inputs

Name Type Required Description
num_rows int Yes Number of synthetic rows to generate
max_tries_per_batch int No Retry limit per batch for constraint satisfaction (default: 100)
batch_size int or None No Rows per sampling batch (default: num_rows)
output_file_path str or None No File for incremental output (default: None)

Outputs

Name Type Description
return value pd.DataFrame Synthetic data with same schema as original

Usage Examples

# After fitting
synthetic_data = synthesizer.sample(num_rows=1000)
print(synthetic_data.head())
print(f"Generated {len(synthetic_data)} rows")

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment