Skip to main content
LearnMLAcademy
Advanced10 min read

Synthetic Data Generation

Generate privacy-preserving synthetic tabular and text datasets using CTGAN, with diffusion diagrams, prompt experiments, and output-quality checks.

What you will master in this lesson
Intuitive core mechanisms & practical real-world intuition
Step-by-step mathematical breakdown & visual diagrams
Runnable Python implementation & practical trade-offs

Synthetic data is designed evidence

Synthetic data consists of records, images, text, audio, or other examples produced by rules, simulations, statistical models, or generative models instead of directly observing each example in the real world. It is useful only when its design and evaluation match the decision the data will support.

Teams create synthetic data to exercise rare situations, test software before real records are available, balance training cases, reduce exposure of sensitive records, or explore controlled scenarios. None of those goals guarantees realism, privacy, or usefulness. Synthetic-data work is both generative modelling and data engineering: schemas, labels, constraints, coverage, lineage, and tests matter.

Synthetic Data Generation in Simple Words

Imagine training an autonomous vehicle for extreme snow blizzards when 99% of your driving logs were recorded on sunny highways. You cannot wait for rare fatal accidents to happen. Synthetic data uses physics engines, diffusion models, or tabular transformers (like CTGAN) to intentionally generate thousands of edge-case scenarios while mathematically safeguarding patient and user privacy with differential privacy!

1

Learn Real Schemas

Model joint column distributions and correlations

2

Rebalance Rare Cases

Oversample rare fraud or minority medical conditions

3

Privacy Guarantees

Inject differential privacy (ε, δ) to prevent memorization

4

TSTR Validation

Train on Synthetic, evaluate strictly on Real test set

Augmentation and a fully synthetic dataset are not the same

Data augmentation

Starts from a real example and applies a validity-preserving change: crop an image, add appropriate noise, or paraphrase text while keeping its label. The synthetic item remains tied to a source example.

Fully synthetic generation

Constructs a record or sample from a rule, simulator, fitted distribution, or generative model. It may resemble the real dataset without being a transformed copy of one selected row.

Four ways to generate synthetic examples

MethodHow examples are producedGood fitMain strengthMain limitation
RulesDeveloper-written logic samples fields under explicit constraintsSchemas, edge cases, unit and integration testsTransparent and controllableMisses interactions the rules do not encode
SimulationA model of a process produces states, measurements, or rendered scenesRobotics, driving, physics, operations, sensor failureCan generate labelled rare or hazardous scenarios safelySimulator-to-real gap can dominate performance
Statistical synthesisA fitted probabilistic model samples tabular or time-series variables and dependenciesStructured datasets with measurable constraintsDistribution checks can be explicitComplex tails and dependencies may be smoothed away
Generative modelsA GAN, VAE, diffusion model, or language model samples learned representationsComplex images, text, audio, and high-dimensional recordsCan model patterns that are hard to hand-codeMay hallucinate, memorize, violate constraints, or hide coverage gaps

A project can combine methods. A simulator might render street scenes, rules might guarantee rare weather and pedestrian combinations, and a generative model might vary texture. The correct question is not “Which method is most advanced?” but “Which assumptions can we test against the real task?”

Figure 1 — Synthetic data enters training only after separate evidence checks

Fidelity, coverage, privacy and label correctness answer different questions. TSTR keeps the final utility test real: train on synthetic or mixed data, then test on untouched real examples.

Authorized real evidence and domain knowledge feed four alternative synthesis methods: rules, simulation, statistical synthesis, and a generative model. These methods produce a synthetic dataset. Four separate branches check fidelity, diversity and coverage, privacy and memorization, and label correctness. After relevant checks pass, a downstream model trains on synthetic or mixed data. It is then evaluated on an untouched real test set that was held aside before synthesis and training.

Worked example: coverage and fidelity can disagree

A real sample contains 100 labelled cases: A = 80 and B = 20. These are data-supplied counts. A developer creates a 100-row synthetic set with A = 60 andB = 40 to expose a classifier to more B cases. These are chosen generation targets.

Real proportions

A: 80 ÷ 100 = 0.80 = 80%

B: 20 ÷ 100 = 0.20 = 20%

Synthetic proportions

A: 60 ÷ 100 = 0.60 = 60%

B: 40 ÷ 100 = 0.40 = 40%

How B changed
count: 40 ÷ 20 = 2× proportion: 40% − 20% = +20 percentage points

The synthetic set doubles the number of B cases and adds 20 percentage points to B's share. That improves minority coverage for intentional balancing, but it does not faithfully reproduce the real class frequency. For population estimation this could be harmful distortion; for training a classifier it may be useful if evaluation remains on the untouched real distribution.

Figure 2 — Rebalancing can improve coverage while reducing distribution fidelity

Both bars contain 100 examples. Synthetic B doubles from 20 to 40, which may be intentional for coverage, but the 60/40 synthetic distribution no longer reproduces the real 80/20 population frequency.

Two proportional bars compare one hundred real examples, with class A equal to eighty and class B equal to twenty, against one hundred synthetic examples, with A equal to sixty and B equal to forty. The B segment is visibly twice as wide in the synthetic bar. One interpretation branch says that reproducing population frequency has lower fidelity. A second branch says that increasing minority coverage may be deliberate. Both lead to validation on untouched real held-out data.

Reproduce the class-distribution calculation

This self-contained Python 3 code derives the proportions and B coverage multiplier from the supplied counts. It does not claim that balance alone makes synthetic data useful.

Python 3 · runnable without extra packages
# Runnable Python 3: calculate class proportions in the worked example.
real = {"A": 80, "B": 20}
synthetic = {"A": 60, "B": 40}

def proportions(counts):
    total = sum(counts.values())
    return {name: count / total for name, count in counts.items()}

print("real:", proportions(real))
print("synthetic:", proportions(synthetic))
print("B coverage multiplier:", synthetic["B"] / real["B"])

Four evaluation dimensions must stay separate

DimensionQuestionPossible evidenceWhat it does not prove
FidelityDoes synthetic data resemble important real distributions and relationships?Marginal and joint distributions, constraints, expert inspectionThat rare cases are covered or a downstream model will work
Diversity / coverageAre important modes, tails, rare cases, and subgroups present?Coverage by subgroup and scenario; duplicate rates; mode analysisThat generated examples are accurate or private
UtilityDoes synthetic data help the real task?Train on synthetic, test on real (TSTR); compare against real-data baselinesThat records cannot reveal training members
PrivacyCould outputs reveal, reproduce, or identify source records?Exact duplicate and nearest-neighbour checks, disclosure tests, privacy accounting where applicableThat the data is useful or unbiased

Utility means testing on real evidence

In train-on-synthetic, test-on-real (TSTR), the model is fitted using synthetic examples and evaluated on a real test set that was not used to fit the synthesizer or the downstream model. The measured score is calculated from real outcomes. Compare it with a model trained on real data, a mixed-data model, and a simple baseline so any claimed benefit has context.

An average can hide harm. Report results for important subgroups, rare scenarios, and time periods. If the real environment drifts after synthesis, repeat distribution and utility checks; a synthetic generator preserves assumptions from its source data or simulator, not future reality.

TSTR (Train on Synthetic, Test on Real) Benchmark Accuracy (%)

All models are evaluated on the identical untouched Real test set to verify downstream statistical utility.

Synthetic data preserves nearly 97% of real-data utility standalone, and combining real with synthetic minority-boosted samples achieves highest performance!

Realistic does not mean private

A high-capacity generator can reproduce a training row or create an output extremely close to one. Exact duplicate checks catch direct copies. Nearest-neighbour checks compare each synthetic record with authorized real records to find suspicious similarity. Membership tests ask whether an attacker can infer that a particular person or record influenced training. Each check covers a different risk.

Removing names after generation is not a privacy guarantee, and visual realism is not privacy evidence. Sensitive uses may require a formal privacy mechanism, restricted access, and an independent risk review. Privacy protection can also change fidelity and utility, so all dimensions must be measured together.

Summary / Key Takeaways

  • Synthetic data is designed evidence produced by rules, simulations, statistical models, or generative models rather than direct observation of every example.
  • Data augmentation transforms a real source example, while fully synthetic generation constructs a sample from a rule or learned process.
  • The right generator depends on which assumptions can be tested against the real task, not on which method sounds most advanced.
  • In the worked example, increasing class B from 20% to 40% doubles its count but intentionally reduces fidelity to the real class frequency.
  • Fidelity, coverage, utility, and privacy answer different questions and must not be treated as interchangeable evidence.
  • Train-on-synthetic, test-on-real evaluates downstream utility on an untouched real test set and should be compared with real-data and mixed-data baselines.
  • Realistic output is not automatically private, and synthetic data cannot replace missing real-world evidence for consequential claims.

Apply this concept in a real hands-on project

You have studied the idea. Now use it in working Python code, see the calculation and output, and explain what changed. Each project includes step-by-step instructions, full source and tests.

Practice challenge: predict an outcome first, run the code, and explain the difference.

Track Your Progress0% curriculum done

Finished "Synthetic Data Generation"?

Mark this lesson as completed to update your progress bar and track your milestones across the full curriculum.

Overall Progress0 / 167 lessons

Was this tutorial helpful?

Your feedback helps us continuously refine and improve our open-access tutorials.

Knowledge Check

Progress: 0/5

Test your active recall. Choose one answer for each question, then check it to reveal the step-by-step reasoning.

Question 1 of 5conceptual
What distinguishes data augmentation from fully synthetic generation?
Question 2 of 5numerical/formula
Class B rises from 20 of 100 real cases to 40 of 100 synthetic cases. How did its coverage change?
Question 3 of 5interpretation
How should the changed 60/40 synthetic class balance be interpreted?
Question 4 of 5debugging/diagnostic
Synthetic records look realistic. Why is that not enough to claim privacy?
Question 5 of 5application/scenario
Which evaluation most directly tests whether synthetic training data helps the real task?

Knowledge Check Review & Explanations

Review the questions, verified correct answers, and conceptual explanations for this lesson.

1What distinguishes data augmentation from fully synthetic generation?▼

Correct Answer: Augmentation starts from a real example and applies a validity-preserving change

An augmented item remains tied to a source example. Fully synthetic generation constructs a sample from rules, simulation, a fitted distribution, or a generative model.

2Class B rises from 20 of 100 real cases to 40 of 100 synthetic cases. How did its coverage change?▼

Correct Answer: It doubled and rose 20 percentage points

The count multiplier is 40 ÷ 20 = 2×, while the share changes from 20% to 40%, an increase of 20 percentage points.

3How should the changed 60/40 synthetic class balance be interpreted?▼

Correct Answer: It improves class-B coverage but no longer reproduces the real 80/20 frequency

Intentional oversampling can help a classifier see more minority cases, but it trades distribution fidelity for coverage and must be evaluated for the intended use.

4Synthetic records look realistic. Why is that not enough to claim privacy?▼

Correct Answer: Realistic generators may still reproduce or closely resemble source records

Realism and privacy are separate dimensions. Duplicate, nearest-neighbour, disclosure, and membership tests investigate risks that appearance alone cannot reveal.

5Which evaluation most directly tests whether synthetic training data helps the real task?▼

Correct Answer: Train on synthetic data and test on untouched real data

TSTR measures a downstream model on real outcomes after fitting on synthetic examples, preserving the real test set as the evidence for usefulness.

Keep moving through the path

Continue Learning

Free Download: ML Interview Cheatsheet

100 essential Machine Learning interview questions and answers covering foundations, algorithms, evaluation, deep learning, Python, system design and interview strategy. Enter your email to download it instantly.

Next