in Python
In this problem, your goal is to explore the
distribution of the residuals in the Anscombe
quartet data to see how different changes to a linear
relationship impact the residuals.
In the code below:
Read in the anscombe dataset from the pre-loaded
seaborn datasets as we've done in past problem sets and lectures
(sns.load_dataset(...))
Fit a separate linear regression to each of
the dataset types within the anscombe dataset using
the sklearn LinearRegression class.
Calculate the residuals for each of the four regressions you
created above. Reminder: the
residuals 𝜖𝑖=𝑦𝑖−𝑦̂ 𝑖ϵi=yi−y^i for each datapoint.
You should use the regression predict function we showed
in class to get the regression estimates 𝑦̂ 𝑖y^i.
Finally, plot the distribution of the
residuals for each dataset on separate graphs. You can use the
seaborn displot function, which allows you to generate
separate histograms for different values of a particular variable
or column using the col argument (take a look at the very
last examples on the displot documentation
page here). You do not need to change anything about the
residual plot titles or axis labels (but remember, putting clear
axis labels on your plots is always good practice!).
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score
from sklearn.model_selection import cross_val_score,
train_test_split
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import PolynomialFeatures
in Python In this problem, your goal is to explore the distribution of the residuals in the Anscombe quartet data to see
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
in Python In this problem, your goal is to explore the distribution of the residuals in the Anscombe quartet data to see
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!