0

I've followed the accepted answer in this post:

Multiple linear regression in Python

In the comments, it mentions how to fit the line with a constant term (y-intercept). How do I access this?

Community
  • 1
  • 1
Apollo
  • 8,874
  • 32
  • 104
  • 192

1 Answers1

1

After you fit the model, the intercept is available as model.intercept_. Here is an example:

# Example that should have intercept of 1
x = np.random.rand(10,3)
y = 1 + x.dot([1,2,3]) + 0.05 * np.random.rand(10)
lr.fit(x, y)
lr.coef_
>> array([ 1.01701958,  2.00951304,  3.00504058])
lr.intercept_
>> 0.99952789780697682
Dthal
  • 3,216
  • 1
  • 16
  • 10