Shridhar R Kulkarni
Shridhar R Kulkarni

Reputation: 7063

Why is intercept_ an array in sklearn linear regression?

In sklearn linear regression, intercept_ returned is an array and not a scalar. Why so?

Other type of regressors, for example HuberRegressor allow intercept_ to be returned as scalar. So code consistency throughout the api should not be the reason.

Upvotes: 0

Views: 1423

Answers (1)

MaxU - stand with Ukraine
MaxU - stand with Ukraine

Reputation: 210832

I would rephrase your question as "why some algorithms return intercept_ as a scalar value?"

For multiple features we usually need multiple biases (intercepts) if we are talking about linear models...

In HuberRegressor the intercept is set explicitly to a scalar value:

if self.fit_intercept:
    self.intercept_ = parameters[-2]
else:
    self.intercept_ = 0.0
self.coef_ = parameters[:X.shape[1]]

Upvotes: 1

Related Questions