Question: Please help code this in python. Thank you. In this question, we are going to consider the simple linear mode; y=x where we are interested

Please help code this in python. Thank you.

Please help code this in python. Thank you. In this question, we

are going to consider the simple linear mode; y=x where we areinterested in estimating the value from some set of x and yvalues. To do this, we will first focus on the mean squared

In this question, we are going to consider the simple linear mode; y=x where we are interested in estimating the value from some set of x and y values. To do this, we will first focus on the mean squared error: MSE=N1i=1N(yixi)2 First, let's start out by generating some data for this problem set. Sample n=30 values from a uniform distribution between 0 and 10 . From these x values, we will multiply by a true theta value true=1.2 and add 30 random draws from a standard normal to these x values to get y values. Then plot the results on a scatter plot. import numpy as np import matplotlib.pyplot as plt from scipy import stats from math import factorial np.random.seed( 121 ) \# Let's set some parameters theta =1.2 n_samples =30 \# Draw x from a uniform distribution over [0,10) and noise from a standard normal distribution, then calculate y \#ans here Now, let's create a function called mse, which will use inputs x,y, and theta_hat, and from those inputs calculate the mean squared error. Fill out the empty variables y_hat and mse to complete the function. Then write a loop to call the function for 3 theta_hat values [0.75,1.0,1.5]. Use the x and y samples from the cell above as your inputs to this function! def mse(x, y, theta_hat): "" "Compute the mean squared error Args: x (ndarray): An array of shape (samples, ) that contains the input values. y (ndarray): An array of shape (samples, ) that contains the corresponding measurement values to the inputs. theta hat (float): An estimate of the slope parameter Returns: float: The mean squared error of the data with the estimated parameter. "" \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# \#\# Enter your code below \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# \# Compute the estimated y \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# \# Compute mean squared error \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# return mse \#\#\#\# Call the function with the 3 given theta_hat values below \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#

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!