In [1]:
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
import statsmodels.formula.api as smf

In [2]:
cd C:\Users\Harsha Devulapalli\Desktop\algorithms\class5


C:\Users\Harsha Devulapalli\Desktop\algorithms\class5

In [28]:
df=pd.read_csv("data/heights_weights_genders.csv")

In [29]:
df.plot(kind="scatter",x="Height",y="Weight")


Out[29]:
<matplotlib.axes._subplots.AxesSubplot at 0x1fbce6eb0f0>

In [30]:
lm = smf.ols(formula="Weight~Height",data=df).fit()

In [39]:
lm.params


Out[39]:
Intercept   -350.737192
Height         7.717288
dtype: float64

In [32]:
intercept, slope = lm.params

In [33]:
df.plot(kind="scatter",x="Height",y="Weight")
plt.plot(df["Height"],slope*df["Height"]+intercept,"-",color="red")


Out[33]:
[<matplotlib.lines.Line2D at 0x1fbce6f2c18>]

In [36]:
def getweight(height):
    weight = slope*height+intercept
    return weight

In [38]:
getweight(69)


Out[38]:
181.75565540205253

In [ ]: