Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Coding Mechanics
#1
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.
Reply


Messages In This Thread
Coding Mechanics - by 321brian - Dec-01-2020, 12:58 PM
RE: Coding Mechanics - by buran - Dec-01-2020, 01:48 PM
RE: Coding Mechanics - by 321brian - Dec-02-2020, 11:30 AM
RE: Coding Mechanics - by buran - Dec-02-2020, 12:04 PM
RE: Coding Mechanics - by 321brian - Dec-02-2020, 12:45 PM
RE: Coding Mechanics - by buran - Dec-02-2020, 01:43 PM
RE: Coding Mechanics - by 321brian - Dec-03-2020, 12:01 PM
RE: Coding Mechanics - by buran - Dec-03-2020, 02:25 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020