Created
November 3, 2022 09:49
-
-
Save rpromoditha/309bd69941d28af2393139c7901c2168 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Getting data | |
import pandas as pd | |
df = pd.read_csv('Advertising.csv') | |
X = df[['TV']] | |
y = df['Sales'] | |
# Create the train and test data | |
from sklearn.model_selection import train_test_split | |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, | |
random_state=42) | |
# Importing ResidualsPlot visualizer | |
from yellowbrick.regressor import ResidualsPlot | |
# Importing the Linear Regression model | |
from sklearn.linear_model import LinearRegression | |
# Creating the Residuals Plot | |
visualizer = ResidualsPlot(LinearRegression(), hist=False) | |
visualizer.fit(X_train, y_train) | |
visualizer.score(X_test, y_test) | |
# Saving plot in PNG format | |
visualizer.show(outpath="Residuals_Plot.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment