Search

Search papers and lessons

Weighted Average

Level 1 · 11 min read

A weighted average is a mean in which each value counts in proportion to its weight, so bigger weights pull the result toward their values.

On this page

  • Colour = topic mix
  • Discrete math
  • Probability
  • ReadReady to readNot yet

TL;DR

A weighted average combines several values into one number, giving each value a share that matches its weight. A value with weight 3 counts three times as much as a value with weight 1. It solves the problem that an ordinary average treats every item as equally important, which is often wrong: a 3-credit course should count more than a 1-credit course, and a large purchase should count more than a small one.

Builds on: Summation Notation · Leads to: the mean and variance, expected value

Where it's used

Course grades. A student's grade point average (GPA) is a weighted average of the grade points earned in each course, with each course's credit hours as the weight. A four-credit course with a poor grade pulls the GPA down more than a one-credit course with the same grade, which matches how much work each course is.

Buying in bulk at different prices. A shop may buy 10 kilograms of flour at 2 dollars per kilogram in one order and 30 kilograms at 3 dollars per kilogram in another. The average price paid per kilogram is (10×2+30×3)/40=2.75(10 \times 2 + 30 \times 3) / 40 = 2.75 dollars, weighted by the quantities. Averaging the two prices evenly would give 2.50 dollars, which understates the cost because most of the flour was bought at 3 dollars. Accountants use this to value stock held at different costs.

Combining survey results. When a national poll reports the share of people who support a policy, a weighted average of regional results with each region weighted by its population gives a national figure. For example, region A has 1 million people with 60 percent support and region B has 3 million with 40 percent. The weighted figure is (1×60+3×40)/4=45(1 \times 60 + 3 \times 40) / 4 = 45 percent, while the unweighted average is 50 percent, which gives the small region the same influence as the large one. Surveys often correct for unequal selection with inverse probability weighting.

Attention in language models. In a transformer, each output vector is a weighted average of the value vectors in the sequence. The weights come from a Softmax that turns scores into positive shares adding to 1, so the most relevant tokens pull the output most. This is the normalised-weight form used in the math section.

How it works

Take two quiz scores, 80 and 60. The first quiz is worth weight 1, and the exam is worth weight 3, because the exam counts three times as much.

  1. Write each value with its weight. Quiz: value 80, weight 1. Exam: value 60, weight 3.
  2. Multiply each value by its weight. Quiz: 80×1=8080 \times 1 = 80. Exam: 60×3=18060 \times 3 = 180. Check: these are the weighted contributions of the two scores.
  3. Add the contributions. This is the sum that the summation sign in summation notation stands for: 80+180=26080 + 180 = 260.
  4. Add the weights. 1+3=41 + 3 = 4. Check: the weights say the total importance is 4 units.
  5. Divide the total contribution by the total weight. 260/4=65260 / 4 = 65. The weighted average is 65.
  6. Compare with the ordinary mean, (80+60)/2=70(80 + 60) / 2 = 70. The weighted average is lower, because the exam with the lower score has the bigger weight. The result sits closer to 60 than to 80, which is where the weight is.

The picture is a balance. Each value is a weight placed at a point on a line, and the average is where the line balances.

flowchart LR
    A[Values and weights] --> B[Multiply each value by its weight]
    B --> C[Add the products]
    A --> D[Add the weights]
    C --> E[Divide the sum of products by the sum of weights]
    D --> E
    E --> F[Weighted average]

The diagram shows the two sums that every weighted average needs: a sum of products on top, and a sum of weights below.

The math

Let there be nn values x1,…,xnx_1, \ldots, x_n with weights w1,…,wnw_1, \ldots, w_n, where each wi≥0w_i \ge 0 and at least one weight is positive. The weighted average is written xˉw\bar{x}_w.

Step 5 in symbols: the definition

xˉw=∑i=1nwi xi∑i=1nwi.\bar{x}_w = \frac{\sum_{i=1}^{n} w_i\,x_i}{\sum_{i=1}^{n} w_i}.

The numerator is the sum of the products in step 2 and the denominator is the sum of the weights in step 4. Check with the example: xˉw=1×80+3×601+3=2604=65\bar{x}_w = \frac{1 \times 80 + 3 \times 60}{1 + 3} = \frac{260}{4} = 65.

Step 4 in symbols: normalised weights

Divide each weight by the total weight to get shares pi=wi/∑jwjp_i = w_i / \sum_j w_j. The shares are non-negative and add to 1:

xˉw=∑i=1npi xi,∑i=1npi=1.\bar{x}_w = \sum_{i=1}^{n} p_i\,x_i, \qquad \sum_{i=1}^{n} p_i = 1.

Check: the shares are p1=1/4p_1 = 1/4 and p2=3/4p_2 = 3/4, which add to 1. Then 14×80+34×60=20+45=65\frac{1}{4} \times 80 + \frac{3}{4} \times 60 = 20 + 45 = 65. This is the same answer, and it is the form used in expected value, where the shares are probabilities of the outcomes of a random variable.

Two special cases

If every weight is equal, say wi=cw_i = c for all ii, the constant cancels and the formula becomes the ordinary mean:

xˉw=c∑ixic n=1n∑i=1nxi.\bar{x}_w = \frac{c\sum_i x_i}{c\,n} = \frac{1}{n}\sum_{i=1}^{n} x_i.

If one weight is zero, its value drops out completely. Check: with weights 0 and 1 on the values 10 and 20, the result is (0×10+1×20)/1=20(0 \times 10 + 1 \times 20) / 1 = 20.

Worked examples

Example
1. Two values by hand

Two values, 2 and 4, have weights 1 and 3.

  1. Multiply: 1×2=21 \times 2 = 2 and 3×4=123 \times 4 = 12.
  2. Add the products: 2+12=142 + 12 = 14.
  3. Add the weights: 1+3=41 + 3 = 4.
  4. Divide: 14/4=3.514 / 4 = 3.5.

Answer: the weighted average is 3.5. The ordinary average would be 3, and the answer is pulled toward 4 because 4 has three times the weight.

Example
2. A grade point average

A student takes three courses. The grade points are 4 (an A), 3 (a B) and 2 (a C), and the credit hours are 3, 4 and 3.

  1. Treat the grade points as the values and the credit hours as the weights.
  2. Multiply each grade point by its credits: 4×3=124 \times 3 = 12, 3×4=123 \times 4 = 12, 2×3=62 \times 3 = 6.
  3. Add the products: 12+12+6=3012 + 12 + 6 = 30.
  4. Add the credit hours: 3+4+3=103 + 4 + 3 = 10.
  5. Divide: 30/10=3.030 / 10 = 3.0.
  6. Check the result by reasoning: 3.0 lies between the grade points 2 and 4, and it is closer to 3, which is the grade of the course with the most credits (4). The GPA is 3.0.

Answer: the GPA is 3.0. The two 3-credit courses count equally and the 4-credit B course counts most, so the answer is set by the credits, not by the number of courses.

Example
3. A realistic task: the price paid per kilogram

A bakery buys flour in two orders. The first is 5 kilograms at 4 dollars per kilogram. The second is 15 kilograms at 6 dollars per kilogram. The owner wants to know the average price paid per kilogram across both orders.

  1. The values are the prices (4 and 6 dollars per kilogram). The weights are the quantities (5 and 15 kilograms).
  2. Multiply each price by its quantity to get the total spent on each order: 4×5=204 \times 5 = 20 dollars and 6×15=906 \times 15 = 90 dollars.
  3. Add the totals: 20+90=11020 + 90 = 110 dollars spent.
  4. Add the quantities: 5+15=205 + 15 = 20 kilograms bought.
  5. Divide: 110/20=5.5110 / 20 = 5.5 dollars per kilogram.
  6. Check: the simple average of the two prices is (4+6)/2=5(4 + 6)/2 = 5 dollars, which is too low, because most of the flour was bought at 6 dollars. The weighted answer of 5.5 is closer to 6, as it should be.

Answer: the average price paid is 5.5 dollars per kilogram. The owner's real cost is the total spent divided by the total bought, which is exactly the weighted average.

Try it: a shop sells 8 kilograms of rice at 3 dollars per kilogram and 12 kilograms at 5 dollars per kilogram. What is the average price per kilogram across the whole sale? Answer: the total spent is 8×3+12×5=24+60=848 \times 3 + 12 \times 5 = 24 + 60 = 84 dollars for 20 kilograms, so the average is 84/20=4.284 / 20 = 4.2 dollars per kilogram.

Common mistakes and tradeoffs

It is tempting to think a weighted average is the average of the weights times the average of the values; in fact it is the sum of products divided by the sum of weights. Multiplying the two averages gives a different number in general, so use the definition from step 5 instead.

It is tempting to divide by the number of values when the weights are not equal; in fact you divide by the sum of the weights. Dividing by the count, as in the GPA example, gives 30 over 3 courses, which is 10 and not a grade at all.

It is tempting to average averages: take the mean of a mean of groups and call it the overall mean. In fact the overall mean needs the group sizes as weights. Two classes with averages 70 and 90 and sizes 10 and 30 have an overall average of (10×70+30×90)/40=85(10 \times 70 + 30 \times 90) / 40 = 85, not 80.

Use a weighted average when the values differ in how much they should count: credits, quantities, populations, or probabilities. Use the ordinary mean when every value counts the same. For values that multiply, such as growth factors, the geometric mean is the right average instead. An alternative is to report the values and their weights together as a table, which is clearer when a reader may want to check the weights themselves. Weighted averages can hide an outlier that has a small weight, so check the individual values before trusting the single number.

History

Averages with weights are as old as trade. Merchants mixing goods of different prices or quality used them long before they had a name, and insurers and tax assessors used them to combine different records. The idea became a formal tool in the early 1800s, when weighted least squares, a form of linear regression, came into use in astronomy and surveying: observations of different precision were given different weights so that the most precise ones counted most. The same weighted sum later became the definition of expected value, which is why the idea appears in probability as well as in everyday arithmetic.

Recap

  • A weighted average is xˉw=∑wixi/∑wi\bar{x}_w = \sum w_i x_i / \sum w_i: products added on top, weights added below.
  • Equal weights give the ordinary mean, and a zero weight removes its value.
  • Normalising the weights to shares that add to 1 gives the same answer and is the form used in expected value.
  • Use it whenever the values should not count equally, such as grades by credits, prices by quantity, or recent observations in an exponential moving average.
  • Read next: Mean and Variance builds on the mean and adds the spread, and Expected Value is the weighted average where the weights are probabilities.

Check yourself

QuestionValues 10 and 30 have weights 2 and 3. What is the weighted average?Show answer

The products are 2×10=202 \times 10 = 20 and 3×30=903 \times 30 = 90. The sum of products is 110, and the sum of weights is 5. The weighted average is 110/5=22110 / 5 = 22. Check: 22 lies between 10 and 30 and is closer to 30, where the larger weight is.

QuestionA student has grades of 3.0 in a 4-credit course and 4.0 in a 2-credit course. What is their GPA, and why is it not the simple average of 3.5?Show answer

The products are 3.0×4=123.0 \times 4 = 12 and 4.0×2=84.0 \times 2 = 8. The sum is 20, and the total credits are 6, so the GPA is 20/6≈3.3320 / 6 \approx 3.33. The simple average of 3.5 gives the 2-credit course the same influence as the 4-credit course. The weighted version lets the larger course count twice as much, so the answer is closer to 3.0.

QuestionTwo classes have average test scores of 70 with 10 students and 90 with 30 students. A teacher reports the overall average as 80. Is this right? Explain with the formula.Show answer

No. The overall average must weight each class by its size: (10×70+30×90)/(10+30)=(700+2700)/40=3400/40=85(10 \times 70 + 30 \times 90) / (10 + 30) = (700 + 2700) / 40 = 3400 / 40 = 85. Averaging the two class averages gives 80, which treats the 30-student class as if it had only 10 students.

QuestionA shop sells some apples at 2 dollars each and some at 4 dollars each, and the total revenue is 60 dollars from 20 apples. What is the average price per apple, and what fact does this tell you about the sales mix?Show answer

The average price is 60/20=360 / 20 = 3 dollars. That is exactly halfway between 2 and 4, so the two groups of apples must be equal in number: 10 sold at 2 dollars and 10 at 4 dollars give 20+40=6020 + 40 = 60 dollars. With equal numbers the weighted and ordinary averages coincide, which is the special case described in the math section.

Sources