Your first synthetic dataset
Generate a table of rows that never happened, see how a Gaussian copula builds them, and meet the three questions every synthetic table has to answer.
What runs in CodeSplash
- Synthetic data — Gaussian copula Verified in Python and R
You will be able to
- Say what synthetic data is for, and why the purpose decides which score matters
- Explain how a Gaussian copula keeps each column's shape and their correlations
- Generate, score and save a synthetic table in the studio
Rows that never happened
ReadSynthetic dataSynthetic dataRows drawn from a model of a real table, meant to resemble it without being anyone's actual record. is drawn from a model of a real table. You fit a generator to your rows, then ask it for new ones. Each new row looks like it could have come from the table, without being anyone's actual record.
People use it for three jobs:
- Share safely: give the data to people who may not see the real rows.
- Augment training data: add rows for a model.
- Test fixtures: get realistic rows for demos, tests and development.
Which score decides?
PredictPredict first
You want to send a customer table to an outside vendor who may not see real records. Which question should decide whether the table goes out?
Reveal
How close synthetic rows come to real people. A table can match the columns well and still contain near-copies of customers. In the studio, the purpose you pick decides which scores drive the verdict: privacy for sharing, utility and fidelity for augmenting, and column shapes for test fixtures.
Make one
In the appOpen Studios, choose Synthetic data, and pick Share a privacy-safe copy.
Here is the same generator run on a table of customers. It kept 80 of 400 rows out of training, learned from the other 320, and drew 320 new rows.
320 synthetic rows over 8 columns from 320 training rows with a Gaussian copula. Numeric columns differ from the data by a mean Kolmogorov–Smirnov distance of 0.052 and categories by a mean total variation of 0.038.
- Synthetic rows
- 320
- Mean KS distance
- 0.0520
- Mean TV distance
- 0.0375
- Rows copied from the data
- 0
Plots
View data
| Density | Source | age |
|---|---|---|
| 0.0230 | real | 18.950 |
| 0.0016 | real | 20.850 |
| 0.0049 | real | 22.750 |
| 0.0148 | real | 24.650 |
| 0.0148 | real | 26.550 |
| 0.0181 | real | 28.450 |
| 0.0197 | real | 30.350 |
| 0.0296 | real | 32.250 |
| 0.0362 | real | 34.150 |
| 0.0115 | real | 36.050 |
| 0.0362 | real | 37.950 |
| 0.0313 | real | 39.850 |
| 0.0296 | real | 41.750 |
| 0.0280 | real | 43.650 |
| 0.0280 | real | 45.550 |
| 0.0181 | real | 47.450 |
| 0.0164 | real | 49.350 |
| 0.0197 | real | 51.250 |
| 0.0362 | real | 53.150 |
| 0.0148 | real | 55.050 |
| 0.0164 | real | 56.950 |
| 0.0181 | real | 58.850 |
| 0.0082 | real | 60.750 |
| 0.0164 | real | 62.650 |
| 0.0049 | real | 64.550 |
| 0.0115 | real | 66.450 |
| 0.0066 | real | 68.350 |
| 0.0049 | real | 70.250 |
| 0.0016 | real | 72.150 |
| 0.0049 | real | 74.050 |
| 0.0164 | synthetic | 18.950 |
| 0 | synthetic | 20.850 |
| 0.0033 | synthetic | 22.750 |
| 0.0164 | synthetic | 24.650 |
| 0.0164 | synthetic | 26.550 |
| 0.0148 | synthetic | 28.450 |
| 0.0214 | synthetic | 30.350 |
| 0.0197 | synthetic | 32.250 |
| 0.0313 | synthetic | 34.150 |
| 0.0082 | synthetic | 36.050 |
| 0.0395 | synthetic | 37.950 |
| 0.0378 | synthetic | 39.850 |
| 0.0263 | synthetic | 41.750 |
| 0.0280 | synthetic | 43.650 |
| 0.0280 | synthetic | 45.550 |
| 0.0197 | synthetic | 47.450 |
| 0.0132 | synthetic | 49.350 |
| 0.0214 | synthetic | 51.250 |
| 0.0428 | synthetic | 53.150 |
| 0.0247 | synthetic | 55.050 |
| 0.0214 | synthetic | 56.950 |
| 0.0181 | synthetic | 58.850 |
| 0.0082 | synthetic | 60.750 |
| 0.0115 | synthetic | 62.650 |
| 0.0082 | synthetic | 64.550 |
| 0.0148 | synthetic | 66.450 |
| 0.0066 | synthetic | 68.350 |
| 0.0033 | synthetic | 70.250 |
| 0.0033 | synthetic | 72.150 |
| 0.0016 | synthetic | 74.050 |
View data
| Density | Source | annual income |
|---|---|---|
| 3.010e-6 | real | 6851.93 |
| 1.605e-5 | real | 10141.74 |
| 2.107e-5 | real | 13431.55 |
| 2.408e-5 | real | 16721.36 |
| 3.511e-5 | real | 20011.17 |
| 4.113e-5 | real | 23300.98 |
| 2.809e-5 | real | 26590.79 |
| 2.408e-5 | real | 29880.60 |
| 2.508e-5 | real | 33170.41 |
| 1.605e-5 | real | 36460.22 |
| 1.605e-5 | real | 39750.03 |
| 1.505e-5 | real | 43039.84 |
| 1.003e-5 | real | 46329.65 |
| 5.016e-6 | real | 49619.46 |
| 6.019e-6 | real | 52909.27 |
| 4.013e-6 | real | 56199.07 |
| 4.013e-6 | real | 59488.88 |
| 4.013e-6 | real | 62778.69 |
| 1.003e-6 | real | 66068.50 |
| 1.003e-6 | real | 69358.31 |
| 1.003e-6 | real | 72648.12 |
| 0 | real | 75937.93 |
| 1.003e-6 | real | 79227.74 |
| 1.003e-6 | real | 82517.55 |
| 0 | real | 85807.36 |
| 0 | real | 89097.17 |
| 0 | real | 92386.98 |
| 0 | real | 95676.79 |
| 0 | real | 98966.60 |
| 1.003e-6 | real | 102256.41 |
| 4.000e-6 | synthetic | 6851.93 |
| 9.999e-6 | synthetic | 10141.74 |
| 1.800e-5 | synthetic | 13431.55 |
| 3.100e-5 | synthetic | 16721.36 |
| 3.200e-5 | synthetic | 20011.17 |
| 3.200e-5 | synthetic | 23300.98 |
| 3.300e-5 | synthetic | 26590.79 |
| 2.000e-5 | synthetic | 29880.60 |
| 3.100e-5 | synthetic | 33170.41 |
| 2.100e-5 | synthetic | 36460.22 |
| 1.400e-5 | synthetic | 39750.03 |
| 9.999e-6 | synthetic | 43039.84 |
| 1.300e-5 | synthetic | 46329.65 |
| 5.999e-6 | synthetic | 49619.46 |
| 4.999e-6 | synthetic | 52909.27 |
| 4.000e-6 | synthetic | 56199.07 |
| 7.999e-6 | synthetic | 59488.88 |
| 6.999e-6 | synthetic | 62778.69 |
| 2.000e-6 | synthetic | 66068.50 |
| 0 | synthetic | 69358.31 |
| 0 | synthetic | 72648.12 |
| 9.999e-7 | synthetic | 75937.93 |
| 0 | synthetic | 79227.74 |
| 0 | synthetic | 82517.55 |
| 0 | synthetic | 85807.36 |
| 9.999e-7 | synthetic | 89097.17 |
| 0 | synthetic | 92386.98 |
| 0 | synthetic | 95676.79 |
| 0 | synthetic | 98966.60 |
| 9.999e-7 | synthetic | 102256.41 |
View data
| Density | Source | tenure_months |
|---|---|---|
| 0.0938 | real | 0.7667 |
| 0.0224 | real | 2.300 |
| 0.0183 | real | 3.833 |
| 0.0306 | real | 5.367 |
| 0.0204 | real | 6.900 |
| 0.0265 | real | 8.433 |
| 0.0204 | real | 9.967 |
| 0.0530 | real | 11.500 |
| 0.0183 | real | 13.033 |
| 0.0510 | real | 14.567 |
| 0.0183 | real | 16.100 |
| 0.0367 | real | 17.633 |
| 0.0224 | real | 19.167 |
| 0.0448 | real | 20.700 |
| 0.0469 | real | 22.233 |
| 0.0082 | real | 23.767 |
| 0.0306 | real | 25.300 |
| 0.0061 | real | 26.833 |
| 0.0183 | real | 28.367 |
| 0.0041 | real | 29.900 |
| 0.0143 | real | 31.433 |
| 0.0061 | real | 32.967 |
| 0.0183 | real | 34.500 |
| 0.0020 | real | 36.033 |
| 0.0041 | real | 37.567 |
| 0 | real | 39.100 |
| 0.0061 | real | 40.633 |
| 0.0041 | real | 42.167 |
| 0.0020 | real | 43.700 |
| 0.0041 | real | 45.233 |
| 0.0836 | synthetic | 0.7667 |
| 0.0245 | synthetic | 2.300 |
| 0.0143 | synthetic | 3.833 |
| 0.0224 | synthetic | 5.367 |
| 0.0163 | synthetic | 6.900 |
| 0.0265 | synthetic | 8.433 |
| 0.0204 | synthetic | 9.967 |
| 0.0510 | synthetic | 11.500 |
| 0.0122 | synthetic | 13.033 |
| 0.0591 | synthetic | 14.567 |
| 0.0122 | synthetic | 16.100 |
| 0.0408 | synthetic | 17.633 |
| 0.0285 | synthetic | 19.167 |
| 0.0387 | synthetic | 20.700 |
| 0.0632 | synthetic | 22.233 |
| 0.0082 | synthetic | 23.767 |
| 0.0387 | synthetic | 25.300 |
| 0.0082 | synthetic | 26.833 |
| 0.0204 | synthetic | 28.367 |
| 0.0020 | synthetic | 29.900 |
| 0.0245 | synthetic | 31.433 |
| 0.0102 | synthetic | 32.967 |
| 0.0061 | synthetic | 34.500 |
| 0.0041 | synthetic | 36.033 |
| 0.0041 | synthetic | 37.567 |
| 0 | synthetic | 39.100 |
| 0.0020 | synthetic | 40.633 |
| 0.0041 | synthetic | 42.167 |
| 0.0061 | synthetic | 43.700 |
| 0 | synthetic | 45.233 |
View data
| Density | Source | signup |
|---|---|---|
| 0.0005 | real | 17582.23 |
| 0.0007 | real | 17654.70 |
| 0.0005 | real | 17727.17 |
| 0.0005 | real | 17799.63 |
| 0.0004 | real | 17872.10 |
| 0.0005 | real | 17944.57 |
| 0.0006 | real | 18017.03 |
| 0.0004 | real | 18089.50 |
| 0.0005 | real | 18161.97 |
| 0.0005 | real | 18234.43 |
| 0.0001 | real | 18306.90 |
| 0.0009 | real | 18379.37 |
| 0.0006 | real | 18451.83 |
| 0.0003 | real | 18524.30 |
| 0.0005 | real | 18596.77 |
| 0.0004 | real | 18669.23 |
| 0.0002 | real | 18741.70 |
| 0.0005 | real | 18814.17 |
| 0.0006 | real | 18886.63 |
| 0.0005 | real | 18959.10 |
| 0.0005 | real | 19031.57 |
| 0.0005 | real | 19104.03 |
| 0.0003 | real | 19176.50 |
| 0.0006 | real | 19248.97 |
| 0.0004 | real | 19321.43 |
| 0.0003 | real | 19393.90 |
| 0.0002 | real | 19466.37 |
| 0.0005 | real | 19538.83 |
| 0.0003 | real | 19611.30 |
| 0.0004 | real | 19683.77 |
| 0.0006 | synthetic | 17582.23 |
| 0.0006 | synthetic | 17654.70 |
| 0.0004 | synthetic | 17727.17 |
| 0.0005 | synthetic | 17799.63 |
| 0.0005 | synthetic | 17872.10 |
| 0.0005 | synthetic | 17944.57 |
| 0.0006 | synthetic | 18017.03 |
| 0.0005 | synthetic | 18089.50 |
| 0.0007 | synthetic | 18161.97 |
| 0.0005 | synthetic | 18234.43 |
| 0.0002 | synthetic | 18306.90 |
| 0.0010 | synthetic | 18379.37 |
| 0.0009 | synthetic | 18451.83 |
| 0.0004 | synthetic | 18524.30 |
| 0.0003 | synthetic | 18596.77 |
| 0.0003 | synthetic | 18669.23 |
| 0.0001 | synthetic | 18741.70 |
| 0.0005 | synthetic | 18814.17 |
| 0.0007 | synthetic | 18886.63 |
| 0.0004 | synthetic | 18959.10 |
| 0.0004 | synthetic | 19031.57 |
| 0.0003 | synthetic | 19104.03 |
| 0.0004 | synthetic | 19176.50 |
| 0.0006 | synthetic | 19248.97 |
| 0.0003 | synthetic | 19321.43 |
| 0.0004 | synthetic | 19393.90 |
| 0.0002 | synthetic | 19466.37 |
| 0.0002 | synthetic | 19538.83 |
| 0.0002 | synthetic | 19611.30 |
| 0.0003 | synthetic | 19683.77 |
View data
| plan | Share | Source |
|---|---|---|
| basic | 0.3563 | real |
| plus | 0.3969 | real |
| premium | 0.2469 | real |
| basic | 0.3031 | synthetic |
| plus | 0.4031 | synthetic |
| premium | 0.2938 | synthetic |
View data
| region | Share | Source |
|---|---|---|
| east | 0.2848 | real |
| north | 0.2718 | real |
| south | 0.3042 | real |
| west | 0.1392 | real |
| east | 0.2754 | synthetic |
| north | 0.2656 | synthetic |
| south | 0.3115 | synthetic |
| west | 0.1475 | synthetic |
View data
| churned | Share | Source |
|---|---|---|
| false | 0.7688 | real |
| true | 0.2313 | real |
| false | 0.7250 | synthetic |
| true | 0.2750 | synthetic |
View data
| Column | Column | Difference |
|---|---|---|
| age | age | 0 |
| annual income | age | −0.0395 |
| tenure_months | age | 0.0251 |
| signup | age | 0.0161 |
| visits | age | 0.0482 |
| age | annual income | −0.0395 |
| annual income | annual income | 0 |
| tenure_months | annual income | −0.0986 |
| signup | annual income | 0.0416 |
| visits | annual income | 0.0930 |
| age | tenure_months | 0.0251 |
| annual income | tenure_months | −0.0986 |
| tenure_months | tenure_months | 0 |
| signup | tenure_months | 0.0056 |
| visits | tenure_months | −0.0217 |
| age | signup | 0.0161 |
| annual income | signup | 0.0416 |
| tenure_months | signup | 0.0056 |
| signup | signup | 0 |
| visits | signup | −0.0303 |
| age | visits | 0.0482 |
| annual income | visits | 0.0930 |
| tenure_months | visits | −0.0217 |
| signup | visits | −0.0303 |
| visits | visits | 0 |
Real vs synthetic, column by column
| Column | Kind | Real | Synthetic | Distance | Measure |
|---|---|---|---|---|---|
| age | numeric | 43.14 ± 13.1 | 44.19 ± 12.6 | 0.0531 | Kolmogorov–Smirnov D |
| annual income | numeric | 2.929e+04 ± 1.43e+04 | 3.043e+04 ± 1.47e+04 | 0.0508 | Kolmogorov–Smirnov D |
| tenure_months | numeric | 15 ± 10.7 | 15.7 ± 10.4 | 0.0500 | Kolmogorov–Smirnov D |
| plan | categorical | plus 39.7% | plus 40.3% | 0.0531 | total variation |
| region | categorical | south 30.4% | south 31.1% | 0.0157 | total variation |
| churned | boolean | false 76.9% | false 72.5% | 0.0437 | total variation |
| signup | temporal | 2020-11-05 ± 621 days | 2020-08-22 ± 593 days | 0.0844 | Kolmogorov–Smirnov D |
| visits | numeric | 3.394 ± 2.09 | 3.469 ± 2.14 | 0.0219 | Kolmogorov–Smirnov D |
Copula correlations (normal scores)
| Column | age | annual income | tenure_months | plan | region | churned | signup | visits |
|---|---|---|---|---|---|---|---|---|
| age | 1 | 0.3161 | 0.7229 | 0.1714 | −0.0043 | −0.0816 | −0.0289 | 0.0342 |
| annual income | 0.3161 | 1 | 0.1855 | 0.6503 | −0.1323 | −0.0202 | −0.0244 | 0.2147 |
| tenure_months | 0.7229 | 0.1855 | 1 | 0.1515 | 0.0518 | −0.1174 | −0.0413 | 0.0361 |
| plan | 0.1714 | 0.6503 | 0.1515 | 1 | −0.0928 | −0.1387 | −0.0624 | 0.3428 |
| region | −0.0043 | −0.1323 | 0.0518 | −0.0928 | 1 | 0.0850 | 0.0078 | 0.0240 |
| churned | −0.0816 | −0.0202 | −0.1174 | −0.1387 | 0.0850 | 1 | 0.0535 | −0.0268 |
| signup | −0.0289 | −0.0244 | −0.0413 | −0.0624 | 0.0078 | 0.0535 | 1 | −0.0207 |
| visits | 0.0342 | 0.2147 | 0.0361 | 0.3428 | 0.0240 | −0.0268 | −0.0207 | 1 |
- 80 of 400 rows (20%) were held out of training so privacy and utility can be checked against rows the generator never saw.
The exact R script · R R version 4.5.1 (2025-06-13)
# Synthetic data — Gaussian copula
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method synth.copula 1.1.0 · spec 9387f102a28b36bf
# Dataset: g1_customers (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
library(codesplashr)
# %% Data
COLUMNS <- c("age", "annual income", "tenure_months", "plan", "region", "churned", "signup", "visits")
KINDS <- list(
age = "numeric",
`annual income` = "numeric",
tenure_months = "numeric",
plan = "categorical",
region = "categorical",
churned = "boolean",
signup = "temporal",
visits = "numeric"
)
LEVELS <- list(
plan = c("basic", "plus", "premium"),
region = c("east", "north", "south", "west")
)
SEED <- 42
loaded <- cs_synth_load("tests/parity/fixtures/g1_customers.parquet", COLUMNS, KINDS, LEVELS)
cols <- loaded$cols; n_input <- loaded$n
for (c in cols) if (c$kind == "numeric") cs_check_finite(c$values, c$name) # infinite values stop the run (registry/errors.yaml)
rng <- cs_rng(SEED) # shared stream: the same holdout and the same synthetic rows in Python and R
sp <- cs_synth_split(n_input, 0.2, rng)
train_rows <- sp$train; holdout_rows <- sp$holdout
train <- lapply(cols, cs_synth_take, rows = train_rows)
N_OUT <- length(train_rows)
warnings <- list()
fit_values <- list()
extra_tables <- list()
model_note <- ""
if (length(holdout_rows)) {
warnings <- c(warnings, sprintf("%s of %s rows (%.0f%%) were held out of training so privacy and utility can be checked against rows the generator never saw.",
format(length(holdout_rows), big.mark = ","), format(n_input, big.mark = ","), 100 * length(holdout_rows) / n_input))
}
for (c in train) if (mean(cs_synth_missing(c)) == 1) cs_error("CS_E_ALL_MISSING", column = c$name) # no values in the training rows
# %% Generate
# Gaussian copula (twin: codesplash.synth.copula): normal scores -> correlation -> shared-stream
# draws -> each column's marginal (interpolated values for numbers).
fit <- cs_synth_copula(train, N_OUT, rng, marginal = "interpolated")
synth <- fit$cols
R <- fit$R
fit_values$marginal <- "interpolated"
up <- which(upper.tri(R), arr.ind = TRUE)
up <- up[order(up[, 1], up[, 2]), , drop = FALSE]
fit_values$max_abs_corr <- if (nrow(up)) max(abs(R[up])) else 0
for (r in seq_len(nrow(up))) fit_values[[sprintf("corr[%s,%s]", COLUMNS[up[r, 1]], COLUMNS[up[r, 2]])]] <- R[up[r, 1], up[r, 2]]
model_note <- " with a Gaussian copula"
# Copula (dependence) log density per row: mean over complete training rows and held-out rows. Not
# reported when the correlation of normal scores is (nearly) singular: the density is then meaningless.
if (min(eigen(R, symmetric = TRUE, only.values = TRUE)$values) < 1e-6) {
fit_values$copula_loglik_train <- NA_real_ # NA publishes as null
fit_values$copula_loglik_holdout <- NA_real_
warnings <- c(warnings, "The copula's log density is not reported: the correlation of the normal scores is singular (too few complete rows, or columns that move together exactly).")
} else {
ld_train_ <- cs_synth_copula_log_density(train, R, train)
fit_values$copula_loglik_train <- mean(ld_train_, na.rm = TRUE)
ld_hold_ <- if (length(holdout_rows)) cs_synth_copula_log_density(train, R, lapply(cols, cs_synth_take, rows = holdout_rows)) else numeric(0)
fit_values$copula_loglik_holdout <- if (any(!is.na(ld_hold_))) mean(ld_hold_, na.rm = TRUE) else NA_real_ # NA publishes as null
}
crow <- lapply(seq_along(COLUMNS), function(i) c(list(column = COLUMNS[i]), stats::setNames(as.list(R[i, ]), sprintf("c%d", seq_along(COLUMNS) - 1L))))
extra_tables <- list(list(
key = "copula", title = "Copula correlations (normal scores)",
columns = c(list(list(key = "column", label = "Column", type = "string")),
lapply(seq_along(COLUMNS), function(j) list(key = sprintf("c%d", j - 1L), label = COLUMNS[j], type = "number"))),
rows = crow))
synth <- cs_synth_add_missing(synth, train, rng, "keep_rate") # each column's missing share, at random
# %% Write and compare
out <- cs_ml_out_dir("target/academy-parity/run-54123/synth.copula/customers_all/out-r")
path <- cs_synth_write(file.path(out, "synthetic.parquet"), synth)
split <- cs_synth_write_split(file.path(out, "split.parquet"), n_input, train_rows, holdout_rows)
sm <- cs_synth_summarize(train, synth, length(train_rows), n_input, length(holdout_rows), fit_values)
values <- sm$values
summary <- sprintf("%s synthetic rows over %d column%s from %s training rows%s.",
format(values$n_rows, big.mark = ","), length(COLUMNS), if (length(COLUMNS) != 1) "s" else "",
format(length(train_rows), big.mark = ","), model_note)
if (!is.nan(values$fidelity_ks_mean)) {
summary <- paste0(summary, sprintf(" Numeric columns differ from the data by a mean Kolmogorov–Smirnov distance of %.3f", values$fidelity_ks_mean),
if (!is.nan(values$fidelity_tv_mean)) sprintf(" and categories by a mean total variation of %.3f.", values$fidelity_tv_mean) else ".")
} else if (!is.nan(values$fidelity_tv_mean)) {
summary <- paste0(summary, sprintf(" Categories differ from the data by a mean total variation of %.3f.", values$fidelity_tv_mean))
}
if (values$exact_matches > 0) {
summary <- paste0(summary, sprintf(" %s synthetic row%s identical to a training row.", format(values$exact_matches, big.mark = ","),
if (values$exact_matches != 1) "s are" else " is"))
}
cs_synth_publish(
"Synthetic data — Gaussian copula",
cs_engine_info("stats", "nanoparquet", "nanoparquet"),
summary, values, sm$table, sm$charts, warnings,
list(list(key = "synthetic", path = path, format = "parquet", title = "Synthetic rows"),
list(key = "split", path = split, format = "parquet", title = "Training and holdout rows")),
list(kind = "generator", columns = I(COLUMNS), params = list(
n_rows = NULL,
marginal = "interpolated",
missing = "keep_rate",
holdout = 0.2
)),
extra_tables
)
320 synthetic rows over 8 columns from 320 training rows with a Gaussian copula. Numeric columns differ from the data by a mean Kolmogorov–Smirnov distance of 0.052 and categories by a mean total variation of 0.038.
- Synthetic rows
- 320
- Mean KS distance
- 0.0520
- Mean TV distance
- 0.0375
- Rows copied from the data
- 0
To keep this page light, the plots are shown once, under the R tab.
Real vs synthetic, column by column
| Column | Kind | Real | Synthetic | Distance | Measure |
|---|---|---|---|---|---|
| age | numeric | 43.14 ± 13.1 | 44.19 ± 12.6 | 0.0531 | Kolmogorov–Smirnov D |
| annual income | numeric | 2.929e+04 ± 1.43e+04 | 3.043e+04 ± 1.47e+04 | 0.0508 | Kolmogorov–Smirnov D |
| tenure_months | numeric | 15 ± 10.7 | 15.7 ± 10.4 | 0.0500 | Kolmogorov–Smirnov D |
| plan | categorical | plus 39.7% | plus 40.3% | 0.0531 | total variation |
| region | categorical | south 30.4% | south 31.1% | 0.0157 | total variation |
| churned | boolean | false 76.9% | false 72.5% | 0.0438 | total variation |
| signup | temporal | 2020-11-05 ± 621 days | 2020-08-22 ± 593 days | 0.0844 | Kolmogorov–Smirnov D |
| visits | numeric | 3.394 ± 2.09 | 3.469 ± 2.14 | 0.0219 | Kolmogorov–Smirnov D |
Copula correlations (normal scores)
| Column | age | annual income | tenure_months | plan | region | churned | signup | visits |
|---|---|---|---|---|---|---|---|---|
| age | 1 | 0.3161 | 0.7229 | 0.1714 | −0.0043 | −0.0816 | −0.0289 | 0.0342 |
| annual income | 0.3161 | 1 | 0.1855 | 0.6503 | −0.1323 | −0.0202 | −0.0244 | 0.2147 |
| tenure_months | 0.7229 | 0.1855 | 1 | 0.1515 | 0.0518 | −0.1174 | −0.0413 | 0.0361 |
| plan | 0.1714 | 0.6503 | 0.1515 | 1 | −0.0928 | −0.1387 | −0.0624 | 0.3428 |
| region | −0.0043 | −0.1323 | 0.0518 | −0.0928 | 1 | 0.0850 | 0.0078 | 0.0240 |
| churned | −0.0816 | −0.0202 | −0.1174 | −0.1387 | 0.0850 | 1 | 0.0535 | −0.0268 |
| signup | −0.0289 | −0.0244 | −0.0413 | −0.0624 | 0.0078 | 0.0535 | 1 | −0.0207 |
| visits | 0.0342 | 0.2147 | 0.0361 | 0.3428 | 0.0240 | −0.0268 | −0.0207 | 1 |
- 80 of 400 rows (20%) were held out of training so privacy and utility can be checked against rows the generator never saw.
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Synthetic data — Gaussian copula
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method synth.copula 1.1.0 · spec 9387f102a28b36bf
# Dataset: g1_customers (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import os
import numpy as np
import codesplash as cs
from codesplash.errors import check_finite
from codesplash.ml.run import out_dir
from codesplash.stats.rng import Rng
from codesplash.synth import common as sy
from codesplash.synth import copula
from codesplash.synth import copula_density
# %% Data
COLUMNS = ["age", "annual income", "tenure_months", "plan", "region", "churned", "signup", "visits"]
KINDS = {
"age": "numeric",
"annual income": "numeric",
"tenure_months": "numeric",
"plan": "categorical",
"region": "categorical",
"churned": "boolean",
"signup": "temporal",
"visits": "numeric",
}
LEVELS = {
"plan": ["basic", "plus", "premium"],
"region": ["east", "north", "south", "west"],
}
SEED = 42
cols, n_input = sy.load("tests/parity/fixtures/g1_customers.parquet", COLUMNS, KINDS, LEVELS)
for c in cols:
if c.kind == "numeric":
check_finite(c.values, c.name) # infinite values stop the run (registry/errors.yaml)
rng = Rng(SEED) # shared stream: the same holdout and the same synthetic rows in Python and R
train_rows, holdout_rows = sy.split_holdout(n_input, 0.2, rng)
train = [c.take(train_rows) for c in cols]
N_OUT = None or len(train_rows)
warnings = []
fit_values = {}
extra_tables = []
model_note = ""
if len(holdout_rows):
warnings.append(f"{len(holdout_rows):,} of {n_input:,} rows ({len(holdout_rows) / n_input:.0%}) were held out of training so privacy and utility can be checked against rows the generator never saw.")
for c in train:
share = float(np.mean(c.missing()))
if share == 1.0:
cs.cs_error("CS_E_ALL_MISSING", column=c.name) # no values in the training rows
# %% Generate
# Gaussian copula (twin: codesplashr::cs_synth_copula): normal scores → correlation → shared-stream
# draws → each column's marginal (interpolated values for numbers).
synth, R = copula.synthesize(train, N_OUT, rng, marginal="interpolated")
fit_values["marginal"] = "interpolated"
iu = np.triu_indices(len(COLUMNS), 1)
fit_values["max_abs_corr"] = float(np.max(np.abs(R[iu]))) if len(iu[0]) else 0.0
for i, j in zip(*iu):
fit_values[f"corr[{COLUMNS[i]},{COLUMNS[j]}]"] = float(R[i, j])
model_note = " with a Gaussian copula"
# Copula (dependence) log density per row: mean over complete training rows and held-out rows. Not
# reported when the correlation of normal scores is (nearly) singular: the density is then meaningless.
if float(np.linalg.eigvalsh(R).min()) < 1e-6:
fit_values["copula_loglik_train"] = None
fit_values["copula_loglik_holdout"] = None
warnings.append("The copula's log density is not reported: the correlation of the normal scores is singular (too few complete rows, or columns that move together exactly).")
else:
_ld_train = copula_density.log_density(train, R, train)
fit_values["copula_loglik_train"] = float(np.nanmean(_ld_train))
_ld_hold = copula_density.log_density(train, R, [c.take(holdout_rows) for c in cols]) if len(holdout_rows) else np.array([])
fit_values["copula_loglik_holdout"] = float(np.nanmean(_ld_hold)) if np.any(~np.isnan(_ld_hold)) else None
extra_tables.append({
"key": "copula",
"title": "Copula correlations (normal scores)",
"columns": [{"key": "column", "label": "Column", "type": "string"}] + [{"key": f"c{j}", "label": c, "type": "number"} for j, c in enumerate(COLUMNS)],
"rows": [{"column": a, **{f"c{j}": float(R[i, j]) for j in range(len(COLUMNS))}} for i, a in enumerate(COLUMNS)],
})
sy.add_missing(synth, train, rng, "keep_rate") # each column's missing share, at random
# %% Write and compare
out = out_dir("target/academy-parity/run-54123/synth.copula/customers_all/out-python")
path = sy.write(os.path.join(out, "synthetic.parquet"), synth)
split = sy.write_split(os.path.join(out, "split.parquet"), n_input, train_rows, holdout_rows)
values, table, charts = sy.summarize(train, synth, len(train_rows), n_input, len(holdout_rows), fit_values)
summary = (
f"{values['n_rows']:,} synthetic rows over {len(COLUMNS)} column{'s' if len(COLUMNS) != 1 else ''} from "
f"{len(train_rows):,} training rows{model_note}."
)
if not np.isnan(values["fidelity_ks_mean"]):
summary += f" Numeric columns differ from the data by a mean Kolmogorov–Smirnov distance of {values['fidelity_ks_mean']:.3f}"
summary += f" and categories by a mean total variation of {values['fidelity_tv_mean']:.3f}." if not np.isnan(values["fidelity_tv_mean"]) else "."
elif not np.isnan(values["fidelity_tv_mean"]):
summary += f" Categories differ from the data by a mean total variation of {values['fidelity_tv_mean']:.3f}."
if values["exact_matches"]:
summary += f" {values['exact_matches']:,} synthetic row{'s are' if values['exact_matches'] != 1 else ' is'} identical to a training row."
sy.publish(
"Synthetic data — Gaussian copula",
cs.engine_info("scipy", "pyarrow", "numpy", "pyarrow"),
summary, values, table, charts, warnings,
[{"key": "synthetic", "path": path, "format": "parquet", "title": "Synthetic rows"},
{"key": "split", "path": split, "format": "parquet", "title": "Training and holdout rows"}],
{"kind": "generator", "columns": COLUMNS, "params": {
"n_rows": None,
"marginal": "interpolated",
"missing": "keep_rate",
"holdout": 0.2,
}},
extra_tables,
)
How a copula builds a row
ReadA Gaussian copulaGaussian copulaKeeps each column's own distribution and ties the columns together with the correlations of a multivariate normal. separates two things: each column's own shape, and how the columns move together.
- Turn each column into normal scores, through its ranks.
- Learn the correlations among those scores.
- Draw new scores from a multivariate normal with those correlations.
- Map each score back through that column's own quantiles.
Skew and odd shapes survive step 4, because each column keeps its own quantiles. Categories come from their observed shares. Draws come from the shared random stream, so Python and R produce the same rows.
Will it copy anyone?
PredictPredict first
With its default settings, the copula interpolates new values between observed ones. Of the rows it drew, how many will match a training row in every column?
Make your guess between 0 and 320 rows, then reveal.
Reveal
0 of 320. Now switch to observed values only, on four columns: 13 of 250 rows are exact copies. Settings and the number of columns both change this, so you measure it every time.
See the trade-off
ExploreTry three generators here: noisy copies, one bell-shaped cloud, and shuffled columns.
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 two outputs as you go. The largest column KS asks whether the columns match, and the privacy ratio asks whether synthetic rows sit closer to the training data than new real rows would. Press copy the rows and see what perfect fidelity costs.
Three questions
ReadThe studio's Scorecard tab answers three questions, using rows the generator never saw:
| Question | Scores |
|---|---|
| Fidelity: does it look like the data? | Columns, pairs, a real-or-synthetic classifier |
| Privacy: does it sit too close to real rows? | Distance to closest record, exact copies |
| Utility: can it do the job? | A model trained on it, tested on real rows |
Then it gives a verdict for your purpose. Treat the verdict as a summary of these scores, and read the scores yourself.
Check your understanding
CheckpointCheck yourself
A skewed income column goes through a Gaussian copula. What does the synthetic column look like?
Show the answer
Answer: a
The normal distribution only carries the dependence between columns. Each column's shape comes back in the final step.
Check yourself
Why does the generator keep a share of rows out of training?
Show the answer
Answer: b
Without unseen rows, you can't tell "close to the training data" from "close to data like this in general". With the holdout set to zero, privacy is not measured.
Check yourself
A colleague says, "It's synthetic, so it's anonymous." What's the right response?
Show the answer
Answer: b
Synthetic rows can sit very close to real people, and in the worst case copy them. You measure this for each table.
Do it on your own data
In the appRun a copula on a table you know, and press Generate. The code below shows the idea on three numeric columns. Its rows won't match the app's, because the app handles categories and missing values and draws from the shared random stream.
import numpy as np
import pandas as pd
from scipy import stats
df = pd.read_csv("customers.csv")[["age", "visits", "tenure_months"]].dropna()
n = len(df)
rng = np.random.default_rng(1)
z = stats.norm.ppf(df.rank() / (n + 1))
corr = np.corrcoef(z, rowvar=False)
new_z = rng.multivariate_normal(np.zeros(df.shape[1]), corr, size=n)
u = stats.norm.cdf(new_z)
synth = pd.DataFrame({c: np.quantile(df[c], u[:, j]) for j, c in enumerate(df.columns)})
print(synth.describe().round(2))df <- na.omit(read.csv("customers.csv")[, c("age", "visits", "tenure_months")])
n <- nrow(df)
set.seed(1)
z <- apply(df, 2, function(x) qnorm(rank(x) / (n + 1)))
new_z <- MASS::mvrnorm(n, rep(0, ncol(df)), cor(z))
u <- pnorm(new_z)
synth <- as.data.frame(lapply(seq_along(df), function(j) quantile(df[[j]], u[, j], names = FALSE)))
names(synth) <- names(df)
summary(synth)Recap
Recap- A generator learns a table's patterns and draws new rows from them.
- A Gaussian copula keeps each column's shape and ties the columns together with correlations.
- Your purpose decides which score matters: privacy, utility or column shapes.
- Being synthetic doesn't make a table private. You measure that.
Concepts in this lesson