Faker Synthesizer
ydata.synthesizers.FakerSynthesizer
A synthesizer for generating synthetic data based on user-defined configurations.
The FakerSynthesizer allows users to create synthetic tabular data without needing
an existing dataset. Instead, it generates data based on user-provided metadata
or manually defined column configurations. This approach is useful for:
- Creating mock datasets for testing and development.
- Generating data prototypes before real data is available.
- Ensuring privacy-preserving synthetic data without reference to actual records.
Key Features:
- Metadata-Driven Generation: Generates synthetic data based on predefined Metadata.
- Customizable Column Types: Supports user-defined column structures.
- Multi-Language Support: Uses locale settings to generate realistic names, addresses, etc.
Example Usage:
from ydata.synthesizers import FakerSynthesizer
# Initialize the synthesizer with a specific locale
faker_synth = FakerSynthesizer(locale="en") # English data generation
faker_synth.fit(metadata)
# Generate synthetic data
synthetic_data = faker_synth.sample(n_samples=1000)
fit(metadata, calculated_features=None, scaffold=None, reference_data=None, distributions=None, conditions=None)
Configure the FakerSynthesizer using provided metadata.
This method sets up the synthesizer by defining the structure of the synthetic
dataset based on the given Metadata. The metadata can either be:
- Computed: Automatically extracted from an existing dataset.
- User-Defined: Manually constructed to specify custom column types and distributions.
Once fit() is called, the synthesizer will use this metadata to generate
structured synthetic data that adheres to the defined schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
Metadata
|
A metadata object describing the structure of the synthetic dataset, including: - Column names and data types. - Faker-based data generators (e.g., names, addresses, emails). - Value constraints (e.g., numeric ranges, categorical options). |
required |
calculated_features
|
list[dict] | None
|
Optional. Columns computed deterministically from other
columns AFTER sampling — exact identities, sign rules, derived flags.
Same single-table convention as :class: Features are applied in list order (later features may consume earlier
outputs) and are excluded from generation. Cross-table |
None
|
scaffold
|
dict | ScaffoldConfig | None
|
Optional. A declarative structural grid
(:class: |
None
|
reference_data
|
dict[str, DataFrame] | None
|
Optional. Named DataFrames backing the scaffold's
|
None
|
distributions
|
dict[str, dict] | None
|
Optional. Per-column distribution overrides for numerical columns (default: uniform within the declared domain). Pure data, so it can also live in the YAML configuration:: Supported: uniform, normal, lognormal, exponential, poisson,
triangular, beta. |
None
|
conditions
|
list[dict] | None
|
Optional. Conditional generation rules: a column's values are
sampled per segment defined by
|
None
|
sample(sample_size=1000, random_state=None)
Generate a synthetic dataset based on the configured metadata.
This method produces synthetic data according to the schema defined in the
fit() step. The generated data adheres to the column types, constraints,
and distributions specified in the provided Metadata.
When a scaffold was configured in fit(), the scaffold grid defines
both the structural columns (emitted verbatim) and the row count —
sample_size is then ignored. Calculated features configured in fit()
are computed after sampling, in list order, and are never generated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_size
|
int
|
The number of synthetic records/rows to generate. Defaults to |
1000
|
random_state
|
int | None
|
Seed for reproducible sampling (column draws and the scaffold's density filtering). Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dataset |
Dataset
|
A Dataset object with the generated synthetic records/rows. |
save(path)
Saves the SYNTHESIZER and the model fitted per variable.