Create two models for the relationship between height and weight based on gender Modify the code in Assignment 1 to ask for a person's gender as well as their height to produce an estimate of a person's weight using the models you created Find the weights and use those in your function (i.e. don't generate a model each time)
In [3]:
import pandas as pd
import statsmodels.formula.api as smf
In [4]:
df = pd.read_csv("heights_weights_genders.csv")
In [5]:
df
Out[5]:
In [6]:
df.head()
Out[6]:
In [7]:
lm = smf.ols(formula="Weight ~ Height + Gender",data=df).fit()
In [9]:
lm.params
Out[9]:
In [11]:
height_input = input("What is your height in inches?")
In [15]:
gender_input = input('Male or Famale')
In [16]:
def weight_estimation(individual_height, individual_gender):
Intercept= -244.923503
Male= 19.377711
Slope= 5.976941
if individual_gender == 'Male':
return (Intercept + Male + (Slope * float(individual_height)))
else:
return (Intercept + (Slope * float(individual_height)))
In [17]:
weight_estimation(73.847017, 'Male')
Out[17]:
In [19]:
weight_estimation(73.847017, 'Female')
Out[19]:
In [ ]: