(Coding) Mode, Mean, Variance, StdDev

118 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
118
On SlideShare
0
From Embeds
0
Number of Embeds
26
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

(Coding) Mode, Mean, Variance, StdDev

  1. 1. Coding in Python Mode list index modecnt imode … … … value mode data[i] … … … # the mode function to make it return the mode of a list of numbers def mode(data): modecnt = 0 for i in range(len(data)): imode = data.count(data[i]) if imode > modecnt: modecnt = imode mode = data[i] return mode Kelly Chan | Nov 11 2013
  2. 2. Coding in Python Variance data data[i] … mean ndata (data[i] – mean)**2 … mean sigma2 # the variance function to make it return the variance of a list of numbers def mean(data): return sum(data)/len(data) def variance(data) mu = mean(data) ndata = [] for i in range(len(data)): ndata.append((data[i] - mu)**2) sigma2 = mean(ndata) return sigma2 def variance(data) mu = mean(data) return mean([(x - mu)**2 for x in data]) Kelly Chan | Nov 11 2013
  3. 3. Coding in Python Standard Deviation data data[i] … mean ndata (data[i] – mean)**2 … mean sigma2 variance sigma stddev # the stddev function to make it return the standard deviation of a list of numbers from math import sqrt def mean(data): return sum(data)/len(data) def variance(data): mu=mean(data) return mean([(x-mu)**2 for x in data]) def stddev(data): return sqrt(variance(data)) Kelly Chan | Nov 11 2013

×