Free Trial

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

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

B. Mathematical Formulas > Weighted Mean

Weighted Mean

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 x1...xn are the observations and w1...wn are the weights.

Weighted mean

Figure B-3. Weighted mean

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.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint