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 [24]:
import pandas as pd
%matplotlib inline
import matplotlib.pyplot as plt
import statsmodels.formula.api as smf

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

In [26]:
df.columns


Out[26]:
Index(['Gender', 'Height', 'Weight'], dtype='object')

In [27]:
df[df['Gender']=='Male'].plot(kind="scatter",x="Height",y="Weight")


Out[27]:
<matplotlib.axes._subplots.AxesSubplot at 0x10afbb710>

In [28]:
df[df['Gender']=='Female'].plot(kind="scatter",x="Height",y="Weight")


Out[28]:
<matplotlib.axes._subplots.AxesSubplot at 0x10b2cb3c8>

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

In [30]:
lm.params


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

In [31]:
intercept, slope = lm.params

In [32]:
df.plot(kind="scatter",x="Height",y="Weight")
plt.plot(df["Height"],slope*df["Height"]+intercept,"-",color="red")


Out[32]:
[<matplotlib.lines.Line2D at 0x10b43b5c0>]

In [33]:
def predict_weight(input_height): 
    return (slope*input_height)+intercept

In [34]:
predict_weight(68)


Out[34]:
174.03836776126673