AI Hints
Home›Statistics & Math for ML Tutorial›The Normal Distribution
Statistics & Math for ML · Lesson 45 of 138

PDF and CDF

Density and area.

⏱ 2 min read▶ Video at 51:15🎓 Free
Watch this lesson in the Statistics & Math for ML courseWatch on YouTube ↗Full Statistics & Math for ML course

For continuous variables, we can't ask for the chance of an exact value. We ask about ranges instead. What's the chance someone is shorter than one eighty? That's an area under the curve.

PDF and CDF
From the video: PDF and CDF
  • No exact values
  • Ask about ranges
  • Area under the curve

Two functions

The PDF, the probability density function, is the height of the curve. Higher means values there are more common. The CDF, the cumulative distribution function, is the area to the left of a point. So the CDF at one eighty is the chance of being shorter than one eighty.

PDFheight of the curve
CDFarea to the left
P(X < a)cdf(a)
P(a < X < b)cdf(b) − cdf(a)

Areas with scipy

Norm dot CDF gives the chance of being below a value. Subtract two CDFs for a range. And PPF goes backwards. It finds the height that ninety five percent of people are below. Run it. About eighty nine percent are under one eighty, and the ninety fifth percentile is about one eighty three.

cdf.pypython
from scipy.stats import norm

mu, sigma = 170, 8

print("P(h < 180):      ", round(norm.cdf(180, mu, sigma), 4))
between = norm.cdf(180, mu, sigma) - norm.cdf(160, mu, sigma)
print("P(160 < h < 180):", round(between, 4))
print("95th percentile: ", round(norm.ppf(0.95, mu, sigma), 1))
Output
P(h < 180):       0.8944
P(160 < h < 180): 0.7887
95th percentile:  183.2

Summary

The PDF is the curve's height, and the CDF is the area to the left. PPF goes from a probability back to a value. Next, checking whether data is really normal.

Key takeaways
  • norm.cdf for areas
  • Subtract for a range
  • norm.ppf goes backwards
Next up: Is It Normal? — Q-Q plots