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]:
In [3]:
df_men = df[df['Gender']=="Male"]
In [4]:
lm = smf.ols(formula="Weight~Height",data=df_men).fit()
lm.params
Out[4]:
In [5]:
df_women = df[df['Gender']=="Female"]
In [6]:
lm = smf.ols(formula="Weight~Height",data=df_women).fit()
lm.params
Out[6]:
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!")
In [ ]:
In [ ]: