In [ ]:
# HIDDEN
from datascience import *
%matplotlib inline
import matplotlib.pyplot as plots
plots.style.use('fivethirtyeight')
import numpy as np

Lecture 25

Average (Mean)

In [ ]:
values = make_array(2, 3, 3, 9)
In [ ]:
sum(values)/len(values)
In [ ]:
np.average(values)
In [ ]:
np.mean(values)
In [ ]:
(2 + 3 + 3 + 9)/4
In [ ]:
2*(1/4) + 3*(2/4) + 9*(1/4)
In [ ]:
values_table = Table().with_columns('value', values)
values_table
In [ ]:
bins_for_display = np.arange(0.5, 10.6, 1)
values_table.hist(0, bins = bins_for_display)
In [ ]:
twos = 2 * np.ones(10)
threes = 3 * np.ones(20)
nines = 9 * np.ones(10)
In [ ]:
new_vals = np.append(np.append(twos, threes), nines)
new_vals
In [ ]:
len(new_vals)
In [ ]:
Table().with_column('value', new_vals).hist(bins = bins_for_display)
In [ ]:
np.average(values)
In [ ]:
np.average(new_vals)
In [ ]:
####################################
nba = Table.read_table('nba2013.csv')
In [ ]:
nba.labels
In [ ]:
nba.hist('Height', bins=np.arange(65.5, 90.5))
In [ ]:
heights = nba.column('Height')
percentile(50, heights)
In [ ]:
np.average(heights)

Standard Deviation

In [ ]:
sd_table = Table().with_columns('Value', values)
sd_table
In [ ]:
average_value = np.average(sd_table.column(0))
average_value
In [ ]:
deviations = values - average_value
sd_table = sd_table.with_column('Deviation', deviations)
sd_table
In [ ]:
sum(deviations)
In [ ]:
sd_table = sd_table.with_columns('Squared Deviation', deviations ** 2)
sd_table
In [ ]:
# Variance of the data

variance = np.mean(sd_table.column('Squared Deviation'))
variance
In [ ]:
# Standard Deviation (SD) is the square root of the variance

sd = variance ** 0.5
sd
In [ ]:
np.std(values)
In [ ]: