Skip to content

Instantly share code, notes, and snippets.

@ProfAvery
Last active February 14, 2020 01:27
Show Gist options
  • Save ProfAvery/9f52b9b33cd555fd5370b1d643f36eeb to your computer and use it in GitHub Desktop.
Save ProfAvery/9f52b9b33cd555fd5370b1d643f36eeb to your computer and use it in GitHub Desktop.
Skeleton code for in-class exercise
1 6
2 6
3 10
4 12
#!/usr/bin/env python3
import csv
import sys
def read_data(filename):
x = []
t = []
with open(filename) as csvfile:
data = csv.reader(csvfile)
for year, time in data:
x.append(float(year))
t.append(float(time))
return x, t
def average(array):
return sum(array) / len(array)
# Try this with two different CSV files:
# * https://gist.githubusercontent.com/ProfAvery/9f52b9b33cd555fd5370b1d643f36eeb/raw/d8928956d937657005053bf186fb7c9155efa4a8/data.csv
# * https://raw.githubusercontent.com/sdrogers/fcmlcode/master/notebooks/data/olympic100m.txt
#
x, t = read_data(sys.argv[1])
# TODO: Replace '?'s with code to compute the desired value.
x_bar = '?'
t_bar = '?'
xt_bar = '?'
w0_hat = '?'
w1_hat = '?'
print(f'y = {w0_hat} + {w1_hat}x')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment