Computer Science 151
An introduction to the art of
computing
Standard Deviation Lecture
Rudy Martinez
Arithmetic Mean formalized
• Remember Arithmetic Mean
• A measure of the most typical value in a set.
• 𝑥 usually denotes the mean
• More formally:
• 𝑥 𝑖𝑠 𝑡ℎ𝑒 𝑠𝑢𝑚 𝑜𝑓 𝑎𝑙𝑙 𝑛𝑢𝑚𝑏𝑒𝑟𝑠, 𝑥, 𝑑𝑖𝑣𝑖𝑑𝑒𝑑 𝑏𝑦 𝑡ℎ𝑒 𝑡𝑜𝑡𝑎𝑙 𝑛𝑢𝑚𝑏𝑒𝑟
𝑥 =
𝑥
𝑁
3/26/2019CS151SP19
Standard Deviation
• The 𝑥 is the most likely value
as denoted by the largest area
under the curve.
3/26/2019CS151SP19
Standard Deviation
• For a given data set, the standard deviation measures how spread
out numbers are from an average value ( 𝑥).
𝑠 =
𝑥− 𝑥 2
𝑛−1
• As you can see you are taking the distance of each point from the
average value.
• A note, if you have the whole list of numbers and not a random
selection then n-1 becomes n!
3/26/2019CS151SP19
How do we do this in Python?
• Saw we have a list of values
myList = [65, 45, 78, 92, 27]
3/26/2019CS151SP19
How do we do this in Python?
• Saw we have a list of values
myList = [65, 45, 78, 92, 27]
• First we need to calculate the arithmetic mean and store that.
3/26/2019CS151SP19
How do we do this in Python?
• Saw we have a list of values
myList = [65, 45, 78, 92, 27]
• First we need to calculate the arithmetic mean and store that.
sum = 0.0
3/26/2019CS151SP19
How do we do this in Python?
• Saw we have a list of values
myList = [65, 45, 78, 92, 27]
• First we need to calculate the arithmetic mean and store that.
sum = 0.0
for i in range(0, len(myList), 1):
sum += myList[i]
3/26/2019CS151SP19
How do we do this in Python?
• Saw we have a list of values
myList = [65, 45, 78, 92, 27]
• First we need to calculate the arithmetic mean and store that.
sum = 0.0
for i in range(0, len(myList), 1):
sum += myList[i]
xbar = sum/len(myList)
3/26/2019CS151SP19
How do we do this in Python?
• Saw we have a list of values
myList = [65, 45, 78, 92, 27]
• First we need to calculate the arithmetic mean and store that.
sum = 0.0
for i in range(0, len(myList), 1):
sum += myList[i]
xbar = sum/len(myList)
• Then iterate over the list of values subtracting the mean from the
item in the list, and write that to a list.
3/26/2019CS151SP19
How do we do this in Python?
• Saw we have a list of values
myList = [65, 45, 78, 92, 27]
• First we need to calculate the arithmetic mean and store that.
sum = 0.0
for i in range(0, len(myList), 1):
sum += myList[i]
xbar = sum/len(myList)
• Then iterate over the list of values subtracting the mean from the
item in the list, and write that to a list.
xbarValues = [ ]
3/26/2019CS151SP19
How do we do this in Python?
• Saw we have a list of values
myList = [65, 45, 78, 92, 27]
• First we need to calculate the arithmetic mean and store that.
sum = 0.0
for i in range(0, len(myList), 1):
sum += myList[i]
xbar = sum/len(myList)
• Then iterate over the list of values subtracting the mean from the item in
the list, and write that to a list.
xbarValues = [ ]
for i in range(0, len(myList), 1):
xbarValues[i] = math.pow((myList[i] – xbar),2)
3/26/2019CS151SP19
How do we do this in Python?
myList = [65, 45, 78, 92, 27]
sum = 0.0
for i in range(0, len(myList), 1):
sum += myList[i]
xbar = sum/len(myList)
xbarValues = [ ]
for i in range(0, len(myList), 1):
xbarValues[i] = math.pow((myList[i] – xbar),2)
• Sum the list and divide by the length of the list, then take the square root.
3/26/2019CS151SP19
How do we do this in Python?
myList = [65, 45, 78, 92, 27]
sum = 0.0
for i in range(0, len(myList), 1):
sum += myList[i]
xbar = sum/len(myList)
xbarValues = [ ]
for i in range(0, len(myList), 1):
xbarValues[i] = math.pow((myList[i] – xbar),2)
• Sum the list and divide by the length of the list, then take the square root.
xbarSum = 0.0
for i in range(0, len(xbarValues)1):
xbarSum += xbarValues[i]
3/26/2019CS151SP19
How do we do this in Python?
myList = [65, 45, 78, 92, 27]
sum = 0.0
for i in range(0, len(myList), 1):
sum += myList[i]
xbar = sum/len(myList)
xbarValues = [ ]
for i in range(0, len(myList), 1):
xbarValues[i] = math.pow((myList[i] – xbar),2)
• Sum the list and divide by the length of the list, then take the square root.
xbarSum = 0.0
for i in range(0, len(xbarValues)1):
xbarSum += xbarValues[i]
s = math.sqrt(xbarSum/len(xbarValues))
3/26/2019CS151SP19
How do we apply this to our data?
• Recall we have a both a clean set of data values in Homework2.csv
• Year, Tmax, Tmin
• We also have the average per year in averagedata.csv
3/26/2019CS151SP19
Final Exam/Project
• You should declare by email which one you would like to do.
• Email rudym@cs.unm.edu
• Subject CS151sp19 Final
• Body should contain a single word: Exam or Project
• You may choose one but not both!
3/26/2019CS151SP19
If you choose Exam
• It will be given during exam week
• Friday May 10th at 1230pm
• You will have 2 hours but shouldn’t need it.
• Test will be comprehensive.
• Strings
• For/while loops
• If statements
• Lists
• Dictionaries
• Very similar to the types of questions on the Midterm.
3/26/2019CS151SP19
If you choose Project
• Due Friday March 3rd by Midnight
• The project will be assigned on Friday April 5th
• You will receive a Project Specification which will need to be followed
thoroughly.
3/26/2019CS151SP19

CS 151 Standard deviation lecture

  • 1.
    Computer Science 151 Anintroduction to the art of computing Standard Deviation Lecture Rudy Martinez
  • 2.
    Arithmetic Mean formalized •Remember Arithmetic Mean • A measure of the most typical value in a set. • 𝑥 usually denotes the mean • More formally: • 𝑥 𝑖𝑠 𝑡ℎ𝑒 𝑠𝑢𝑚 𝑜𝑓 𝑎𝑙𝑙 𝑛𝑢𝑚𝑏𝑒𝑟𝑠, 𝑥, 𝑑𝑖𝑣𝑖𝑑𝑒𝑑 𝑏𝑦 𝑡ℎ𝑒 𝑡𝑜𝑡𝑎𝑙 𝑛𝑢𝑚𝑏𝑒𝑟 𝑥 = 𝑥 𝑁 3/26/2019CS151SP19
  • 3.
    Standard Deviation • The𝑥 is the most likely value as denoted by the largest area under the curve. 3/26/2019CS151SP19
  • 4.
    Standard Deviation • Fora given data set, the standard deviation measures how spread out numbers are from an average value ( 𝑥). 𝑠 = 𝑥− 𝑥 2 𝑛−1 • As you can see you are taking the distance of each point from the average value. • A note, if you have the whole list of numbers and not a random selection then n-1 becomes n! 3/26/2019CS151SP19
  • 5.
    How do wedo this in Python? • Saw we have a list of values myList = [65, 45, 78, 92, 27] 3/26/2019CS151SP19
  • 6.
    How do wedo this in Python? • Saw we have a list of values myList = [65, 45, 78, 92, 27] • First we need to calculate the arithmetic mean and store that. 3/26/2019CS151SP19
  • 7.
    How do wedo this in Python? • Saw we have a list of values myList = [65, 45, 78, 92, 27] • First we need to calculate the arithmetic mean and store that. sum = 0.0 3/26/2019CS151SP19
  • 8.
    How do wedo this in Python? • Saw we have a list of values myList = [65, 45, 78, 92, 27] • First we need to calculate the arithmetic mean and store that. sum = 0.0 for i in range(0, len(myList), 1): sum += myList[i] 3/26/2019CS151SP19
  • 9.
    How do wedo this in Python? • Saw we have a list of values myList = [65, 45, 78, 92, 27] • First we need to calculate the arithmetic mean and store that. sum = 0.0 for i in range(0, len(myList), 1): sum += myList[i] xbar = sum/len(myList) 3/26/2019CS151SP19
  • 10.
    How do wedo this in Python? • Saw we have a list of values myList = [65, 45, 78, 92, 27] • First we need to calculate the arithmetic mean and store that. sum = 0.0 for i in range(0, len(myList), 1): sum += myList[i] xbar = sum/len(myList) • Then iterate over the list of values subtracting the mean from the item in the list, and write that to a list. 3/26/2019CS151SP19
  • 11.
    How do wedo this in Python? • Saw we have a list of values myList = [65, 45, 78, 92, 27] • First we need to calculate the arithmetic mean and store that. sum = 0.0 for i in range(0, len(myList), 1): sum += myList[i] xbar = sum/len(myList) • Then iterate over the list of values subtracting the mean from the item in the list, and write that to a list. xbarValues = [ ] 3/26/2019CS151SP19
  • 12.
    How do wedo this in Python? • Saw we have a list of values myList = [65, 45, 78, 92, 27] • First we need to calculate the arithmetic mean and store that. sum = 0.0 for i in range(0, len(myList), 1): sum += myList[i] xbar = sum/len(myList) • Then iterate over the list of values subtracting the mean from the item in the list, and write that to a list. xbarValues = [ ] for i in range(0, len(myList), 1): xbarValues[i] = math.pow((myList[i] – xbar),2) 3/26/2019CS151SP19
  • 13.
    How do wedo this in Python? myList = [65, 45, 78, 92, 27] sum = 0.0 for i in range(0, len(myList), 1): sum += myList[i] xbar = sum/len(myList) xbarValues = [ ] for i in range(0, len(myList), 1): xbarValues[i] = math.pow((myList[i] – xbar),2) • Sum the list and divide by the length of the list, then take the square root. 3/26/2019CS151SP19
  • 14.
    How do wedo this in Python? myList = [65, 45, 78, 92, 27] sum = 0.0 for i in range(0, len(myList), 1): sum += myList[i] xbar = sum/len(myList) xbarValues = [ ] for i in range(0, len(myList), 1): xbarValues[i] = math.pow((myList[i] – xbar),2) • Sum the list and divide by the length of the list, then take the square root. xbarSum = 0.0 for i in range(0, len(xbarValues)1): xbarSum += xbarValues[i] 3/26/2019CS151SP19
  • 15.
    How do wedo this in Python? myList = [65, 45, 78, 92, 27] sum = 0.0 for i in range(0, len(myList), 1): sum += myList[i] xbar = sum/len(myList) xbarValues = [ ] for i in range(0, len(myList), 1): xbarValues[i] = math.pow((myList[i] – xbar),2) • Sum the list and divide by the length of the list, then take the square root. xbarSum = 0.0 for i in range(0, len(xbarValues)1): xbarSum += xbarValues[i] s = math.sqrt(xbarSum/len(xbarValues)) 3/26/2019CS151SP19
  • 16.
    How do weapply this to our data? • Recall we have a both a clean set of data values in Homework2.csv • Year, Tmax, Tmin • We also have the average per year in averagedata.csv 3/26/2019CS151SP19
  • 17.
    Final Exam/Project • Youshould declare by email which one you would like to do. • Email rudym@cs.unm.edu • Subject CS151sp19 Final • Body should contain a single word: Exam or Project • You may choose one but not both! 3/26/2019CS151SP19
  • 18.
    If you chooseExam • It will be given during exam week • Friday May 10th at 1230pm • You will have 2 hours but shouldn’t need it. • Test will be comprehensive. • Strings • For/while loops • If statements • Lists • Dictionaries • Very similar to the types of questions on the Midterm. 3/26/2019CS151SP19
  • 19.
    If you chooseProject • Due Friday March 3rd by Midnight • The project will be assigned on Friday April 5th • You will receive a Project Specification which will need to be followed thoroughly. 3/26/2019CS151SP19