Drawback Assertion: We analyzed easy linear regression in our final article and in contrast TV and newspaper spend and if we will draw a correlation with gross sales. On this article, we are going to do identical comparability however utilizing polynomial match. We shall be becoming larger diploma polynomial ,say, third order equation.
Information is downloaded from Kaggle
Polynomial match equation third diploma
y = B3*X**3 + B2*X**2 + B1*X + B0
which is B3 (coefficient) occasions X to the ability 3 + B2 occasions X to the ability 2+ B1 occasions X + B0
We are going to use our identical np.polyfit, however earlier than lets do the necessities and import all of the libraries and skim our csv
Import your Libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
Load the file
file_path = r'/Customers/Downloads/promoting.csv'
df_ad_data = pd.read_csv(file_path)
df_ad_data.head()
X_TV = df_ad_data['TV']
y_tv = df_ad_data['Sales']
Polynomial Regression
beta_tv_3, beta_tv_2, beta_tv_1, beta_tv_0 = np.polyfit(X_TV, y_tv, deg = 3)