shadow_dev
shadow_dev

Reputation: 130

Access weights / coefficients of multi output Linear Regression model

I have trained a linear regression model to forecast in a multioutput fashion. This is a time series forecasting problem which estimates the next 12 months of demand based on a set of inputs. In the past - had I only been forecasting one output value - I would have simply called the following in order to access the beta coefficients of the model:

model = LinearRegression()
model.fit(X, Y)
weights = pd.DataFrame(regression.coef_, X.columns, columns=['Coefficients'])
print(weights)

However, when I run this for a multioutput model, I get the error:

'MultiOutputRegressor' object has no attribute 'coef_'

How can I access the coefficients of a multi-output linear model?

Upvotes: 1

Views: 976

Answers (1)

Amine Benatmane
Amine Benatmane

Reputation: 1261

Since it's MultiOutputRegressor object, each estimator has it's own coef_. You can get the list of the estimators used for predictions by accessing attribute estimators_

m_lr=MultiOutputRegressor(LinearRegression())
m_lr.fit(X, Y)
...
for estimator in m_lr.estimators_:
    weights = pd.DataFrame(estimator.coef_, X.columns, columns=['Coefficients'])

Upvotes: 3

Related Questions