Apollo
Apollo

Reputation: 9054

Access y-intercept in multiple regression using scikitlearn

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?

Upvotes: 0

Views: 53

Answers (1)

Dthal
Dthal

Reputation: 3316

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

Upvotes: 1

Related Questions