In [1]:
import pandas as pd
%matplotlib inline
In [2]:
import matplotlib.pyplot as plt
import statsmodels.formula.api as smf
In [3]:
df = pd.read_csv("heights_weights_genders.csv")
In [4]:
df.head()
Out[4]:
In [93]:
lm = smf.ols(formula="Weight ~ Height + Gender",data=df).fit()
In [94]:
lm.params
Out[94]:
In [106]:
def guess_weight(height, gender):
for item in df['Weight']:
intercept = -244.923503
male = 19.377711
if gender == 'Male':
weight = height * 5.97 + intercept + male
else:
weight = height * 5.97 + intercept
return round(weight)
In [107]:
guess_weight(70, 'Male')
Out[107]:
In [108]:
guess_weight(70, 'Female')
Out[108]: