AI Hints
Statistics & Math for ML · Lesson 35 of 138

Combinations

When order doesn't.

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

Choosing three friends for a team is different from ranking them. Ana, Ben, and Cara is the same team as Cara, Ben, and Ana. When the order doesn't matter, we count combinations.

Combinations
From the video: Combinations
  • Pick a team of three
  • Order doesn't matter
  • Combinations

Choosing groups

Math dot comb counts the ways to choose K items from N. Choosing three from five gives ten teams, because each team was counted six times as a permutation. A lottery that picks six numbers from forty nine has nearly fourteen million combinations. Run it. One ticket gives you about a one in fourteen million chance.

combs.pypython
import math
from itertools import combinations

print(math.comb(5, 3), "teams")
print(list(combinations("ABCDE", 3))[:3])

tickets = math.comb(49, 6)
print(f"lottery: {tickets:,} combinations")
Output
10 teams
[('A', 'B', 'C'), ('A', 'B', 'D'), ('A', 'B', 'E')]
lottery: 13,983,816 combinations

Counting in ML

Combinations explain why some problems explode. A model with forty features has over a trillion possible subsets of features, so you can't try them all. That's why we use smarter methods, like regularization, or greedy feature selection, instead of checking every combination.

keyvalue
math.comb(n, k)n! ÷ (k! (n−k)!)
5 choose 310
Lottery13,983,816
40 featuresover a trillion subsets

Summary

Combinations count groups where order doesn't matter. They grow very fast. Next, a quiz on probability.

Key takeaways
  • math.comb(n, k)
  • Order doesn't matter
  • They explode quickly
Next up: Probability Quiz — test yourself