Skip to content

Fidelity: does it look like the data?

Check a synthetic table at three levels (columns, pairs and whole rows), and see why a table can pass the first and fail the rest.

Applied ~12 min12 steps

What runs in CodeSplash

You will be able to

  • Read column scores from KS and total variation distance
  • Explain why a table can match every column and still lose every relationship
  • Interpret a classifier that tries to tell real rows from synthetic ones

Read first

01

Three levels of "looks like"

Read

FidelityFidelityHow closely synthetic rows match the real ones, column by column, in pairs, and as whole rows. isn't one number. You can ask at three levels:

  1. Columns: does each column on its own match?
  2. Pairs: do pairs of columns move together as they did?
  3. Whole rows: could a classifier tell a synthetic row from a real one?

Each level catches failures that the one before it misses.

02

Can you pass and still fail?

Predict

Predict first

A generator shuffles each column on its own. Every value is real, but each row is now a random mix. How does it score?

Columns good, correlations goodColumns good, correlations goneColumns poor, correlations gone
Reveal

Columns good, correlations gone. Each column has exactly its real values, so a column test sees nothing wrong. All the relationships between columns have been destroyed, and with them most of what makes a table useful.

03

Shuffle a table

Explore

Choose Shuffle each column and look at both outputs.

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?

1.50
How sure?

How it's generated

0.10

Used by “Copy rows and add noise”.

300
  • Real (training)
  • Synthetic
as far as new real rows
  • Privacy ratio
  • Largest column KS × 4

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

The largest column KS should be close to zero, while the correlation gap is large. Now try Fit one bell-shaped cloud. The correlation survives, but the two clusters merge into one, so now the columns suffer.

04

One column at a time

Read

For numbers, the card uses the Kolmogorov–Smirnov distance: the largest gap between two cumulative distributions. For categories, it uses total variation: half the sum of the gaps in shares. A column's score is one minus that distance.

In the customer run, numeric columns have a mean KS of 0.052 and categories a mean total variation of 0.038.

Small distances are expected: even a second real sample would differ a bit. With few rows, this noise gets bigger, as iris shows at 0.119 on 120 rows.

05

Pairs

Read

The scorecard compares pairs with two measures, and each is 100% for a perfect match:

  • Correlation similarity: for pairs of numeric columns, one minus half the gap between real and synthetic correlations, averaged.
  • Contingency similarity: for pairs of categories, one minus the total variation of their joint shares, averaged.

The result card also reports the mean absolute gap in correlations directly. For customers it's 0.042.

06

Can a classifier tell?

Predict

Predict first

You train a classifier on real and synthetic rows, labeled as such. If the generator were perfect, what AUC would it get?

About 0.5About 0.75Close to 1
Reveal

About 0.5: a coin flip. The app's Propensity AUC does this with a ridge logistic regression, and pMSE measures the same gap another way. S_pMSE divides pMSE by the value expected when both tables come from one distribution, so values near 1 are what you hope for. This is propensity score MSEPropensity score MSETrains a classifier to tell real from synthetic rows and measures how far it gets from a coin flip., and it's the only check here that looks at whole rows.

07

How the light is set

Read

Overall fidelity averages the column, correlation and contingency scores. The light also looks at the classifier:

LightOverallPropensity AUC
GoodAt least 90%At most 0.65
CautionAt least 80%At most 0.8
PoorAnything lessAnything more

These are the app's working rules, not laws, and a logistic classifier sees only simple differences. A table can pass and still fail a stronger one.

08

Find the weakest column

In the app

Generate a table in the studio and open Scorecard. The fidelity light's detail names the weakest column.

Read the table under Fidelity by column: amber marks scores below 90% and red below 80%. Compare the Missing real / synth. column too, since missing values often reveal a mismatch.

09

What matters for your job?

Reflect

Fidelity is only worth having where your use depends on it.

Say you plan to use a synthetic table to test whether a dashboard handles real data. Which of the three levels matters most? What if you plan to train a model on it instead? Write one sentence for each.

10

Check your understanding

Checkpoint

Check yourself

A numeric column has a KS distance of 0.05 from the real one. What's its column score? Give it as a decimal.

Show the answer

Answer: 0.95

A column's score is one minus its distance: 1 − 0.05 = 0.95.

Check yourself

All column scores are high, but correlation similarity is low. What do you conclude?

Show the answer

Answer: a

Column scores can't see relationships. Fidelity says nothing about privacy either way.

Check yourself

The propensity AUC is 0.97. What should you do?

Show the answer

Answer: a

Here, 0.5 is the goal. An AUC near 1 means synthetic rows are easy to tell apart, often through an impossible combination that column scores miss.

11

Do it on your own data

In the app

After you save a synthetic table, you can check the first and third levels by hand. These scores use only numeric columns with no missing values, so they differ from the card's.

Python
import numpy as np
import pandas as pd
from scipy import stats
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import roc_auc_score
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler

cols = ["age", "visits", "tenure_months"]
real = pd.read_csv("customers.csv")[cols].dropna()
syn = pd.read_csv("customers_synthetic.csv")[cols].dropna()

for c in cols:
    print(c, round(stats.ks_2samp(real[c], syn[c]).statistic, 3))

X = pd.concat([real, syn])
y = np.r_[np.zeros(len(real)), np.ones(len(syn))]
clf = make_pipeline(StandardScaler(), LogisticRegression()).fit(X, y)
print("propensity AUC", round(roc_auc_score(y, clf.predict_proba(X)[:, 1]), 3))
R
cols <- c("age", "visits", "tenure_months")
real <- na.omit(read.csv("customers.csv")[, cols])
syn <- na.omit(read.csv("customers_synthetic.csv")[, cols])

for (col in cols) {
  ks <- suppressWarnings(ks.test(real[[col]], syn[[col]]))$statistic
  cat(col, round(ks, 3), "\n")
}

d <- rbind(real, syn)
d$synthetic <- rep(0:1, c(nrow(real), nrow(syn)))
p <- fitted(glm(synthetic ~ ., binomial, d))
r <- rank(p)
n1 <- sum(d$synthetic == 1)
n0 <- sum(d$synthetic == 0)
cat("propensity AUC", round((sum(r[d$synthetic == 1]) - n1 * (n1 + 1) / 2) / (n1 * n0), 3), "\n")
12

Recap

Recap
  • Check columns, pairs and whole rows. A shuffled table passes the first and fails the others.
  • Column scores are one minus KS or total variation; some gap is normal, more so with few rows.
  • A classifier that can tell synthetic from real should do no better than a coin flip, so 0.5 is the goal.
  • Fidelity alone says nothing about privacy.

Concepts in this lesson