Data Science Probability Distributions
Connect a probability calculation to an explicit model.
How it works
A probability distribution assigns probabilities to possible outcomes. A binomial model assumes a fixed number of trials, the same success probability and independent trials. Those assumptions may be inappropriate if visitors arrive in groups or conditions change during the day. Start with a small case that can be checked by multiplication before trusting a library call on a complex model.
Run the code
Try in playground opens the correct scipy editor and preloads the complete source. Choose Run to execute; loading does not execute it. The isolated browser runtime does not read personal PC files.
Local review: Python 3.12.14, NumPy 2.5.4, Pandas 3.0.6 and SciPy 1.18.0. Browser review: Pyodide 0.27.7, Python 3.12.7, NumPy 2.0.2, Pandas 2.2.3 and SciPy 1.14.1 in their respective editors. Save the download as probability-distributions.py and run python probability-distributions.py in your separate environment. Apache and MySQL are not needed. Environment setup.
Example
from scipy import stats
probability = stats.binom.pmf(2, n=3, p=0.5)
assert abs(probability - 3/8) < 1e-12
assert abs(stats.binom.pmf([0,1,2,3], 3, .5).sum() - 1) < 1e-12
print(f"Exactly two successes in three fair trials: {probability:.3f}")
Expected result
Exactly two successes in three fair trials: 0.375
There are three arrangements with two successes, each having probability one eighth under the stated model. Summing all four possible counts checks the probability mass. This verifies a mathematical calculation, not whether kiosk visitors satisfy independent-trial assumptions. A domain model needs collection evidence as well as a correct function call.
Technical references: NumPy, Pandas and SciPy. For evaluation design see the scikit-learn guide to leakage; these examples do not require scikit-learn.