Use the data from heights_weights_genders.csv to create a simple predictor that takes in a person's height and guesses their weight based on a model using all the data, regardless of gender. To do this, find the parameters (lm.params) 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
import statsmodels.formula.api as smf

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

In [13]:
df.head()


Out[13]:
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 [4]:
df.plot(kind="scatter",x="Height",y="Weight")


Out[4]:
<matplotlib.axes._subplots.AxesSubplot at 0x1157a3b38>

In [5]:
lm = smf.ols(formula="Weight~Height",data=df).fit()

In [6]:
lm.params


Out[6]:
Intercept   -350.737192
Height         7.717288
dtype: float64

In [7]:
def find_user_weight(user_height):
    user_weight = 7.7172876407853712 * float(user_height) - 350.737192
    return user_weight

In [ ]:
user_height = input("How tall are you in inches?: ")
find_user_weight(user_height)

In [ ]: