Answered step by step
Verified Expert Solution
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 : 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started