Assignment 3

  • 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 [12]:
import pandas as pd
import statsmodels.formula.api as smf

In [13]:
df = pd.read_excel("2013_NYC_CD_MedianIncome_Recycle.xlsx")

In [14]:
df.head()


Out[14]:
CD_Name MdHHIncE RecycleRate
0 Battery Park City, Greenwich Village & Soho 119596 0.286771
1 Battery Park City, Greenwich Village & Soho 119596 0.264074
2 Chinatown & Lower East Side 40919 0.156485
3 Chelsea, Clinton & Midtown Business Distric 92583 0.235125
4 Chelsea, Clinton & Midtown Business Distric 92583 0.246725

In [25]:
lm = smf.ols(formula="RecycleRate~MdHHIncE",data=df).fit()
intercept,slope = lm.params
def pre_weight(income):
    recyclerate = intercept + income * slope
    return recyclerate

In [26]:
pre_weight(2929292)


Out[26]:
5.551445566629349

In [ ]: