0Pricing
Learn AI with Python · Lesson

Descriptive Statistics and Distributions

Mean, median, variance, std, skewness, kurtosis, normal/binomial/Poisson distributions.

Descriptive Statistics and Distributions is a free Learn AI with Python lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Learn AI with Python learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Summarizing Data

Descriptive statistics condense a dataset into a few numbers describing its center, spread, and shape. They are the first thing you compute on any new dataset.

import numpy as np
data = np.array([4, 8, 6, 5, 3, 7, 9, 6])

Mean and Median

The mean is the arithmetic average; the median is the middle value. The median resists outliers, so a large gap between them signals skew.

print(np.mean(data))     # 6.0
print(np.median(data))   # 6.0

Variance and Std Dev

Variance is the average squared deviation from the mean; standard deviation is its square root, in the same units as the data.

print(np.var(data))   # population variance
print(np.std(data))   # standard deviation

Sample vs Population (ddof)

NumPy divides by N by default (population). For a SAMPLE estimate divide by N-1 using ddof=1, which corrects bias.

print(np.std(data, ddof=0))   # population
print(np.std(data, ddof=1))   # sample (unbiased)

Percentiles and IQR

Percentiles split sorted data. The 25th and 75th percentiles (quartiles) bound the middle 50 percent; their difference is the IQR.

q1 = np.percentile(data, 25)
q3 = np.percentile(data, 75)
print(q1, q3, q3 - q1)   # IQR

Skewness

Skewness measures asymmetry. Positive skew has a long right tail (income data); negative skew a long left tail. scipy.stats.skew computes it.

from scipy import stats
print(stats.skew(data))   # near 0 -> symmetric

Kurtosis

Kurtosis measures tail heaviness. High kurtosis means more extreme outliers than a normal curve. scipy reports excess kurtosis (normal = 0).

print(stats.kurtosis(data))   # 0 means normal-like tails

The Normal Distribution

The bell-shaped normal distribution is defined by its mean and standard deviation. About 68 percent of values fall within one std, 95 percent within two.

sample = stats.norm.rvs(loc=0, scale=1, size=1000, random_state=0)
print(np.mean(sample), np.std(sample))   # near 0 and 1

The Binomial Distribution

The binomial distribution counts successes in n independent yes/no trials with success probability p, such as heads in coin flips.

print(stats.binom.pmf(k=3, n=10, p=0.5))   # P(exactly 3 heads in 10)

The Poisson Distribution

The Poisson distribution models counts of rare events in a fixed interval given an average rate lambda, such as arrivals per minute.

print(stats.poisson.pmf(k=2, mu=3))   # P(2 events when avg is 3)

Histograms

A histogram bins values to reveal a distribution's shape. np.histogram returns counts and bin edges; matplotlib draws it.

counts, edges = np.histogram(sample, bins=10)
print(counts)
# import matplotlib.pyplot as plt; plt.hist(sample, bins=30)

Quick Check

Test your descriptive statistics knowledge.

Recap

Descriptive statistics toolkit:

  • Center: np.mean, np.median
  • Spread: np.var, np.std (use ddof=1 for samples), IQR via percentiles
  • Shape: scipy.stats.skew, scipy.stats.kurtosis
  • Distributions: normal, binomial, Poisson in scipy.stats
  • Histograms to visualize shape

Frequently asked questions

Is the “Descriptive Statistics and Distributions” lesson free?

Yes — the full text of “Descriptive Statistics and Distributions” is free to read here on the web, and the Learn AI with Python course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Learn AI with Python course, upgrade to CoddyKit PRO.

What will I learn in “Descriptive Statistics and Distributions”?

Mean, median, variance, std, skewness, kurtosis, normal/binomial/Poisson distributions. You practise Learn AI with Python with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Learn AI with Python?

No prior experience is required. Learn AI with Python on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Descriptive Statistics and Distributions” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Learn AI with Python lesson?

Yes. Every Learn AI with Python lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Descriptive Statistics and Distributions
  2. Probability and Bayes Theorem
  3. Hypothesis Testing
  4. Correlation and Covariance
← Back to Learn AI with Python