Skip to content

ASynthetic data · synth.cart

Synthetic data — sequential CART

Can I generate rows that keep the interactions and odd shapes of this table, column by column?

Synthesizes the columns one at a time in the order you list them (the synthpop "cart" method): the first column is resampled from its values, and each later column is predicted from the columns before it by a classification or regression tree; every synthetic row then takes the value of a real row that falls in the same leaf. Trees capture interactions and non-linear relations that a copula misses, but values are copied from the data, so check the privacy scorecard. A share of rows is held out of training for privacy and utility checks; draws come from the shared random stream, so Python and R grow the same trees and pick the same donors.

Verified in Python and R Python and R agree to 10 decimals Seeded

A real result

Example “Customers all”, recorded in both engines. In the app, “Try this example” loads it into Analyze.

Synthetic data — sequential CARTRecorded · Python and R agreeRecorded 2026-11-17 · 53 values compared · largest relative difference 2.5e-15
R

320 synthetic rows over 8 columns from 320 training rows with sequential classification and regression trees. Numeric columns differ from the data by a mean Kolmogorov–Smirnov distance of 0.051 and categories by a mean total variation of 0.042.

Synthetic rows
320
Mean KS distance
0.0511
Mean TV distance
0.0424
Rows copied from the data
0

Plots

age: real vs syntheticDoes the synthetic data reproduce the shape of a numeric column?
View data
DensitySourceage
0.0230real18.950
0.0016real20.850
0.0049real22.750
0.0148real24.650
0.0148real26.550
0.0181real28.450
0.0197real30.350
0.0296real32.250
0.0362real34.150
0.0115real36.050
0.0362real37.950
0.0313real39.850
0.0296real41.750
0.0280real43.650
0.0280real45.550
0.0181real47.450
0.0164real49.350
0.0197real51.250
0.0362real53.150
0.0148real55.050
0.0164real56.950
0.0181real58.850
0.0082real60.750
0.0164real62.650
0.0049real64.550
0.0115real66.450
0.0066real68.350
0.0049real70.250
0.0016real72.150
0.0049real74.050
0.0164synthetic18.950
0.0049synthetic20.850
0.0082synthetic22.750
0.0132synthetic24.650
0.0066synthetic26.550
0.0280synthetic28.450
0.0247synthetic30.350
0.0263synthetic32.250
0.0214synthetic34.150
0.0132synthetic36.050
0.0296synthetic37.950
0.0247synthetic39.850
0.0395synthetic41.750
0.0395synthetic43.650
0.0296synthetic45.550
0.0115synthetic47.450
0.0230synthetic49.350
0.0132synthetic51.250
0.0345synthetic53.150
0.0214synthetic55.050
0.0115synthetic56.950
0.0132synthetic58.850
0.0115synthetic60.750
0.0181synthetic62.650
0.0148synthetic64.550
0.0066synthetic66.450
0.0049synthetic68.350
0.0082synthetic70.250
0.0033synthetic72.150
0.0049synthetic74.050
annual income: real vs syntheticDoes the synthetic data reproduce the shape of a numeric column?
View data
DensitySourceannual income
3.010e-6real6851.93
1.605e-5real10141.74
2.107e-5real13431.55
2.408e-5real16721.36
3.511e-5real20011.17
4.113e-5real23300.98
2.809e-5real26590.79
2.408e-5real29880.60
2.508e-5real33170.41
1.605e-5real36460.22
1.605e-5real39750.03
1.505e-5real43039.84
1.003e-5real46329.65
5.016e-6real49619.46
6.019e-6real52909.27
4.013e-6real56199.07
4.013e-6real59488.88
4.013e-6real62778.69
1.003e-6real66068.50
1.003e-6real69358.31
1.003e-6real72648.12
0real75937.93
1.003e-6real79227.74
1.003e-6real82517.55
0real85807.36
0real89097.17
0real92386.98
0real95676.79
0real98966.60
1.003e-6real102256.41
8.133e-6synthetic6851.93
1.423e-5synthetic10141.74
2.135e-5synthetic13431.55
3.457e-5synthetic16721.36
3.355e-5synthetic20011.17
3.152e-5synthetic23300.98
3.253e-5synthetic26590.79
1.932e-5synthetic29880.60
3.253e-5synthetic33170.41
1.830e-5synthetic36460.22
1.423e-5synthetic39750.03
1.017e-5synthetic43039.84
1.220e-5synthetic46329.65
4.066e-6synthetic49619.46
1.017e-6synthetic52909.27
3.050e-6synthetic56199.07
4.066e-6synthetic59488.88
3.050e-6synthetic62778.69
1.017e-6synthetic66068.50
1.017e-6synthetic69358.31
2.033e-6synthetic72648.12
0synthetic75937.93
0synthetic79227.74
1.017e-6synthetic82517.55
0synthetic85807.36
0synthetic89097.17
0synthetic92386.98
0synthetic95676.79
0synthetic98966.60
1.017e-6synthetic102256.41
tenure_months: real vs syntheticDoes the synthetic data reproduce the shape of a numeric column?
View data
DensitySourcetenure_months
0.0938real0.7667
0.0224real2.300
0.0183real3.833
0.0306real5.367
0.0204real6.900
0.0265real8.433
0.0204real9.967
0.0530real11.500
0.0183real13.033
0.0510real14.567
0.0183real16.100
0.0367real17.633
0.0224real19.167
0.0448real20.700
0.0469real22.233
0.0082real23.767
0.0306real25.300
0.0061real26.833
0.0183real28.367
0.0041real29.900
0.0143real31.433
0.0061real32.967
0.0183real34.500
0.0020real36.033
0.0041real37.567
0real39.100
0.0061real40.633
0.0041real42.167
0.0020real43.700
0.0041real45.233
0.0917synthetic0.7667
0.0061synthetic2.300
0.0143synthetic3.833
0.0306synthetic5.367
0.0265synthetic6.900
0.0346synthetic8.433
0.0183synthetic9.967
0.0428synthetic11.500
0.0204synthetic13.033
0.0448synthetic14.567
0.0245synthetic16.100
0.0367synthetic17.633
0.0204synthetic19.167
0.0510synthetic20.700
0.0510synthetic22.233
0.0122synthetic23.767
0.0326synthetic25.300
0.0061synthetic26.833
0.0224synthetic28.367
0.0102synthetic29.900
0.0143synthetic31.433
0.0041synthetic32.967
0.0143synthetic34.500
0.0041synthetic36.033
0.0020synthetic37.567
0synthetic39.100
0.0020synthetic40.633
0.0061synthetic42.167
0.0020synthetic43.700
0.0061synthetic45.233
signup: real vs syntheticDoes the synthetic data reproduce the shape of a numeric column?
View data
DensitySourcesignup
0.0005real17582.23
0.0007real17654.70
0.0005real17727.17
0.0005real17799.63
0.0004real17872.10
0.0005real17944.57
0.0006real18017.03
0.0004real18089.50
0.0005real18161.97
0.0005real18234.43
0.0001real18306.90
0.0009real18379.37
0.0006real18451.83
0.0003real18524.30
0.0005real18596.77
0.0004real18669.23
0.0002real18741.70
0.0005real18814.17
0.0006real18886.63
0.0005real18959.10
0.0005real19031.57
0.0005real19104.03
0.0003real19176.50
0.0006real19248.97
0.0004real19321.43
0.0003real19393.90
0.0002real19466.37
0.0005real19538.83
0.0003real19611.30
0.0004real19683.77
0.0002synthetic17582.23
0.0004synthetic17654.70
0.0006synthetic17727.17
0.0006synthetic17799.63
0.0004synthetic17872.10
0.0006synthetic17944.57
0.0007synthetic18017.03
8.625e-5synthetic18089.50
0.0010synthetic18161.97
0.0006synthetic18234.43
0.0003synthetic18306.90
0.0009synthetic18379.37
0.0008synthetic18451.83
0.0003synthetic18524.30
0.0003synthetic18596.77
0.0003synthetic18669.23
0.0001synthetic18741.70
0.0004synthetic18814.17
0.0005synthetic18886.63
0.0006synthetic18959.10
0.0005synthetic19031.57
0.0002synthetic19104.03
0.0004synthetic19176.50
0.0007synthetic19248.97
0.0005synthetic19321.43
0.0004synthetic19393.90
0.0001synthetic19466.37
0.0005synthetic19538.83
0.0003synthetic19611.30
0.0003synthetic19683.77
region: real vs syntheticDoes the synthetic data keep the category proportions of the real data?
View data
regionShareSource
east0.2848real
north0.2718real
south0.3042real
west0.1392real
east0.3151synthetic
north0.2637synthetic
south0.2958synthetic
west0.1254synthetic
plan: real vs syntheticDoes the synthetic data keep the category proportions of the real data?
View data
planShareSource
basic0.3563real
plus0.3969real
premium0.2469real
basic0.4281synthetic
plus0.3688synthetic
premium0.2031synthetic
churned: real vs syntheticDoes the synthetic data keep the category proportions of the real data?
View data
churnedShareSource
false0.7688real
true0.2313real
false0.7438synthetic
true0.2562synthetic
Correlation difference (real − synthetic)What do the values of a square or rectangular result matrix look like at a glance?
View data
ColumnColumnDifference
ageage0
annual incomeage−0.0433
tenure_monthsage−0.0104
signupage−0.0279
visitsage0.0164
ageannual income−0.0433
annual incomeannual income0
tenure_monthsannual income0.0559
signupannual income0.0337
visitsannual income0.0579
agetenure_months−0.0104
annual incometenure_months0.0559
tenure_monthstenure_months0
signuptenure_months−0.0118
visitstenure_months0.1094
agesignup−0.0279
annual incomesignup0.0337
tenure_monthssignup−0.0118
signupsignup0
visitssignup0.0628
agevisits0.0164
annual incomevisits0.0579
tenure_monthsvisits0.1094
signupvisits0.0628
visitsvisits0

Real vs synthetic, column by column

ColumnKindRealSyntheticDistanceMeasure
agenumeric43.14 ± 13.143.84 ± 13.20.0531Kolmogorov–Smirnov D
regioncategoricalsouth 30.4%south 29.6%0.0303total variation
plancategoricalplus 39.7%plus 36.9%0.0719total variation
annual incomenumeric2.929e+04 ± 1.43e+042.81e+04 ± 1.4e+040.0615Kolmogorov–Smirnov D
tenure_monthsnumeric15 ± 10.715.59 ± 10.60.0375Kolmogorov–Smirnov D
churnedbooleanfalse 76.9%false 74.4%0.0250total variation
signuptemporal2020-11-05 ± 621 days2020-11-10 ± 604 days0.0469Kolmogorov–Smirnov D
visitsnumeric3.394 ± 2.093.2 ± 2.130.0563Kolmogorov–Smirnov D

Trees (synthesis order)

StepColumnDrawn by
1ageresampling its values
2regiona tree on the 1 column before it (36 leaves)
3plana tree on the 2 columns before it (46 leaves)
4annual incomea tree on the 3 columns before it (48 leaves)
5tenure_monthsa tree on the 4 columns before it (46 leaves)
6churneda tree on the 5 columns before it (35 leaves)
7signupa tree on the 6 columns before it (47 leaves)
8visitsa tree on the 7 columns before it (46 leaves)
  • 80 of 400 rows (20%) were held out of training so privacy and utility can be checked against rows the generator never saw.
Python

320 synthetic rows over 8 columns from 320 training rows with sequential classification and regression trees. Numeric columns differ from the data by a mean Kolmogorov–Smirnov distance of 0.051 and categories by a mean total variation of 0.042.

Synthetic rows
320
Mean KS distance
0.0511
Mean TV distance
0.0424
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

ColumnKindRealSyntheticDistanceMeasure
agenumeric43.14 ± 13.143.84 ± 13.20.0531Kolmogorov–Smirnov D
regioncategoricalsouth 30.4%south 29.6%0.0303total variation
plancategoricalplus 39.7%plus 36.9%0.0719total variation
annual incomenumeric2.929e+04 ± 1.43e+042.81e+04 ± 1.4e+040.0615Kolmogorov–Smirnov D
tenure_monthsnumeric15 ± 10.715.59 ± 10.60.0375Kolmogorov–Smirnov D
churnedbooleanfalse 76.9%false 74.4%0.0250total variation
signuptemporal2020-11-05 ± 621 days2020-11-10 ± 604 days0.0469Kolmogorov–Smirnov D
visitsnumeric3.394 ± 2.093.2 ± 2.130.0563Kolmogorov–Smirnov D

Trees (synthesis order)

StepColumnDrawn by
1ageresampling its values
2regiona tree on the 1 column before it (36 leaves)
3plana tree on the 2 columns before it (46 leaves)
4annual incomea tree on the 3 columns before it (48 leaves)
5tenure_monthsa tree on the 4 columns before it (46 leaves)
6churneda tree on the 5 columns before it (35 leaves)
7signupa tree on the 6 columns before it (47 leaves)
8visitsa tree on the 7 columns before it (46 leaves)
  • 80 of 400 rows (20%) were held out of training so privacy and utility can be checked against rows the generator never saw.

Do it in CodeSplash Run it on your own data, in Python or R, with the code to prove it.

Worked examples in the app

  • Customers allg1_customers · columns: age, region, plan, annual income, tenure_months, churned, signup, visits
  • Customers small leavesg1_customers · columns: plan, churned, annual income, visits
  • Penguinsml_penguins · columns: species, island, sex, bill_len, flipper_len, body_mass
  • Degenerate all nag1_customers · columns: age, region, plan, annual income, tenure_months, churned, signup, visits
  • Degenerate n2g1_customers · columns: age, region, plan, annual income, tenure_months, churned, signup, visits
  • Degenerate infg1_customers · columns: age, region, plan, annual income, tenure_months, churned, signup, visits

In the guides

Where it sits in the decision guides

  • Generative models (GMM, VAEs) · DS & ML Decision Guide · Generate
  • Generate: quality (human or automated); relevance, safety, bias; task-specific metrics (BLEU, ROUGE, LLM-as-judge) · DS & ML Decision Guide · How to evaluate — common metrics by question type

What you need

Columns (in synthesis order)numeric / categorical / boolean / temporal · 1–60 columns
The order matters — put the variables others depend on first (e.g. age, region before income). Leave out direct identifiers.

Choices you make

options

Synthetic rowsdefault —

How many synthetic rows to generate. Leave empty to match the number of real rows.

Missing valuesdefault keep_rate

Whether synthetic data keeps each column's share of missing values (placed at random).

  • Keep each column's missing share (at random)(default) — Blanks synthetic values at each column's real missing share, at random; keeps the data's gaps in overall rate.
  • No missing values — Produces complete synthetic data with no gaps; pick it when downstream tools can't handle missing values.

model

Rows per leaf (minimum)default 5

Larger leaves pool more donors (more privacy, smoother data); smaller leaves follow the data more closely.

Advanced

Maximum tree depthdefault —

Deepest each synthesizing tree may grow. Empty lets trees grow until leaves are small (closer to the real data).

validation

Holdout for privacy and utility checksdefault 0.2

Share of rows kept out of training. The scorecard compares synthetic rows with these unseen rows.

What it reports

n_rows
How many independent units the analysis used; it sets precision and power.
n_real
How many independent units the analysis used; it sets precision and power.
n_input
How many independent units the analysis used; it sets precision and power.
n_holdout
How many independent units the analysis used; it sets precision and power.
n_columns
How many independent units the analysis used; it sets precision and power.
exact_matches
How far a row sits from its nearest training row; synthetic rows should sit no closer than real rows the generator never saw.
fidelity_ks_mean
How closely synthetic rows match the real ones, column by column, in pairs, and as whole rows.
fidelity_tv_mean
How closely synthetic rows match the real ones, column by column, in pairs, and as whole rows.

Per group, level or term: mean[<column>], sd[<column>], wmean[<column>], share[<column>=<level>], wcode[<column>], missing[<column>], ks[<column>], tv[<column>], leaves[<column>], corr_mad

Python and R

Python and R agree to 10 decimals (relative tolerance 1e-12). Python uses numpy, pyarrow; R uses nanoparquet.

Default traps between the two languages

  • Both engines run the codesplash twin (codesplash.synth.cart ↔ codesplashr::cs_synth_cart) built on the Phase 6 CART twin, which grows identical trees; synthetic values are copied from donor rows chosen by shared-stream uniforms, so the tables are identical.
  • synthpop::syn(method = "cart") is the classic R equivalent: it uses rpart (categorical splits by level subsets, cp = 1e-8, minbucket = 5) and R's own random numbers, so its rows differ.
Python

The exact script CodeSplash ran for example “Customers all” · Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0

# Synthetic data — sequential CART
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method synth.cart 1.0.2 · spec 1d9728a4b0fe66db
# 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 cart

# %% Data
COLUMNS = ["age", "region", "plan", "annual income", "tenure_months", "churned", "signup", "visits"]
KINDS = {
    "age": "numeric",
    "region": "categorical",
    "plan": "categorical",
    "annual income": "numeric",
    "tenure_months": "numeric",
    "churned": "boolean",
    "signup": "temporal",
    "visits": "numeric",
}
LEVELS = {
    "region": ["east", "north", "south", "west"],
    "plan": ["basic", "plus", "premium"],
}
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
# Sequential CART (twin: codesplashr::cs_synth_cart; classic equivalent: synthpop::syn(method = "cart")).
# Columns in the order listed; each later column is drawn from donors in its tree's leaf.
synth, leaves = cart.synthesize(train, N_OUT, rng, min_leaf=5, max_depth=None)
for name, n_leaves in zip(COLUMNS[1:], leaves):
    fit_values[f"leaves[{name}]"] = n_leaves
model_note = " with sequential classification and regression trees"
extra_tables.append({
    "key": "trees",
    "title": "Trees (synthesis order)",
    "columns": [{"key": "step", "label": "Step", "type": "integer"}, {"key": "column", "label": "Column", "type": "string"},
                {"key": "how", "label": "Drawn by", "type": "string"}],
    "rows": [{"step": 1, "column": COLUMNS[0], "how": "resampling its values"}]
    + [{"step": i + 2, "column": c, "how": f"a tree on the {i + 1} column{'s' if i else ''} before it ({n} leaves)"} for i, (c, n) in enumerate(zip(COLUMNS[1:], leaves))],
})
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-953/synth.cart/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 — sequential CART",
    cs.engine_info("numpy", "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,
        "min_leaf": 5,
        "max_depth": None,
        "missing": "keep_rate",
        "holdout": 0.2,
    }},
    extra_tables,
)
R

The exact script CodeSplash ran for example “Customers all” · R version 4.5.1 (2025-06-13)

# Synthetic data — sequential CART
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method synth.cart 1.0.2 · spec 1d9728a4b0fe66db
# 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", "region", "plan", "annual income", "tenure_months", "churned", "signup", "visits")
KINDS <- list(
  age = "numeric",
  region = "categorical",
  plan = "categorical",
  `annual income` = "numeric",
  tenure_months = "numeric",
  churned = "boolean",
  signup = "temporal",
  visits = "numeric"
)
LEVELS <- list(
  region = c("east", "north", "south", "west"),
  plan = c("basic", "plus", "premium")
)
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
# Sequential CART (twin: codesplash.synth.cart; classic equivalent: synthpop::syn(method = "cart")).
# Columns in the order listed; each later column is drawn from donors in its tree's leaf.
fit <- cs_synth_cart(train, N_OUT, rng, min_leaf = 5L, max_depth = NULL)
synth <- fit$cols
for (j in seq_along(fit$leaves)) fit_values[[sprintf("leaves[%s]", COLUMNS[j + 1L])]] <- fit$leaves[j]
model_note <- " with sequential classification and regression trees"
trows <- list(list(step = 1L, column = COLUMNS[1], how = "resampling its values"))
for (j in seq_along(fit$leaves)) {
  trows[[j + 1L]] <- list(step = j + 1L, column = COLUMNS[j + 1L],
                          how = sprintf("a tree on the %d column%s before it (%d leaves)", j, if (j > 1L) "s" else "", fit$leaves[j]))
}
extra_tables <- list(list(
  key = "trees", title = "Trees (synthesis order)",
  columns = list(list(key = "step", label = "Step", type = "integer"), list(key = "column", label = "Column", type = "string"),
                 list(key = "how", label = "Drawn by", type = "string")),
  rows = trows))
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-953/synth.cart/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 — sequential CART",
  cs_engine_info("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,
    min_leaf = 5,
    max_depth = NULL,
    missing = "keep_rate",
    holdout = 0.2
  )),
  extra_tables
)

Sources

  • Reiter JP (2005). Using CART to generate partially synthetic public use microdata. Journal of Official Statistics 21:441–462.
  • Nowok B, Raab GM, Dibben C (2016). synthpop: bespoke creation of synthetic data in R. Journal of Statistical Software 74(11).
  • Breiman L, Friedman JH, Olshen RA, Stone CJ (1984). Classification and Regression Trees. Wadsworth.

From the CodeSplash method registry · synth.cart v1.0.2.