Table of Contents#### Download Safari Books Online apps: Apple iOS | Android | BlackBerry

# Weighted Mean

Entire Site

Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

The *weighted mean* is a type of average that
has a weight for every observation being averaged. It is used in this
book to make numerical predictions based on similarity scores. The
weighted mean has the formula shown in Figure B-3, where
x_{1}...x_{n} are the
observations and w_{1}...w_{n}
are the weights.

A simple implementation of this formula that takes a list of values and weights is given here:

def weightedmean(x,w): num=sum([x[i]*w[i] for i in range(len(w))]) den=sum([w[i] for i in range(len(w))]) return num/den

In Chapter 2, weighted means are used to predict how much you’ll enjoy a movie. This is done by calculating an average rating from other people, weighted by how similar their tastes are to yours. In Chapter 8, weighted means are used to predict prices.