AttributeError:“函数”对象没有属性“摘要”

时间:2019-06-09 09:39:49

标签: python python-3.x linear-regression statsmodels

我正在运行线性回归,并且得到'summary'的attributeError。

我正在使用Windows操作系统python 3.7

y=dataset
X=dataset [['A'] + ['B'] + ['C'] + ['D'] + ['E']]
X1 = sm.add_constant(X)
model = sm.OLS(endog = y, exog = X)
results = model.fit
results.summary()
  

AttributeError:“函数”对象没有属性“摘要”

1 个答案:

答案 0 :(得分:1)

来自statsmodels OLS example

import numpy as np

import statsmodels.api as sm

# Artificial data:
nsample = 100
x = np.linspace(0, 10, 100)
X = np.column_stack((x, x**2))
beta = np.array([1, 0.1, 10])
e = np.random.normal(size=nsample)

# Our model needs an intercept so we add a column of 1s:
X = sm.add_constant(X)
y = np.dot(X, beta) + e

# Fit and summary:
model = sm.OLS(y, X)
results = model.fit()

print(results.summary())

print('Parameters: ', results.params)
print('R2: ', results.rsquared)

在您的情况下,results = model.fit必须为results = model.fit()