Linear Regression — Residual plot for Radio spend data
In our last article, we said we will evaluate performance metrics and analyze Residual plot for Radio spend data. So let’s get going
Radio
Import our libraries and load our data
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
file_path = r'/Users/Downloads/advertising.csv'
df_ad_data = pd.read_csv(file_path)
df_ad_data.head()
Creating X matrix for Radio data
X_radio = df_ad_data[["Radio"]]
X_radio.head()
Get Y Vector Column
y_radio = df_ad_data['Sales']
y_radio.head()
Separate out our training data and test data
from sklearn.model_selection import train_test_split
X_train_radio, X_test_radio, y_train_radio, y_test_radio = train_test_split(X_radio, y_radio, test_size=0.3, random_state=101)
Apply LinearRegression
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit(X_train_radio, y_train_radio)
test_predictions_radio = model.predict(X_test_radio)
Calculate mean_absolute_error and root_mean_squared_error
from sklearn.metrics import mean_squared_error, mean_absolute_error…