Question: In this problem, we are going to use simulated datasets to better understand how the square of bias, variance, irreducible error, and MSE vary with
In this problem, we are going to use simulated datasets to better understand how the square
of bias, variance, irreducible error, and MSE vary with model flexibility.
a Generate a simulated dataset as follows:
def fx:
return x x
def getsimdataf samplesize std:
x nprandom.uniform samplesize
y fx nprandom.normal std samplesize
df pdDataFramex: xy: y
return df
In this dataset, what is the number of observations and what is the number of features
different powers of are counted as different features Write out the model used
to generate the data in equation form.
bpts Fit the polynomial functions of degree from to using the simulated data in
a:
vdots
cdots
Hint: You may find
from sklearn. preprocessing import PolynomialFeatures
from sklearn.linearmodel import LinearRegression
useful.
cpts Predict the response at using the fitted functions in b
d Repeat for times.
e Use d to calculate the square of bias for the fitted polynomials hathatcdots,hat
In this problem, we are going to use simulated datasets to better understand how the square
of bias, variance, irreducible error, and MSE vary with model flexibility.
a Generate a simulated dataset as follows:
def fx:
return x x
def getsimdataf samplesize std:
x nprandom.uniform samplesize
y fx nprandom.normal std samplesize
df pdDataFramex: xy: y
return df
In this dataset, what is the number of observations and what is the number of features
different powers of are counted as different features Write out the model used
to generate the data in equation form.
bpts Fit the polynomial functions of degree from to using the simulated data in
a:
vdots
cdots
Hint: You may find
from sklearn. preprocessing import PolynomialFeatures
from sklearn.linearmodel import LinearRegression
useful.
cpts Predict the response at using the fitted functions in b
d Repeat for times.
e Use d to calculate the square of bias for the fitted polynomials hathatcdots,hat
f Use d to calculate the variance for the fitted polynomials hathatcdots,hat
g Calculate the irreducible error based on the data generating process.
h Calculate the MSE based on ef and g
ipts Plot how the square of bias, variance, irreducible error, and MSE vary with the
degree of polynomials. Explain your findings.
f Use d to calculate the variance for the fitted polynomials hathatcdots,hat
g Calculate the irreducible error based on the data generating process.
h Calculate the MSE based on ef and g
ipts Plot how the square of bias, variance, irreducible error, and MSE vary with the
degree of polynomials. Explain your findings.
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
