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_male=df[df['Gender']=='Male']
df_female=df[df['Gender']=='Female']
In [4]:
df_female.head()
Out[4]:
In [5]:
lm1 = smf.ols(formula="Weight~Height",data=df_male).fit()
In [9]:
intercept_male, slope_male = lm1.params
In [7]:
lm2 = smf.ols(formula="Weight~Height",data=df_female).fit()
In [10]:
intercept_female, slope_female = lm2.params
In [28]:
def predict_weight_gender():
input_gender=input("What's your gender?").upper()
input_height=int(input("What's your height?"))
if input_gender == 'MALE':
return (slope_male*input_height) + intercept_male
elif input_gender == 'FEMALE':
return (slope_female*input_height) + intercept_female
else:
print('Invalid inputs')
In [29]:
predict_weight_gender()
Out[29]: