Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 3 : Linear Regression Let us consider a polynomial fitting problem. We assume the following model: y = 0 + 1 L 1 (

Exercise 3: Linear Regression
Let us consider a polynomial fitting problem. We assume the following model:
y=0+1L1(x)+2L2(x)+dots+pLp(x)+lon,
where Lp(x) is the p-th Legendre polynomial, j are the coefficients, and lon is the error term. In Python, if
you have specified a list of values of x, evaluating the Legendre polynomial is quite straight forward:
import numpy as np
from scipy.special import eval_legendre
x=np.linspace (-1,1,50) # 50 points in the interval -1,1
L4= eval_legendre (4,x),# evaluate the 4 th order Legendre polynomial for x
(a) Let 0=-0.001,1=0.01,2=0.55,3=1.5,4=1.2, and let lonGaussian(0,0.22). Generate 50
points of y over the interval x=np. linspace (-1,1,50). That is,
x=np.l inspace (-1,1,50)#50 points in the interval [-1,1]
y=dots fill this line
Scatter plot the data.
(b) Given the N=50 data points, formulate the linear regression problem. Specifically, write down the
expression
widehat()=argmin||y-x||2.
What are y,x, and ? Derive the optimal solution for this simple regression problem. Express your
answer in terms of x and y.
(c) Write a Python code to compute the solution. Overlay your predicted curve with the scattered plot.
For solving the regression problem, you can call numpy.linalg.lstsq.
(d) For the y you have generated, make 5 outlier points using the code below:
#dots,
idx =[10,16,23,37,45]??# these are the locations of the outliers
y[idx]=5??# set the outliers to have a value 5
#dots,
image text in transcribed

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

More Books

Students also viewed these Databases questions

Question

Use implicit differentiation to find dy/dx. cos y 2 + x = e y

Answered: 1 week ago