← All Base Form Math projects
BM-24NOT STARTEDBASE FORM · PROBABILITYMATHPYTHON

Fake-data generator

Generate realistic fake data from any distribution you choose using inverse-CDF sampling, and prove it matches.

EST.6 h
REWARD+100 XP
AFTERoriginal

ML-ARENA BENCHMARKS

YOUR NUMBER VS THE INDUSTRY'S
METRICINDUSTRYMINE
goodness of fit
GOAL · pass KS at 5% for 10 distributions
scipy.stats (KS test)—
no results yet
YOUR RESULTS

Your recorded results appear here.

Brief

Fake data is useful everywhere: for tests, for demos, and for checking that a method recovers what you put in. The trick behind most random generators is short. If UU is uniform on [0,1][0, 1] and FF is the CDF of the distribution you want, then X=F−1(U)X = F^{-1}(U) has exactly that distribution. This is inverse-CDF sampling, and in this project you build a generator for ten distributions with it.

A distribution is described by its PDF f(x)f(x) or its CDF F(x)=∫−∞xf(t) dtF(x) = \int_{-\infty}^{x} f(t)\,dt. For the exponential with rate λ\lambda, F(x)=1−e−λxF(x) = 1 - e^{-\lambda x}, so F−1(u)=−ln⁡(1−u)/λF^{-1}(u) = -\ln(1-u)/\lambda. When there is no formula for F−1F^{-1}, as for the normal, you integrate the PDF numerically and invert the table.

To prove a sampler works, compare its samples with the target. The Kolmogorov–Smirnov (KS) test measures the largest gap between the empirical CDF FnF_n of your samples and the true one: D=max⁡x∣Fn(x)−F(x)∣D = \max_x \lvert F_n(x) - F(x) \rvert. A small DD gives a large p-value. Keep in mind that a correct sampler still fails the test 5% of the time at the 5% level. That is what the level means. You will also check the expectation E[X]E[X] and variance against their formulas and watch the central limit theorem appear.

VISUALFig. 1
0 1 2 3 4 0 0.5 1 x u = F(x) = 1 − e^(−x) x = 0.22 u = 0.2 x = 0.69 u = 0.5 x = 1.61 u = 0.8 x = 3.00 u = 0.95
Inverse-CDF sampling for an exponential. Pick u on the vertical axis, go across to the curve, then down to x. Evenly spaced u values bunch up near 0, just like the exponential. Why it's here: The whole project is this one picture applied ten times.
HINT · OBJECTIVE 3
Stuck? Hints stay hidden until you ask.
HINT · OBJECTIVE 4
Stuck? Hints stay hidden until you ask.

DATA · none needed

Objectives

0 / 6 CLEARED

Read-only. Log in to update progress.

VICTORY CONDITIONS

  1. All 10 samplers pass scipy.stats.kstest at the 5% level (p above 0.05) with 10,000 samples and a fixed seed. Record the count with `python tools/mlarena.py record BM-24 "<passed>/10"`.
  2. Your KS statistic D matches scipy's within 1e-12 for every distribution.
  3. Over 200 different seeds, about 5% of runs fail at the 5% level, as they should for a correct sampler.

Side quests

Add discrete distributions (Poisson, geometric) by searching the cumulative sum, and test them with a chi-square test, since KS assumes a continuous CDF.
Time Box–Muller against your numerical inverse for the normal.
Build a fake customer table where age, income and purchase count each come from a sensible distribution.

Terms in plain words

PDF
The probability density function f(x). The area under it between a and b is the chance a value lands between a and b.
CDF
The cumulative distribution function F(x), the chance a value is at most x. It rises from 0 to 1 and is the integral of the PDF.
Expectation
The long-run average of a random variable, the sum (or integral) of each value times its probability.
Variance
The expected squared distance from the mean. Its square root, the standard deviation, measures the typical spread.
Central limit theorem
The average of many independent draws is close to normally distributed, whatever the original distribution, as long as its variance is finite.