我正在运行线性回归,并且得到'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:“函数”对象没有属性“摘要”
答案 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()
。