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 # package for doing plotting (necessary for adding the line)
import statsmodels.formula.api as smf # package we'll be using for linear regression

In [29]:
df = pd.read_csv("heights_weights_genders.csv")
df.columns
df_female = df[df['Gender']=='Female']
df_male = df[df['Gender']=='Male']

In [12]:
lm = smf.ols(formula="Weight~Height",data=df_female).fit() #notice the formula regresses Y on X (Y~X)

In [30]:
lm_m = smf.ols(formula="Weight~Height",data=df_male).fit() #notice the formula regresses Y on X (Y~X)

In [31]:
intercept_f, slope_f = lm.params
intercept_m, slope_m = lm_m.params

In [21]:
def get_weight_f(ht):
    return slope_f*height+intercept_f

In [32]:
def get_weight_m(ht):
    return slope_m*height+intercept_m

In [33]:
gender = input("What is your gender? ")
height = int(input("What is your height? "))


What is your gender? Male
What is your height? 69

In [34]:
if gender == 'Female':
    print(get_weight_f(height))
if gender == 'Male':
    print(get_weight_m(height))


186.863552324

In [ ]: