Question: Exercise 2 : Models for Data ( 2 5 points ) y x A model is a function that takes an input and produces a

Exercise 2: Models for Data (25 points)
y
x
A model is a function that takes an input and produces a prediction *
Let's consider two possible models for this data:
M1(x)=x+5
M2(x)=2x+1
Compute the predictions of models M1 and M2 for the values in x. These predictions should be vectors Y
of the same shape as . Then plot the prediction lines of these two models overlayed on the "observed" data (x,Y). Use plt.plot() to draw the lines. Note: you will generate only one plot. Make sure to include axes, titles and legend.
Evaluation Metrics
How good are our models? Intuitively, the better the model, the more closely it fits the data we have. y
x
That is, for each , we'll compare y, the true value, with *, the predicted value. This comparison is often y
called the loss or the error. One common such comparison is squared error: (y-????)2. Averaging over all our data points, we get the mean squared error.
1
yi
MSE =-lonY(yi-hat(i)i)2
Exercise 3: Computing MSE (25 points)
Write a function for computing the MSE metric and use it to compute the MSE for the two models above, M1 and M2.
def MSE(true_values, predicted_values):
""'"Return the MSE between true_values and predicted values.""."
# YOUR CODE HERE
print ('MSE for M1:', MSE(Y, M1))
print ('MSE for M2:', MSE(Y, M2))
MSE fo
r M1:
None
MSE fo
r M2:
None
 Exercise 2: Models for Data (25 points) y x A model

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!