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 [2]:
import pandas as pd
In [3]:
import statsmodels.formula.api as smf
In [4]:
df = pd.read_csv("heights_weights_genders.csv")
In [5]:
df.head()
Out[5]:
Here:
y: is the variable that we want to predict
ß0: is intercept of the regression line i.e. value of y when x is 0
ß1: is coefficient of x i.e. variation in y with change in value of x
x: Variables that affects value of y i.e. already know variable whose effect we want to se on values of y
In [6]:
lm = smf.ols(formula="Weight ~ Height + Gender",data=df).fit()
In [7]:
lm.params
Out[7]:
In [ ]:
given_height= input("What's your height")
In [8]:
given_gender= input('Male or Famale')
In [12]:
def weight_calculator(my_height, my_gender):
Intercept= -244.923503
Male= 19.377711 #add to males
Slope= 5.976941
if my_gender == 'Male':
return (Intercept + Male + (Slope * float(my_height)))
else:
return (Intercept + (Slope * float(my_height)))
In [13]:
weight_calculator(73.847017, 'Male')
Out[13]:
In [14]:
weight_calculator(73.847017, 'Female')
Out[14]:
In [ ]: