In [1]:
import pandas as pd
import matplotlib.pyplot as plt # package for doing plotting (necessary for adding the line)
import statsmodels.formula.api as smf # package we'll be using for linear regression
%matplotlib inline
In [3]:
df = pd.read_excel('../../class4/homework/data/2013_NYC_CD_MedianIncome_Recycle.xlsx')
In [5]:
df.head()
Out[5]:
In [6]:
lm = smf.ols(formula="RecycleRate~MdHHIncE",data=df).fit()
lm.params
intercept, height = lm.params
In [14]:
# Function using the built math.
def simplest_predictor(income, height, intercept):
height = float(height)
intercept = float(intercept)
income = float(income)
return height*income+intercept
In [15]:
income = input("How high is the houshold income? ")
print("We predict a recycling rate of", simplest_predictor(income,height,intercept))