Assignment 1

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

In [20]:
df = pd.read_csv("data/heights_weights_genders.csv")

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

In [22]:
lm.params


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

In [23]:
#Getting the parameters:
intercept, height = lm.params

In [37]:
#Testing my formula:
#example_Height = 60

In [38]:
weight = height*example_Height+intercept

In [39]:
weight


Out[39]:
112.30006663498375

In [54]:
users_height = int(input('Please enter your height in inches: '))
weight = height*users_height+intercept
print('You are approximately', round(weight), "pounds, which is", round(weight * 0.453592), 'kg.')


Please enter your height in inches: 78
You are approximately 251.0 pounds, which is 114.0 kg.

In [ ]:


In [ ]: