'OLS' 对象没有属性 'summary'

'OLS' object has no attribute 'summary'

我将此问题发布给 运行 与我 运行 相同的问题:

当尝试像这样拟合我的数据并打印结果时:

import statsmodel.api as sm
model = sm.OLS(df['SalePrice'], df.drop(['SalePrice'], axis=1))
print(model.summary())

我收到以下错误:

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

解决方案是添加 .fit():

import statsmodel.api as sm
model = sm.OLS(df['SalePrice'], df.drop(['SalePrice'], axis=1)).fit()
print(model.summary())