<jupyter_start><jupyter_text>DAY6Since simple linear regression didnt seem the best solution, we are trying Multiple regression on the same data<jupyter_code>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())<jupyter_output>OLS Regression Results                            
==============================================================================
Dep. Variable:                  sales   R-squared:                       0.897
Model:                            OLS   Adj. R-squared:                  0.896
Method:                 Least Squares   F-statistic:                     859.6
Date:                Sat, 13 Jun 2020   Prob (F-statistic):           4.83e-98
Time:                        21:02:45   Log-Likelihood:                -386.20
No. Observations:                 200   AIC:                             778.4
Df Residuals:                     197   BIC:                             788.3
Df Model:                           2                                         
Covariance Type:            nonrobust                                         
==============================================================================
                 coef    std err          t      P>|[...]
{'fraction_non_alphanumeric': 0.17869415807560138, 'fraction_numerical': 0.03307560137457045, 'mean_word_length': 2.138814016172507, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '566847', 'license': 'MIT', 'n_tokens_mistral': 736, 'n_tokens_neox': 654, 'n_words': 187, 'path': 'Code/Day6- Multiple Regression.ipynb', 'repo_name': 'chetnashahi/100daysofML', 'size': '2328'}