Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And Transact SQL

Authors: Lucy Scott

1st Edition

1974679985, 978-1974679980

More Books

Students also viewed these Databases questions

Question

1. How will you, as city manager, handle these requests?

Answered: 1 week ago