Skip to content
svgdcr-histogram

Distance to closest record

Are synthetic rows suspiciously close to (copies of) real training rows?

Demo data · seed 20261101 · 3,000 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Read one histogram as synthetic rows' distance to their nearest training row.
  2. Read the other as held-out real rows' distance to training.
  3. Synthetic should not be closer: closer suggests copying.
  1. Callout 1: Distances near zero would suggest copies.
  2. Callout 2: The median distances to compare.

Watch out

  • Passing this check isn't a privacy guarantee: it tests only one kind of leak.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Draws the run's numbers as given (computed by the Python/R engine or the host's scorecard); the chart computes nothing statistical.
  • Both histograms share edges over the joint range; dashed lines are medians. Privacy rule of thumb: the synthetic→train distribution should not sit left of holdout→train (the 5th percentiles are in the scorecard), and exact copies (distance 0) should be absent.
# Distance to closest record — Codesplash Chart Lab (recipe "dcr-histogram")
# controls: defaults
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("dcr-histogram-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["pair"] = pd.Categorical(df["pair"].astype("string"), categories=["synthetic → train", "holdout → train"])

def levels_of(s):
    """Declared level order (categoricals), else order of first appearance."""
    if isinstance(s.dtype, pd.CategoricalDtype):
        return [v for v in s.cat.categories if (s == v).any()]
    return list(dict.fromkeys(s.dropna().astype(str)))
D = "Gower distance"
P = "pair"
pairs = levels_of(df[P])
edges = np.linspace(df[D].min(), df[D].max(), 31)  # shared edges
fig, ax = plt.subplots(figsize=(8, 4.5))
for i, p in enumerate(pairs):
    v = df.loc[df[P].astype(str) == str(p), D].dropna()
    ax.hist(v, bins=edges, weights=np.full(len(v), 1 / len(v)), histtype="stepfilled", alpha=0.28, color=PALETTE[i], edgecolor=PALETTE[i], linewidth=1.5, label=f"{p} · median {v.median():.3f}")
    ax.axvline(v.median(), color=PALETTE[i], linestyle="--", linewidth=1)
ax.set_xlabel(D)
ax.set_ylabel("share of rows")
ax.legend(fontsize=8)
plt.show()

Needs pandas, numpy, matplotlib · reads dcr-histogram-demo.csv · app theme from the optional codesplash helper