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 [1]:
import pandas as pd
%matplotlib inline
import matplotlib.pyplot as plt
import statsmodels.formula.api as smf
In [2]:
df = pd.read_csv("heights_weights_genders.csv")
In [3]:
df.head()
Out[3]:
In [6]:
df_male = df[df['Gender'] == 'Male']
In [7]:
df_female = df[df['Gender'] == 'Female']
In [8]:
lm_male = smf.ols(formula="Weight~Height",data=df_male).fit()
In [9]:
lm_female = smf.ols(formula="Weight~Height",data=df_female).fit()
In [10]:
lm_male.params
Out[10]:
In [11]:
lm_female.params
Out[11]:
In [12]:
def find_user_weight(user_height, user_gender):
if user_gender == 'male':
user_weight = 5.961774 * float(user_height) - 224.498841
if user_gender == 'female':
user_weight = 5.994047 * float(user_height) - 246.013266
return user_weight
In [ ]:
user_height = input("How tall are you in inches?: ")
user_gender = input("Are you male or female?: ")
find_user_weight(user_height, user_gender)
In [ ]: