<jupyter_start><jupyter_text>Simple Linear Regression  Import the relevant Libs<jupyter_code>import numpy as np
import pandas as pd
import scipy
import statsmodels.api as sm
import matplotlib.pyplot as plt
import seaborn as sns
import sklearn

sns.set()<jupyter_output><empty_output><jupyter_text>Load the Data<jupyter_code>data = pd.read_csv('1.01. Simple linear regression.csv')
data.head()
data.describe()

plt.scatter(data['GPA'], data['SAT'])
plt.figure()
y = data['GPA']
x1 = data['SAT']
plt.xlabel('SAT', fontsize=20)
plt.ylabel('GPA', fontsize=20)

plt.scatter(x1, y)
plt.show()<jupyter_output><empty_output><jupyter_text>Regression<jupyter_code>x = sm.add_constant(x1)
results = sm.OLS(y, x).fit()
results.summary()
plt.scatter(x1, y)
yhat = 0.0017* x1 + 0.275
fig = plt.plot(x1, yhat, lw=4, c='orange', label='regression line')
plt.xlabel('SAT', fontsize=20)
plt.ylabel('GPA', fontsize=20)
plt.show();
x1.shape
x_rand = np.random.random(84)
x_rand
# Experimeting with OLS
#
x = sm.add_constant(x1)
x1_rand = sm.add_constant(x_rand)
results = sm.OLS(y, x).fit()
print(results.summary())
# This doesnt work :'-(
# OLS only works with a 1d dependent variable``
results = sm.OLS(y, x, x1_rand).fir()
print(results.summary())<jupyter_output>OLS Regression Results                            
==============================================================================
Dep. Variable:                    GPA   R-squared:                       0.406
Model:                            OLS   Adj. R-squared:                  0.399
Method:                 Least Squares   F-statistic:                     56.05
Date:                Sun, 30 May 2021   Prob (F-statistic):           7.20e-11
Time:                        23:19:34   Log-Likelihood:                 12.672
No. Observations:                  84   AIC:                            -21.34
Df Residuals:                      82   BIC:                            -16.48
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
==============================================================================
                 coef    std err          t      P>|[...]
{'fraction_non_alphanumeric': 0.1799370220422852, 'fraction_numerical': 0.03643724696356275, 'mean_word_length': 2.1235955056179776, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '415438', 'license': 'MIT', 'n_tokens_mistral': 774, 'n_tokens_neox': 694, 'n_words': 157, 'path': 'regression/Regression Practice.ipynb', 'repo_name': 'prasadprabhu333/coursera-applied-ds', 'size': '2223'}