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

# Variance

Entire Site

Free Trial

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

*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.

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.