Attribute error: 'function' object has no attribute 'summary'

Attribute error: 'function' object has no attribute 'summary'

我试图在多元线性回归的后向消除法中得到总结并得到错误。

这是我出错的代码。

X_opt = X[:, [0,1,2,3,4,5]]
regressor_OLS = sm.OLS(endog=Y, exog=X_opt).fit
regressor_OLS.summary()
AttributeError     Traceback (most recent call last)
<ipython-input-26-c8a038cdb955> in <module>
----> 1 regressor_OLS.summary()

AttributeError: 'function' object has no attribute 'summary'

它应该只是 return 回归量的 table 但它显示错误。

您可以通过两种不同的方式解决:

regressor_OLS = sm.OLS(endog=Y, exog=X_opt)
results = regressor_OLS.fit()

或:

regressor_OLS = sm.OLS(endog=Y, exog=X_opt).fit()

希望对你有所帮助:)