Jess Hamrick
@jhamrick
@interact
def plot_histogram(num_samples=(0, 10000), bins=(10, 100), normed=True):
rv = scipy.stats.norm(0, 1)
samples = rv.rvs(num_samples)
x = np.linspace(-3, 3)
y = rv.pdf(x)
plt.hist(samples, normed=normed, color='k', bins=bins)
plt.plot(x, y, 'r-', lw=3)
Write code to compute the mean error between two arrays:
def error(x, y):
return np.sum(np.abs(x - y))
Write code to compute the mean squared error between two arrays:
def error(x, y):
# YOUR CODE HERE
raise NotImplementedError
$ ls ps1/
Problem 1.ipynb
Problem 2.ipynb
$ ls ps1/
problem 1.ipynb
Problem 2 Copy.ipynb
def error(x, y):
return np.sum(np.abs(x - y))
print(error(1, 2))
print(error(np.array([1, 2]), np.array([3, 4]))
File "<ipython-input-6-2b19b0758384>", line 2 print(error(np.array([1, 2]), np.array([3, 4])) ^ SyntaxError: unexpected EOF while parsing
Run your error
code on the ouput of the two models:
print("Model 1: {}".format(error(model1(x), y)))
print("Model 2: {}".format(error(model2(x), y)))
Model 1: 4.038695669499274 Model 2: 0.05343573722600464
Explain why the models have different error rates.
YOUR ANSWER HERE