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
In [28]:
df=pd.read_csv("data/heights_weights_genders.csv")
In [29]:
df.plot(kind="scatter",x="Height",y="Weight")
Out[29]:
In [30]:
lm = smf.ols(formula="Weight~Height",data=df).fit()
In [39]:
lm.params
Out[39]:
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]:
In [36]:
def getweight(height):
weight = slope*height+intercept
return weight
In [38]:
getweight(69)
Out[38]:
In [ ]: