Question: Exercise 3 : Linear Regression Let us consider a polynomial fitting problem. We assume the following model: y = 0 + 1 L 1 (
Exercise : Linear Regression
Let us consider a polynomial fitting problem. We assume the following model:
dots
where is the th Legendre polynomial, are the coefficients, and is the error term. In Python, if
you have specified a list of values of evaluating the Legendre polynomial is quite straight forward:
import numpy as np
from scipy.special import evallegendre
linspace # points in the interval
evallegendre # evaluate the th order Legendre polynomial for
a Let and let Generate
points of over the interval linspace That is
inspace # points the interval
dots fill this line
Scatter plot the data.
b Given the data points, formulate the linear regression problem. Specifically, write down the
expression
widehat
What are and Derive the optimal solution for this simple regression problem. Express your
answer in terms of and
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 you have generated, make outlier points using the code below:
#dots,
idx # these are the locations the outliers
# set the outliers have a value
#dots,
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
