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]:
In [27]:
df[df['Gender']=='Male'].plot(kind="scatter",x="Height",y="Weight")
Out[27]:
In [28]:
df[df['Gender']=='Female'].plot(kind="scatter",x="Height",y="Weight")
Out[28]:
In [29]:
lm = smf.ols(formula="Weight~Height",data=df).fit()
In [30]:
lm.params
Out[30]:
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]:
In [33]:
def predict_weight(input_height):
return (slope*input_height)+intercept
In [34]:
predict_weight(68)
Out[34]: