Harmonic Mean
The harmonic mean is a way to describe a “typical” value when your numbers are really about rates or ratios. It’s the average that naturally gives more weight to smaller values, which is often exactly what you want in those situations.
What it is (and how it’s computed)
The harmonic mean of positive values \(x_1, x_2, \dots, x_n\) is:
H = n / (1/x1 + 1/x2 + ... + 1/xn)
Instead of averaging the values directly (like the arithmetic mean), it averages their reciprocals and then flips back. Because of that, a single small value can pull the harmonic mean down a lot. It’s only defined in the usual way for positive numbers; zeros break the formula, and negatives usually don’t make sense for “rates.”
When it’s the right “average”
Use the harmonic mean when the quantity you care about is “per unit,” and you’re combining across equal units of the denominator (equal distances, equal items, equal time slices, etc.).
- Speed example: You drive 60 km at 60 km/h and 60 km at 30 km/h. The average speed is the harmonic mean: \(2 / (1/60 + 1/30) = 40\) km/h (not 45).
- Cost per item: If you pay different prices per unit across equal quantities, the harmonic mean reflects the overall “per unit” cost.
Why it matters in AI/ML
The harmonic mean shows up whenever you want a balanced score between two rates. The most famous case is the F1 score, the harmonic mean of precision and recall. It punishes models that do well on one but poorly on the other, which is crucial in imbalanced problems like fraud detection or medical screening.
Harmonic Mean is a measure of central tendency defined as the reciprocal of the average of reciprocals: for positive values xi, H = n / Σ(1/xi). It down-weights large values and is appropriate for averaging rates or ratios, common in ML evaluation. It underlies the F1 score, which is the harmonic mean of precision and recall, balancing false positives and false negatives.
Imagine you’re judging a car’s “typical” fuel efficiency across several trips. If one trip is very inefficient, it should pull the typical value down a lot, because it really matters. The harmonic mean is a way to average numbers that works especially well for rates and ratios—like speed, fuel economy, or “items per second.”
In statistics and AI/ML, the harmonic mean is often used when you want a balanced score that punishes low values strongly. A famous example is the F1 score, which combines precision and recall so a model can’t look good if one of them is poor.