TapCub is live — analytics, insights and live chat, free on one platform
Glossary

Harmonic mean: formula and when rates need it

The harmonic mean is the reciprocal of the average reciprocal. Learn when speeds, throughput and cost per click need it, why F1 uses it, and how it compares with other means.

Chen Yu Reviewed by Sophia Bennett Also called harmonic average Last updated Dec 3, 2026 Glossary

Quick answer

The harmonic mean is the number of values divided by the sum of their reciprocals. It is the correct average for rates when each item covers the same amount of the top quantity, such as speeds over equal distances, and it underlies the F1 score.

Formula: HM = n ÷ (1/x1 + 1/x2 + … + 1/xn); weighted: Σw ÷ Σ(w ÷ x)

What is the harmonic mean?

The harmonic mean of a set of positive numbers is the number of values divided by the sum of their reciprocals. Put another way, take the reciprocal of each value, average those reciprocals, and flip the result back. The NIST Dataplot manual defines it in exactly this form.

For 2 and 8: the reciprocals are 0.5 and 0.125, their average is 0.3125, and 1 ÷ 0.3125 = 3.2. The geometric mean of the same pair is 4 and the arithmetic mean is 5. For positive numbers that differ, the harmonic mean is the smallest of the three, because small values have large reciprocals and therefore a large say.

It sounds like a curiosity until you meet a rate: something per something, such as megabytes per second, tickets per hour or dollars per click. Whether the harmonic mean is right depends on one question: which quantity was held fixed across the things you are averaging?

When rates need the harmonic mean

Three files of 100 MB each are downloaded one after another at 50, 20 and 10 MB per second (sample data). What was the average speed?

FileSizeSpeedTime
1100 MB50 MB/s2 s
2100 MB20 MB/s5 s
3100 MB10 MB/s10 s
Total300 MB17 s

Average speed means total data over total time: 300 ÷ 17 = 17.6 MB/s. The arithmetic mean of the three speeds, (50 + 20 + 10) ÷ 3 = 26.7 MB/s, is far too high. The harmonic mean gets it right: 3 ÷ (1/50 + 1/20 + 1/10) = 3 ÷ 0.17 = 17.6 MB/s.

The reason is that the slow file takes up most of the clock. Each file has the same size, but not the same duration, so speeds must be weighted by time, and the harmonic mean does that automatically.

Now change the setup. Run each speed for the same 10 seconds instead. The three runs transfer 500, 200 and 100 MB, so the average is 800 ÷ 30 = 26.7 MB/s, which is the arithmetic mean. Same three speeds, different fixed quantity, different correct average.

Rule: for a rate written as A per B, if every item covers the same amount of A (the top), use the harmonic mean; if every item covers the same amount of B (the bottom), use the arithmetic mean.

Throughput and cost per click examples

Three support agents each clear a queue of 60 tickets, working at 12, 20 and 30 tickets per hour (sample data). They need 5, 3 and 2 hours, 10 hours for 180 tickets, so the team rate is 18 tickets per hour. The harmonic mean gives 3 ÷ (1/12 + 1/20 + 1/30) = 18. The arithmetic mean says 20.7 and would lead you to plan too little staff time. Related timing metrics are discussed in average handle time.

The same structure appears in ad reporting. Spend $100 on each of three campaigns with a cost per click of $0.50, $1.00 and $2.00:

CampaignSpendCost per clickClicks
X$100$0.50200
Y$100$1.00100
Z$100$2.0050
Total$300$0.86350

The overall cost per click is $300 ÷ 350 = $0.857, the harmonic mean of the three prices. The arithmetic mean, $1.17, overstates it by about 36%.

When the fixed amounts are unequal, use the weighted harmonic mean: Σ w ÷ Σ (w ÷ x), with the top quantity as the weight. If a 300 MB file arrives at 50 MB/s and a 100 MB file at 10 MB/s, the result is 400 ÷ (300/50 + 100/10) = 400 ÷ 16 = 25 MB/s.

F1 score: the harmonic mean of precision and recall

The best-known use in machine learning is the F1 score. The scikit-learn documentation describes it as a harmonic mean of precision and recall, with the two counting equally, and writes it in counts as 2·TP ÷ (2·TP + FP + FN).

Suppose a rule flags suspicious signups (sample data): it catches 90 bad signups, wrongly flags 10 good ones and misses 210.

  • Precision = 90 ÷ (90 + 10) = 0.90: most of what it flags really is bad.
  • Recall = 90 ÷ (90 + 210) = 0.30: it finds less than a third of the bad ones.
  • F1 = 2 × 0.90 × 0.30 ÷ (0.90 + 0.30) = 0.45, the same as 180 ÷ 400.
RulePrecisionRecallArithmetic meanF1
Cautious0.900.300.600.45
Balanced0.600.600.600.60

The arithmetic mean cannot tell the two rules apart. F1 prefers the balanced one, because a harmonic mean is held down by the weaker of its inputs. If precision or recall falls to zero, F1 goes to zero. F1 is still a single compromise: when a missed case costs far more than a false alarm, report precision and recall separately.

Harmonic mean vs arithmetic mean vs geometric mean

Mean2 and 850, 20, 10Fits
Arithmetic526.7Totals; rates over equal bottom amounts
Geometric421.5Growth factors and ratios
Harmonic3.217.6Rates over equal top amounts; F1

For positive values the order is always arithmetic ≥ geometric ≥ harmonic, with equality only when every value is the same. A wide gap between them is a sign that the values differ a lot and that the choice of average matters. For a non-rate choice between the arithmetic mean and the middle value, see mean vs median.

Pitfalls to avoid

  • Zeros. Zero has no reciprocal. A throughput of zero means the job never finishes, so report it separately.
  • Negative values. SciPy documents the harmonic mean only for non-negative observations and gives a not-a-number result otherwise.
  • Using it on plain amounts. Order values and page counts are not rates; the harmonic mean has no sensible reading for them.
  • Ignoring unequal volumes. Three campaigns with very different spend need the weighted form.
  • Skipping the totals. If you have the raw numerators and denominators, divide the totals. It is always the safest route and needs no formula choice.

Computing it, and where TapCub fits

In a spreadsheet, =HARMEAN(range) gives the unweighted form; for the weighted one, add a helper column holding weight ÷ value and divide the sum of the weights by the sum of that column. In Python, scipy.stats.hmean accepts weights.

With analytics data you can usually avoid the choice by working from totals:

  1. Cost per click by channel. Open the ROI tab of All-platform analytics › Business › Advertising and import spend, with click counts, on its Costs view. For each channel, source or campaign, the CPC column of the ROI view divides total spend by total imported clicks. Do not average that column across rows; divide total spend by total clicks.
  2. Ratios across segments. Define the metric as a formula in All-platform analytics › Behavior › Metrics & SQL, for example a property sum divided by a count of people. It is then computed from totals at every breakdown level.
  3. If all you have is a list of rates. Export or copy the per-item rates, ask what was fixed, and pick the mean by the rule above. Write the choice next to the number.

TapCub does not score classifiers, so precision, recall and F1 for the signup rule above would be calculated in your own tooling.

Sources

Was this explanation clear?

We use your answers to fix and expand this page.

Chen Yu

Technical Engineer

Focuses on tracking code, SDKs, and API integrations, with practical guidance on implementation checks and troubleshooting.

FAQ

Questions people ask

Short answers to the follow-up questions that come up most.

Still have a question?

Chat with the team behind TapCub — we usually reply within a few hours on business days.

When should you use the harmonic mean?

When averaging a rate written as A per B and each item covers the same amount of A: speeds over equal distances, download rates over equal file sizes, or cost per click over equal budgets. If each item covers the same amount of B, use the arithmetic mean.

What is the harmonic mean of 2 and 8?

It is 2 ÷ (1/2 + 1/8) = 2 ÷ 0.625 = 3.2. For comparison, the geometric mean of the same pair is 4 and the arithmetic mean is 5.

Why does the F1 score use the harmonic mean?

Because it is pulled toward the weaker of precision and recall. A rule with precision 0.90 and recall 0.30 has an arithmetic mean of 0.60 but an F1 of only 0.45, which reflects that it misses most cases.

Can the harmonic mean be used with zero values?

Not directly, since zero has no reciprocal. Some contexts take the limit, so F1 is zero when precision or recall is zero. For throughput data, report zero-rate items separately instead of averaging them in.

See this number on your own site

Add one script tag for web and apps, and the first reports fill in within minutes.

See your data clearly. Find your growth.

Every click, backed by data. Install one line of code and see your first numbers in a minute.

No credit card · Free plans for analytics and chat · Cookieless analytics