# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # DAY6
# #Since simple linear regression didnt seem the best solution, we are trying Multiple regression on the same data

import pandas as pd
import numpy as np
import matplotlib.pyplot as py
from sklearn.linear_model import LinearRegression
from sklearn.metrics import r2_score
import statsmodels.api as sm

data = pd.read_csv("Advertising.csv")

data.head(10)

data.isnull().sum()

Xs = data.drop(['sales', 'Unnamed: 0'], axis=1)
y = data['sales'].values.reshape(-1,1)
reg = LinearRegression()
reg.fit(Xs, y)
print("The linear model is: Y = {:.5} + {:.5}*TV + {:.5}*radio + {:.5}*newspaper".format(reg.intercept_[0], reg.coef_[0][0], reg.coef_[0][1], reg.coef_[0][2]))

#correlation of newspaper seems very low & is negative also
X = np.column_stack((data['TV'], data['radio'], data['newspaper']))
y = data['sales']
X2 = sm.add_constant(X)
est = sm.OLS(y, X2)
est2 = est.fit()
print(est2.summary())

# +
#R-squared > R-squared(linear regression)
#F-statistic >1 . Hence depicts strong correlation
#P-VALUE: Large p-value for newspaper shows its insignificant in calculation. Hene, we can drop it.

#correlation of newspaper seems very low & is negative also
X = np.column_stack((data['TV'], data['radio']))
y = data['sales']
X2 = sm.add_constant(X)
est = sm.OLS(y, X2)
est2 = est.fit()
print(est2.summary())
# -



StarcoderdataJupyterScriptsDedupFiltered