我已经训练了一个线性回归模型来进行多输出预测。这是一个时间序列预测问题,根据一组输入来估计未来12个月的需求。在过去,如果我只预测一个输出值,我会简单地调用以下代码来访问模型的Beta系数:
model = LinearRegression()model.fit(X, Y)weights = pd.DataFrame(regression.coef_, X.columns, columns=['Coefficients'])print(weights)
然而,当我为一个多输出模型运行这段代码时,我得到了以下错误:
'MultiOutputRegressor' object has no attribute 'coef_'
如何访问多输出线性模型的系数?
回答:
因为它是一个MultiOutputRegressor对象,每个估计器都有自己的coef_。你可以通过访问属性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'])