Module 3 · Beginner · Distributions

Common distributions in data science

Six distributions every data scientist meets: uniform, binomial, Poisson, exponential, normal and log-normal, the story behind each and where ML uses it.

By theprogrammers team · · 11 min read

A shop gets on average 3 UPI payments a minute. How often does it get 6 or more in one minute? A call centre's customers arrive at random. How long will the next gap between calls be? A cricketer converts 30% of chances. How many of the next 10 will they take? These sound like three different problems, but each is answered by a named distribution: a shape that comes from a particular kind of story.

There are dozens of named distributions, but six cover most of data science. Don't memorise their formulas. Learn the story behind each one: what process produces it. Then, when you meet new data, you can ask "what story made this?" and know what shape to expect, which summaries to trust, and which model or loss function fits.

What you need first: what is a distribution?, the normal distribution explained and skewed data and log transforms.

Key terms

  • Parameter: a number that sets a distribution's exact shape, such as the mean and SD of a normal distribution.
  • Trial: one attempt with two possible outcomes, such as a shot that goes in or misses.
  • Rate: how many events happen per unit of time on average, such as 3 payments a minute.
  • Random variable: a quantity whose value depends on chance, such as the number of payments next minute.
  • scipy.stats: SciPy's module with every common distribution, each with pmf/pdf, cdf and random sampling.

The six at a glance

All six, simulated with 10,000 values each. Each panel's title gives the story; the sections below explain them one at a time.

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy import stats

rng = np.random.default_rng(5)
samples = {
    "Uniform: any value 0–1 equally likely": rng.uniform(0, 1, 10_000),
    "Binomial: successes in 10 tries at 30%": rng.binomial(10, 0.3, 10_000),
    "Poisson: payments a minute, average 3": rng.poisson(3, 10_000),
    "Exponential: minutes between calls, average 2": rng.exponential(2, 10_000),
    "Normal: rice packets, 1,000 g ± 4 g": rng.normal(1000, 4, 10_000),
    "Log-normal: monthly incomes": rng.lognormal(np.log(30_000), 0.6, 10_000),
}

fig, axes = plt.subplots(2, 3, figsize=(13, 6.5))
for ax, (title, data) in zip(axes.ravel(), samples.items()):
    if title.startswith(("Binomial", "Poisson")):
        shares = pd.Series(data).value_counts(normalize=True).sort_index()
        ax.bar(shares.index, shares.values, color="#c2410c")
    else:
        ax.hist(data, bins=40, density=True, color="#d9a05a", edgecolor="white")
    ax.set_title(title, fontsize=10)
    ax.set_yticks([])
plt.tight_layout()
plt.show()
Six panels. Uniform: a flat block from 0 to 1. Binomial: bars from 0 to about 8 successes, peaking at 3. Poisson: bars from 0 to about 10 payments, peaking at 2 and 3, with a right tail. Exponential: highest at 0 minutes and falling steadily, with a long right tail. Normal: a symmetric bell centred on 1,000 g. Log-normal: a hump near 25,000 with a long right tail stretching past 1,00,000.

The binomial and Poisson panels are drawn as bars because they're counts (discrete); the others are continuous, so they're histograms. axes.ravel() turns the 2 × 3 grid of charts into a flat list, so the loop can fill them in order.

Uniform: every value equally likely

Story: a value is picked at random from a range, with no value favoured. A die roll is the discrete version; a random number between 0 and 1 is the continuous one.

Shape: flat. Parameters: the lowest and highest value.

Where it appears: random number generators, shuffling data, choosing random starting points. In machine learning, random search for hyperparameters often draws settings from a uniform range, and some neural network weights start as uniform random numbers.

Binomial: how many successes in a fixed number of tries?

Story: you make n independent tries, each succeeding with the same probability p, and count the successes. Ten penalty kicks by a player who scores 70% of the time. Twenty emails, each spam with probability 0.3.

Shape: bars from 0 to n, peaking near n × p. Parameters: n (tries) and p (chance of success).

A player converts 30% of chances. What's the chance they take 5 or more of the next 10?

print(round(1 - stats.binom.cdf(4, n=10, p=0.3), 3))
print("average successes:", 10 * 0.3)
0.15
average successes: 3.0

binom.cdf(4, ...) is the chance of 4 or fewer successes, so one minus it is the chance of 5 or more: about 15%. On average they'd take 3.

Where it appears: conversion rates, pass rates, the number of correct predictions on a test set. A classifier with 90% accuracy, tested on 200 examples, will get a binomial number right, which is why accuracy on a small test set wobbles. Logistic regression models each example as a single binomial trial (a Bernoulli trial: n = 1).

Poisson: how many events in a fixed time?

Story: events happen independently and at random, at a steady average rate, and you count how many land in a time window. UPI payments a minute, accidents on a road per month, typos per page, website visits per second.

Shape: bars from 0 upwards, peaking near the rate, with a right tail. Parameter: the rate, usually written λ (lambda), which is both its mean and its variance.

The shop averages 3 payments a minute. How often does it get 6 or more in a minute, and how often none at all?

print("6 or more:", round(1 - stats.poisson.cdf(5, mu=3), 3))
print("none:     ", round(stats.poisson.pmf(0, mu=3), 3))
6 or more: 0.084
none:      0.05

poisson.pmf(0, mu=3) is the probability of exactly 0 events (pmf, the probability mass function, gives the chance of one exact count). About 8% of minutes have 6 or more payments, and 5% have none at all, so a payment system sized for "3 a minute" would be overloaded every few minutes. Systems are sized for the tail, not the average.

Where it appears: forecasting demand, sizing servers and call centres, and modelling counts. Scikit-learn's PoissonRegressor predicts counts, such as the number of claims or orders, and won't predict negative numbers the way plain linear regression can.

Exponential: how long until the next event?

Story: the same random events as Poisson, but now you measure the gap between them. If calls arrive at random at an average of one every 2 minutes, how long until the next call?

Shape: highest at 0 and falling steadily, with a long right tail. Short gaps are most common, but long ones happen. Parameter: the average gap (or its inverse, the rate).

print("gap under 1 minute:", round(stats.expon.cdf(1, scale=2), 3))
print("gap over 5 minutes:", round(1 - stats.expon.cdf(5, scale=2), 3))
gap under 1 minute: 0.393
gap over 5 minutes: 0.082

scale=2 sets the average gap to 2 minutes. About 39% of gaps are under a minute, and about 8% are over 5 minutes.

The exponential has a surprising property: it has no memory. If you've already waited 5 minutes for a call, the chance of waiting at least 2 more is exactly the same as it was at the start. Random arrivals don't "owe" you a call.

Where it appears: waiting times, time between failures of a machine, time until a customer churns, and survival analysis.

Normal: many small effects added together

Story: a value is the sum of many small, independent influences, as the normal distribution showed with dice. Heights, measurement errors, weights of factory-filled packets.

Shape: a symmetric bell. Parameters: the mean and the SD.

Where it appears: almost everywhere: errors of regression models, Gaussian Naive Bayes, weight initialisation, the sampling distribution of averages (you'll see why in the sampling module).

Log-normal: many small effects multiplied together

Story: a value is the product of many small, independent factors, as skewed data and log transforms showed with salary raises. Incomes, house prices, city sizes, time spent on a web page.

Shape: a hump on the left with a long right tail; its log is normal. Parameters: the mean and SD of the log values.

Where it appears: money and sizes. Modelling log(price) instead of price, a standard trick in regression, is assuming price is log-normal.

Matching a story to data

DistributionStoryDiscrete or continuousTypical exampleTypical ML use
UniformEvery value in a range equally likelyEitherRandom number, die rollRandom search, initialisation
BinomialSuccesses in n independent triesDiscretePenalties scored out of 10Accuracy on a test set; logistic regression (one trial)
PoissonCount of random events in a time windowDiscretePayments a minuteCount prediction (PoissonRegressor)
ExponentialTime between random eventsContinuousGap between callsWaiting and survival times
NormalSum of many small effectsContinuousHeights, measurement errorsModel errors, Gaussian Naive Bayes
Log-normalProduct of many small effectsContinuousIncomes, pricesLog-transformed targets

When you meet a new column, ask three questions: is it a count or a measurement? Can it be negative? Does it grow by adding or by multiplying? The answers usually point to one of these six.

Common mistakes

  • Using a normal model for counts. Counts can't be negative or fractional; small counts are better described by binomial or Poisson distributions.
  • Ignoring the independence in the story. Poisson assumes events don't cluster. Payments at lunchtime or before a festival come in bursts, so the real tail is heavier than Poisson predicts.
  • Mixing up Poisson and exponential. Poisson counts events in a time window; exponential measures the time between events. Same process, two questions.
  • Expecting perfect fits. These are models. Check them against the data, for example with a Q-Q plot.

Practice

  1. Which distribution fits each story: (a) the number of defective bulbs in a box of 50, if each is defective with probability 2%; (b) the number of emails you receive in an hour; (c) the time until the next bus, if buses come at random; (d) the error of a well-calibrated weighing scale?
Show the answer

(a) Binomial (n = 50, p = 0.02). (b) Poisson. (c) Exponential. (d) Normal.

  1. Predict, then check: in the Poisson simulation with a rate of 3, what are the sample's mean and variance?
Show the answer

Both should be close to 3: for a Poisson distribution, the mean and the variance are equal.

payments = samples["Poisson: payments a minute, average 3"]
print(round(payments.mean(), 2), round(payments.var(), 2))
3.0 3.08
  1. A model with 90% true accuracy is tested on 50 examples. What's the chance it scores 42 or fewer (84% or less) by bad luck alone?
Show the answer
print(round(stats.binom.cdf(42, n=50, p=0.9), 3))
0.122

About 12%: a good model can easily look mediocre on a small test set.

  1. Why can't the exponential distribution have negative values?
Show the answer

It describes waiting times, and you can't wait a negative amount of time. Its shape starts at 0 and only goes right.

  1. A website's daily visitor count has a variance about ten times its mean. Is a Poisson distribution a good model? What might explain the extra spread?
Show the answer

No: a Poisson distribution has variance equal to its mean. The extra spread (called overdispersion) suggests visits aren't independent: weekends, campaigns and viral posts cause bursts. A model that allows extra variance, such as the negative binomial distribution, fits better.

Interview questions

What's the relationship between the Poisson and exponential distributions?

They describe the same process of independent events at a constant rate λ. The number of events in a fixed interval is Poisson(λt); the waiting time between consecutive events is exponential with rate λ (mean 1/λ). The exponential is memoryless.

When would you use Poisson regression instead of linear regression?

When the target is a count of events (claims, orders, visits), especially small counts with many zeros. Poisson regression models the log of the expected count as a linear function of features, so predictions are always positive, and it uses a loss suited to count data. If the variance greatly exceeds the mean, consider a negative binomial model.

Key takeaways

  • Learn distributions by their stories: what process creates each shape.
  • Uniform: all values equally likely. Binomial: successes in fixed tries. Poisson: events in a fixed time.
  • Exponential: time between random events, with no memory. Normal: sums of small effects. Log-normal: products of small effects.
  • Ask: count or measurement? Negative values possible? Adding or multiplying? The answers point to the right shape.
  • scipy.stats gives each one's probabilities (pmf/pdf, cdf) and random samples.

Frequently asked questions

Do I need to know every distribution's formula?

No. Know the story, the shape, the parameters and when to use it; SciPy computes the probabilities. The probability course covers the formulas and where they come from, for those who want them.

What's a Bernoulli distribution?

A binomial distribution with a single try: the outcome is 1 (success) with probability p or 0 (failure). Every yes-or-no label in classification is a Bernoulli outcome.

How do I know which distribution my data follows?

Use the story to make a guess, then check: compare the histogram with the fitted distribution, compare the mean and variance (equal for Poisson), and use a Q-Q plot. No real data fits perfectly; the question is whether the model is good enough for your purpose.

What to learn next

  1. Check whether data fits a distribution in Q-Q plots.
  2. Revisit the bell curve in the normal distribution explained.
  3. See test-set wobble in practice in classification metrics.