Skip to content

Evaluation, diagnostics, benchmarks, and additional tests · Evaluation, diagnostics, benchmarks, and additional hypothesis tests · EVA019 · Hypothesis test

Classifier two-sample test

Uses held-out discrimination between samples as evidence that their distributions differ.

Partly runs in CodeSplash Complete calculation CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method covers part of this entry; some options or variants aren't built yet.

Do it in CodeSplash Run it on your own data, in Python or R.

Availability
Partly runs in CodeSplash
Code example
Complete calculation
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
Verified in Python and R through multivariate.distribution_test. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Uses held-out discrimination between samples as evidence that their distributions differ.

Question / hypotheses

H0: P=Q. Under the independent equal-prior random-label design specified below, a separately fitted classifier has chance accuracy under the null.

Architecture / computational structure

Fit a discriminator on a training split, freeze its features and decision rule, and count correct origin predictions on a separate test split. Independent equal-prior random origins yield the stated binomial null; a fixed class-count design instead uses a suitable conditional permutation reference.

Assumptions

Training, tuning, and scoring must be separated. The displayed exact binomial calibration applies when each held-out origin label is independently Bernoulli(1/2), with its feature drawn from the corresponding distribution, and the classifier was fitted independently. Under H0 the labels are then independent of the features. Forcing exactly equal class counts is a different conditional design and does not generally produce a binomial correctness count; use a justified fixed-count label permutation instead.

Formula / computational definition

T=1ntest∑i1{f(xi)=yi};p=Pr⁡{Binom⁡(ntest,1/2)≥ntestT}.T=\frac1{n_{test}}\sum_i\mathbf1\{f(x_i)=y_i\};\quad p=\Pr\{\operatorname{Binom}(n_{test},1/2)\ge n_{test}T\}.

Parameters and notation

f is a trained classifier; architecture, regularization, split, and metric are hyperparameters. Equal class probability is not the same as a forced equal realized count. With an independent frozen discriminator, permute only held-out labels under the applicable exchangeability design; if training or tuning is part of the statistic being randomized, rerun those operations for every permutation.

Fitting, fine-tuning, and adaptation

Classifier weights are fitted nuisance machinery for the test. Tune capacity, regularization, and threshold on training/development data only. If the classifier is held fixed, test-label permutations need not retrain it; if the statistic includes fitting on the permuted data, rerun that fitting. Combining split results requires a prespecified valid aggregation, not the smallest p-value.

How to use and calibrate

Label real/generated origins, split before preprocessing, train a discriminator, and score untouched cases. Repeat complete experiments for robustness without selecting the most favorable split.

Example application

Ask whether a simple classifier can distinguish independent real and synthetic tabular records.

Interpretation / pitfalls

Watch out

Weak discrimination can reflect a weak classifier, not equality. Test-set tuning invalidates nominal significance. Near duplicates across splits can produce misleadingly easy discrimination.

Python and R code examples

Scope: Mathematical calculation on synthetic inputs; not a complete benchmark pipeline.

Validation: Python — Executed successfully on synthetic inputs. R — reviewed but not executed in this environment. Python dependencies are explicit imports; R uses base R unless a package/bridge is explicitly named.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Complete calculation — Mathematical calculation on synthetic inputs; not a complete benchmark pipeline. · needs scipy

from scipy.stats import binomtest
print(binomtest(68,100,.5,alternative="greater").pvalue)
# 68/100 correct: independently sampled Bernoulli(1/2) held-out origins,
# not a test set constrained to contain exactly 50 examples per origin.
R

Complete calculation — Mathematical calculation on synthetic inputs; not a complete benchmark pipeline.

print(binom.test(68,100,p=.5,alternative="greater")$p.value)

Sources

From the CodeSplash reference, entry EVA019.