Last active
February 14, 2020 01:27
-
-
Save ProfAvery/9f52b9b33cd555fd5370b1d643f36eeb to your computer and use it in GitHub Desktop.
Skeleton code for in-class exercise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 | 6 | |
---|---|---|
2 | 6 | |
3 | 10 | |
4 | 12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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