Jess Hamrick
UC Berkeley
Project Jupyter
@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
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: 5.692703597805511 Model 2: 0.02898058018268955
Explain why the models have different error rates.
YOUR ANSWER HERE