In [1]:
import pandas as pd
import statsmodels.formula.api as smf
import matplotlib.pyplot as plt
%matplotlib inline

In [2]:
df = pd.read_csv('heights_weights_genders.csv')
df.head()


Out[2]:
Gender Height Weight
0 Male 73.847017 241.893563
1 Male 68.781904 162.310473
2 Male 74.110105 212.740856
3 Male 71.730978 220.042470
4 Male 69.881796 206.349801

In [3]:
df_men = df[df['Gender']=="Male"]

In [4]:
lm = smf.ols(formula="Weight~Height",data=df_men).fit()
lm.params


Out[4]:
Intercept   -224.498841
Height         5.961774
dtype: float64

In [5]:
df_women = df[df['Gender']=="Female"]

In [6]:
lm = smf.ols(formula="Weight~Height",data=df_women).fit()
lm.params


Out[6]:
Intercept   -246.013266
Height         5.994047
dtype: float64

In [16]:
height_input = input('Please tell me your height in inches:')
if height_input <= "0":
    print("Something went wrong with data input. Please try again - and add in a value bigger than 0!")

else:
    gender_input = input('For a more accurate prediction, please tell me your gender [type M for male and F for Female]:')

    if gender_input == 'M':
        output = (5.961774 * int(height_input)) + (-224.498841)
        print("I guess your weight is approximately", output, "pounds.")
    if gender_input == 'F':
        output = (5.994047 * int(height_input)) + (-246.013266)
        print("I guess your weight is approximately", output, "pounds.")
    else:
        print("Something went wrong with data input. Please try again - remember to type M for male and F for female!")


Please tell me your height in inches:68
For a more accurate prediction, please tell me your gender [type M for male and F for Female]:F
I guess your weight is approximately 161.58193 pounds.

In [ ]:


In [ ]: