Skip to main content

Harmonic Mean Calculator

Calculate harmonic mean instantly with our math tool. Shows detailed work, formulas used, and multiple solution methods.

Share this calculator

Formula

HM = n / (1/x1 + 1/x2 + ... + 1/xn)

The harmonic mean of n values is n divided by the sum of reciprocals. For two numbers a and b, this simplifies to 2ab/(a+b). The harmonic mean is always less than or equal to the geometric mean, which is always less than or equal to the arithmetic mean (HM <= GM <= AM).

Worked Examples

Example 1: Average Speed for Round Trip

Problem: You drive to work at 40 mph and return at 60 mph over the same distance. What is your average speed?

Solution: Harmonic Mean = 2 x 40 x 60 / (40 + 60)\n= 4800 / 100\n= 48 mph\nVerification: If distance = 100 miles each way:\nTime going = 100/40 = 2.5 hours\nTime returning = 100/60 = 1.667 hours\nAverage = 200 miles / 4.167 hours = 48 mph

Result: Average Speed = 48 mph (not 50 mph as arithmetic mean would suggest)

Example 2: F1 Score Calculation

Problem: A classifier has precision = 0.9 and recall = 0.6. Find the F1 score.

Solution: F1 = Harmonic Mean of Precision and Recall\nF1 = 2 x 0.9 x 0.6 / (0.9 + 0.6)\n= 1.08 / 1.5\n= 0.72\nArithmetic mean would be (0.9 + 0.6)/2 = 0.75\nThe harmonic mean is lower, penalizing the imbalance

Result: F1 Score = 0.72 (harmonic mean penalizes the lower recall)

Frequently Asked Questions

What is the harmonic mean and how is it calculated?

The harmonic mean is a type of average calculated as the number of values divided by the sum of their reciprocals. For n numbers x1, x2, ..., xn, the harmonic mean equals n divided by (1/x1 + 1/x2 + ... + 1/xn). For two numbers a and b, this simplifies to 2ab/(a+b). The harmonic mean gives less weight to large outliers and more weight to smaller values compared to the arithmetic mean. It is always the smallest of the three Pythagorean means (harmonic, geometric, arithmetic) unless all values are equal, in which case all three means are identical.

When should you use the harmonic mean instead of the arithmetic mean?

Use the harmonic mean when averaging rates, ratios, or speeds for equal distances or equal work. The classic example is average speed: if you drive 60 mph for a certain distance and 40 mph for the same distance back, the average speed is the harmonic mean (48 mph), not the arithmetic mean (50 mph). Other applications include averaging price-to-earnings ratios in finance, combining parallel resistances in electronics, averaging fuel efficiency for equal distances, and computing the F1 score in machine learning as the harmonic mean of precision and recall.

Why is the harmonic mean used for average speed calculations?

The harmonic mean is correct for average speed when equal distances are traveled at different speeds because speed is a rate (distance per time). If you drive 100 miles at 40 mph (2.5 hours) and 100 miles at 60 mph (1.667 hours), total distance is 200 miles in 4.167 hours, giving true average speed of 48 mph. The arithmetic mean of 50 mph is wrong because you spend more time at the slower speed. The harmonic mean of 40 and 60 is 2 times 40 times 60 divided by (40 + 60) which equals 48, matching the correct answer. This property extends to any situation involving equal amounts of a denominator quantity.

What is the relationship between harmonic, geometric, and arithmetic means?

For any set of positive numbers, the three Pythagorean means satisfy the inequality: harmonic mean is less than or equal to geometric mean, which is less than or equal to arithmetic mean (HM is less than or equal to GM is less than or equal to AM). This is known as the AM-GM-HM inequality. Equality holds if and only if all values are identical. For two numbers, there is an elegant relationship: the geometric mean squared equals the arithmetic mean times the harmonic mean (GM squared equals AM times HM). These relationships are foundational in mathematical analysis and appear in proofs across many fields.

How is the harmonic mean used in finance?

In finance, the harmonic mean is used to average multiples like price-to-earnings (P/E) ratios, price-to-book ratios, and price-to-sales ratios across a portfolio. This is because these ratios have price in the numerator and a per-share quantity in the denominator, making them rates. The harmonic mean properly weights the average by the denominator. For example, if fund managers use equal dollar amounts across stocks with different P/E ratios, the portfolio P/E is the harmonic mean of individual P/E ratios. Market-cap weighted indices like the S&P 500 use this approach implicitly.

How is the harmonic mean applied in machine learning?

In machine learning and information retrieval, the F1 score is defined as the harmonic mean of precision and recall. Precision measures how many selected items are relevant, while recall measures how many relevant items are selected. The harmonic mean is chosen because it penalizes extreme imbalances between the two. A classifier with 100% precision but 1% recall would have an arithmetic mean of 50.5% but a harmonic mean (F1 score) of only 1.98%, correctly reflecting poor overall performance. The weighted F-beta score generalizes this to different weightings between precision and recall.

References