In [1]:
import pandas as pd
In [5]:
import statsmodels.formula.api as smf
In [2]:
df = pd.read_csv("heights_weights_genders.csv")
In [3]:
df.head()
Out[3]:
In [7]:
lm = smf.ols(formula="Weight~Height",data=df).fit()
In [8]:
lm.params
Out[8]:
Here:
y: is the variable that we want to predict
ß0: is intercept of the regression line i.e. value of y when x is 0
ß1: is coefficient of x i.e. variation in y with change in value of x
x: Variables that affects value of y i.e. already know variable whose effect we want to se on values of y
In [29]:
given_height= input("What's your height")
In [30]:
given_height
Out[30]:
In [33]:
predicted_weight = -350.737192 + (7.717288 * float(given_height))
In [34]:
predicted_weight
Out[34]:
In [ ]:
def weight_calculator(my_height):
return (-350.737192 + (7.717288 * float(my_height)))
In [36]:
df['predicted_weight'] = df['Height'].apply(weight_calculator)
In [37]:
df
Out[37]:
In [ ]: