<jupyter_start><jupyter_text>Simple Linear Regression<jupyter_code>path ='https://github.com/VitorKamada/DataScience/raw/master/Labs/Data/'
advertising = pd.read_csv(path + 'Advertising.csv', usecols=[1,2,3,4])
advertising.info()
sns.regplot(advertising.TV, advertising.Sales, order=1, ci=None, scatter_kws={'color':'r', 's':9})
plt.xlim(-10,310)
plt.ylim(ymin=0);
est = smf.ols('Sales ~ TV', advertising).fit()
est.summary().tables[1]
est = smf.ols('Sales ~ Radio', advertising).fit()
est.summary().tables[1]
est = smf.ols('Sales ~ Newspaper', advertising).fit()
est.summary().tables[1]<jupyter_output><empty_output><jupyter_text>Multiple Linear Regression<jupyter_code>est = smf.ols('Sales ~ TV + Radio + Newspaper', advertising).fit()
print(est.summary())
advertising.corr()
# What are the min/max values of Radio & TV?
# Use these values to set up the grid for plotting.
advertising[['Radio', 'TV']].describe()<jupyter_output><empty_output><jupyter_text>**Credit Dataset**<jupyter_code>credit = pd.read_csv(path + 'Credit.csv', usecols=list(range(1,12)))
credit['Student2'] = credit.Student.map({'No':0, 'Yes':1})
credit.head(3)
sns.pairplot(credit[['Balance','Age','Cards',
                    'Education','Income','Limit','Rating']]);

est = smf.ols('Balance ~ Gender', credit).fit()
print(est.summary().tables[1])
est = smf.ols('Balance ~ Ethnicity', credit).fit()
print(est.summary().tables[1])
est = smf.ols('Sales ~ TV + Radio + TV*Radio', advertising).fit()
print(est.summary().tables[1])
est1 = smf.ols('Balance ~ Income + Student2', credit).fit()
regr1 = est1.params
est2 = smf.ols('Balance ~ Income + Income*Student2', credit).fit()
regr2 = est2.params

print('Regression 1 - without interaction term')
print(regr1)
print('\nRegression 2 - with interaction term')
print(regr2)
# Income (x-axis)
income = np.linspace(0,150)

# Balance without interaction term (y-axis)
student1 = np.linspace(regr1['Intercept']+regr1['Student2'],
                       regr1['Intercept']+regr1['Student2']+150*regr1['Income'])
non_student1 =  np.linspace(regr1['Intercept'],
                            regr1['Intercept']+150*regr1['Income'])

# Balance with iteraction term (y-axis)
student2 = np.linspace(regr2['Intercept']+regr2['Student2'],
                       regr2['Intercept']+regr2['Student2']+
                       150*(regr2['Income']+regr2['Income:Student2']))
non_student2 =  np.linspace(regr2['Intercept'],
                            regr2['Intercept']+150*regr2['Income'])

# Create plot
fig, (ax1,ax2) = plt.subplots(1,2, figsize=(12,5))
ax1.plot(income, student1, 'r', income, non_student1, 'k')
ax2.plot(income, student2, 'r', income, non_student2, 'k')

for ax in fig.axes:
    ax.legend(['student', 'non-student'], loc=2)
    ax.set_xlabel('Income')
    ax.set_ylabel('Balance')
    ax.set_ylim(ymax=1550)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18970948547427371, 'fraction_numerical': 0.033951697584879245, 'mean_word_length': 5.133047210300429, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '529763', 'license': 'MIT', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1041, 'n_words': 169, 'path': 'Slides/Winter 2020/18) Multiple Linear Regression/Multiple_Regression.ipynb', 'repo_name': 'VitorKamada/ECO5100', 'size': '2857'}