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 [1]:
import pandas as pd
%matplotlib inline
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

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

In [28]:
lm = smf.ols(formula="RecycleRate~MdHHIncE",data=df).fit() #notice the formula regresses Y on X (Y~X)
intercept, slope = lm.params
lm.params
df.plot(kind='scatter', x='MdHHIncE', y='RecycleRate')


Out[28]:
<matplotlib.axes._subplots.AxesSubplot at 0x114b62a20>

In [24]:
plt.plot(df['MdHHIncE'], slope*df["MdHHIncE"]+intercept,"-",color="blue") #we create the best fit line from the values in the fit model


Out[24]:
[<matplotlib.lines.Line2D at 0x114aad978>]

In [ ]:


In [ ]:


In [ ]: