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

Variance

Variance measures how much a list of numbers varies from the mean (average) value. It is frequently used in statistics to measure how large the differences are in a set of numbers. It is calculated by averaging the squared difference of every number from the mean, as shown by the formula in Figure B-8.

Variance

Figure B-8. Variance

This is a simple function to implement:

def variance(vals):
  mean=float(sum(vals))/len(vals)
  s=sum([(v-mean)**2 for v in vals])
  return s/len(vals)

In Chapter 7, variance is used in regression tree modeling to determine how to best divide a set to make the subsets more tightly distributed.


  

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