Dec-01-2020, 12:58 PM
I have the following code snippet below:
import pandas as pd import statsmodels.formula.api as sms fat = pd.read_csv('https://s3-us-west-2.amazonaws.com/static-resources.zybooks.com/fat.csv') # Response variable Y = fat['body_fat_percent'] # Generates the linear regression model # Multiple predictor variables are joined with + model = sms.ols('Y ~ triceps_skinfold_thickness_mm + midarm_circumference_cm + thigh_circumference_cm', data = fat).fit() # Prints a list of the fitted values for each sample print(model.fittedvalues)What I want to know is how Python knows to map the variable Y, which is set to a column in a dataframe in line 7, to the "Y" reference in the string in the ols method call on line 11. As far as I can tell, I am just setting Y and then doing nothing with it, but somehow Python knows to reference it in the method call.