Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Coding Mechanics
#4
(Dec-02-2020, 11:30 AM)321brian Wrote: I don't pass anything into that method to tell it to make that connection, but somehow it knows what Y is. Prior to the method call, I set the column set to a variable called Y. But I don't pass that variable value to the ols method. So how does the code inside the method know what Y is?
But you bind name Y to column fat['body_fat_percent'] on line 7!
It uses patsy as language to describe the model. It parse the string 'Y ~ triceps_skinfold_thickness_mm + midarm_circumference_cm + thigh_circumference_cm' and uses the name Y you defined as well as the other columns from fat DataFrame.

If you prefer you can drop line 7 and just use
model = sms.ols('body_fat_percent ~ triceps_skinfold_thickness_mm + midarm_circumference_cm + thigh_circumference_cm', data = fat).fit()
Here's again the link to patsy package docs: https://patsy.readthedocs.io/en/latest/
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

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