Model Coefficient and Residual Plots

DevTechie
DevTechie
Published in
3 min readAug 4, 2024

--

In this article, we will understand and calculate model coefficient and correlate with the residual plots in earlier articles

What is Model Coefficient?

Let us understand this with the same Ads dataset that we have been using. As we have been trying to predict sales based on ads spend data for TV, radio and newspaper, if we recall, when we fit linear regression model to this dataset our resulting linear regression equation might look like below:

Sales = β0​+β1​*TV+β2​*radio+β3​*newspaper

where β0 is the baseline value, i.e. even if there is no ad spend we assume our sales to be this value. β1​ represents that sales are expected to increase for each additional unit spend, same goes for radio and newspaper for β2 and β3 respectively.

Let’s look at the Python code to understand further. This will look familiar to what we have already done in previous articles.

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()

# X matrix to represent all my feature
X = df_ad_data[["TV","Radio","Newspaper"]]
X.head()

# Y vector column

y = df_ad_data['Sales']

--

--