Using the data from the 2013_NYC_CD_MedianIncome_Recycle.xlsx file, create a predictor using the weights from the model. This time, use the built in attributes in your model rather than hard-coding them into your algorithm.
In [2]:
import pandas as pd
%matplotlib inline
import matplotlib.pyplot as plt
import statsmodels.formula.api as smf
In [4]:
df = pd.read_excel("2013_NYC_CD_MedianIncome_Recycle.xlsx")
In [5]:
df.head()
Out[5]:
In [6]:
df.plot(kind="scatter",x="MdHHIncE",y="RecycleRate")
Out[6]:
In [7]:
lm = smf.ols(formula="RecycleRate~MdHHIncE",data=df).fit()
In [8]:
lm.params
Out[8]:
In [21]:
intercept, slope = lm.params
In [29]:
def find_recycle_rate(user_income):
user_recycle_rate = slope * float(user_income) + intercept
return user_recycle_rate
In [30]:
user_income = input("What is your monthly household income?: ")
find_recycle_rate(user_income)
Out[30]:
In [ ]:
In [ ]: