# ---
# 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
# ---

# # Linear Regression

import numpy as np
import pandas as pd
import pandas_datareader as pdr
import matplotlib.pyplot as plt
# %matplotlib inline

housing = pd.read_csv('housing.csv')
housing.head()

housing.info()

housing.dropna(inplace=True)
housing.info()

housing[['Price (00s)', 'SqFt']].corr()

plt.scatter(housing['Price (00s)'], housing['SqFt'])

from sklearn.linear_model import LinearRegression as lr
model = lr(fit_intercept=True)
price = np.array(housing['Price (00s)'])
sqft = np.array(housing['SqFt'])
model.fit(sqft[:, np.newaxis], price)


xfit = np.linspace(sqft.min(),sqft.max(),100)
yfit = model.predict(xfit[:,np.newaxis])
plt.scatter(price,sqft)
plt.plot(yfit,xfit, c='r')
plt.ylabel('Price')
plt.xlabel('Sqft')

model.predict(1500)

print(model.coef_)
print(model.intercept_)

import statsmodels.api as sm
sqft = sm.add_constant(sqft)
reg = sm.OLS(price,sqft).fit()
reg.summary()













StarcoderdataJupyterScriptsDedupFiltered