Privacy: how close do synthetic rows come?
Use unseen rows as a yardstick for how close synthetic rows come to real ones, catch exact copies, leave out identifiers, and state what a clean score doesn't show.
What runs in CodeSplash
- Synthetic data — sequential CART Verified in Python and R
- Synthetic data — Gaussian copula Verified in Python and R
You will be able to
- Explain why privacy is measured against rows the generator never saw
- Read distance to closest record and exact-copy rates from the scorecard
- Separate direct identifiers from quasi-identifiers before generating
- State what these checks don't show
Read first
Synthetic isn't automatically private
ReadA generator learns from real people. If it learns too well, it gives them back.
So privacy is something you measure for each table. The scorecard asks a concrete question: are synthetic rows closer to the training rows than you'd expect by chance?
Copy the table
PredictPredict first
A "generator" returns the training table unchanged. How does it score?
Reveal
Fidelity perfect, privacy gone. Every column, pair and row matches, and every row is someone's real record. That's why a perfect fidelity score should worry you, and why the two have to be read together.
The fidelity–privacy frontier
ExploreThe first generator here copies each row and adds noise. Press copy the rows, then raise the noise slowly.
DExplorable · Synthetic data: fidelity against privacy
Can synthetic data look like the real thing without copying it?
A ratio near 1 means synthetic rows sit about as far from the training data as new real rows do. What will this generator's ratio be?
How it's generated
Used by “Copy rows and add noise”.
- Real (training)
- Synthetic
- Privacy ratio
- Largest column KS × 4
Commit your prediction above to see the result
Make your prediction to see the result.
Watch the privacy ratio: the typical distance from a synthetic row to its closest training row, divided by the same for held-out real rows. Around 1, synthetic rows sit about as far away as new real people would. Then try the check: a ratio of at least 1, with a column KS under 0.1.
Unseen rows are the yardstick
ReadHow close is too close? Real data has near neighbors anyway, so raw distance can't say. The fair comparison is with real rows the generator never saw.
That's the distance to closest recordDistance to closest recordHow far a row sits from its nearest training row; synthetic rows should sit no closer than real rows the generator never saw.. For each row, the app finds its nearest training row by Gower distance, for synthetic rows and for holdout rows. Then:
If synthetic rows are no closer than unseen rows, this comes out near 5%.
Read the histogram
ExploreThe scorecard draws both sets of distances.
View data
| Gower distance | pair |
|---|---|
| 0.7175 | synthetic → train |
| 0.2174 | synthetic → train |
| 0.5495 | synthetic → train |
| 0.8781 | synthetic → train |
| 0.3242 | synthetic → train |
| 0.8852 | synthetic → train |
| 0.7705 | synthetic → train |
| 0.2525 | synthetic → train |
| 0.1997 | synthetic → train |
| 0.4702 | synthetic → train |
| 0.8462 | synthetic → train |
| 1.032 | synthetic → train |
| 0.2576 | synthetic → train |
| 0.3339 | synthetic → train |
| 1.013 | synthetic → train |
| 0.5003 | synthetic → train |
| 0.4487 | synthetic → train |
| 0.5033 | synthetic → train |
| 0.5950 | synthetic → train |
| 0.7156 | synthetic → train |
| 0.8409 | synthetic → train |
| 0.4644 | synthetic → train |
| 0.7235 | synthetic → train |
| 0.3089 | synthetic → train |
| 0.4263 | synthetic → train |
| 0.3669 | synthetic → train |
| 0.2826 | synthetic → train |
| 0.4245 | synthetic → train |
| 0.3592 | synthetic → train |
| 0.3586 | synthetic → train |
| 0.3112 | synthetic → train |
| 0.2749 | synthetic → train |
| 0.8823 | synthetic → train |
| 0.5773 | synthetic → train |
| 0.3404 | synthetic → train |
| 0.4394 | synthetic → train |
| 0.3355 | synthetic → train |
| 0.2064 | synthetic → train |
| 1.412 | synthetic → train |
| 0.2338 | synthetic → train |
| 0.1487 | synthetic → train |
| 0.4480 | synthetic → train |
| 0.4224 | synthetic → train |
| 0.4819 | synthetic → train |
| 0.4662 | synthetic → train |
| 0.3114 | synthetic → train |
| 0.6560 | synthetic → train |
| 0.3462 | synthetic → train |
| 0.4096 | synthetic → train |
| 0.5465 | synthetic → train |
| 0.9643 | synthetic → train |
| 0.5391 | synthetic → train |
| 0.1392 | synthetic → train |
| 0.3875 | synthetic → train |
| 0.7416 | synthetic → train |
| 0.3740 | synthetic → train |
| 0.4776 | synthetic → train |
| 1.417 | synthetic → train |
| 0.6222 | synthetic → train |
| 0.7127 | synthetic → train |
First 60 of 3000 rows.
Compare the two medians, the dashed lines, and then the left edges of the two distributions. The left edge is what matters: a pile of synthetic rows near zero with no matching pile of holdout rows suggests memorization.
Medians can look fine while a few rows sit almost on top of real people.
Exact copies
ReadDistance has a blunt companion: count the rows that match a training row in every column. Holdout rows set the baseline, since real data has duplicates anyway.
Worse still are copies of rows that are unique in the data, because those can only be one person.
The sequential trees in the last lesson gave 64 exact copies in 300 rows. Those runs set the holdout to zero, so the card couldn't compare them with anything, and it would say Privacy not measured.
How the light is set
Read| Light | Share closer | Exact copies above holdout | Copies of unique rows |
|---|---|---|---|
| Good | At most 8% | At most 1% | At most 0.5% |
| Caution | At most 15% | At most 5% | At most 2% |
| Poor | Anything more | Anything more | Anything more |
For Share safely, this light sets the verdict: Safe to share, Share inside the team only, or Do not share.
Leave identifiers out first
In the appA generator can only leak what it was given. The Privacy scan in the studio's setup column flags columns before you generate:
- Direct identifiersDirect identifierA column that points to a person on its own, such as a name, e-mail address, phone number or account number.: names, e-mails, phones, account numbers, and near-unique keys.
- Quasi-identifiersQuasi-identifierA column that identifies people only in combination with others, such as age, postcode and occupation together.: age, postcode, occupation and the like, which identify people in combination.
Choose a dataset and read the flags. Use every safe column leaves out the direct identifiers. Keep quasi-identifiers only if the analysis needs them.
The scan reads names, patterns and uniqueness. No identifiers found means the scan found none, so read your columns too.
What a clean score doesn't show
ReflectThese checks look for one kind of leak: rows too close to real ones. They give no formal guarantee. In particular:
- They don't test whether someone could work out that a given person was in the training data.
- They don't test whether a rare combination gives away a sensitive value.
- CodeSplash doesn't offer differential privacy, the approach that gives a mathematical guarantee.
Who would receive your table, and what else might they know about these people? If the honest answer worries you, get a privacy review before it goes out.
Check your understanding
CheckpointCheck yourself
"Share closer" is 31%. What does that mean?
Show the answer
Answer: b
Unseen rows set the baseline of about 5%. At 31%, the generator is hugging its training data, so the card would rate privacy poor.
Check yourself
You set the holdout to 0 to train on every row. What happens to the privacy score?
Show the answer
Answer: a
Without unseen rows there's no yardstick. The card says so, and for sharing, it tells you to generate again with a holdout.
Check yourself
Which is a quasi-identifier rather than a direct identifier?
Show the answer
Answer: a
A postcode alone rarely points to one person, but combined with age and occupation it may. The others point to a person on their own.
Check yourself
The light is green and the verdict says Safe to share. Which statement is justified?
Show the answer
Answer: a
The card reports specific measurements, compatible with low risk of this one kind of leak. It's not a legal finding or a guarantee.
Compute it yourself
In the appHere is the core of the check, for numeric columns only. Each distance is Gower's: differences scaled by the training range, then averaged over the columns.
import numpy as np
import pandas as pd
from sklearn.neighbors import NearestNeighbors
cols = ["age", "visits", "tenure_months"]
train, holdout, synth = (pd.read_csv(f)[cols].dropna() for f in ["train.csv", "holdout.csv", "synthetic.csv"])
scale = train.max() - train.min()
nn = NearestNeighbors(n_neighbors=1, metric="manhattan").fit(train / scale)
d_syn = nn.kneighbors(synth / scale)[0].ravel() / len(cols)
d_hold = nn.kneighbors(holdout / scale)[0].ravel() / len(cols)
print("share closer:", round((d_syn < np.quantile(d_hold, 0.05)).mean(), 3))cols <- c("age", "visits", "tenure_months")
read_cols <- function(f) as.matrix(na.omit(read.csv(f)[, cols]))
train <- read_cols("train.csv")
holdout <- read_cols("holdout.csv")
synth <- read_cols("synthetic.csv")
scale <- apply(train, 2, function(x) diff(range(x)))
nearest <- function(from, to) {
to <- sweep(to, 2, scale, "/")
apply(sweep(from, 2, scale, "/"), 1, function(r) min(rowMeans(abs(sweep(to, 2, r)))))
}
d_syn <- nearest(synth, train)
d_hold <- nearest(holdout, train)
cat("share closer:", round(mean(d_syn < quantile(d_hold, 0.05)), 3), "\n")Recap
Recap- Measure privacy for each table, against real rows the generator never saw.
- Look at the left edge of the distance histogram, and count exact copies and copies of unique rows.
- Leave direct identifiers out, and keep quasi-identifiers only if you need them.
- A clean score fits low risk of one kind of leak. It's not a guarantee.
Concepts in this lesson