【发布时间】:2020-12-12 22:03:35
【问题描述】:
import numpy as np
import statsmodels.api as sm
list21 = [-0.77, -0.625, -0.264, 0.888, 1.8, 2.411, 2.263, 2.23, 1.981, 2.708]
list23 = [-1.203, -1.264, -1.003, -0.388, -0.154, -0.129, -0.282, -0.017, -0.06, 0.275]
X1 = np.asarray(list21)
Y1 = np.asarray(list23)
x = X1.reshape(-1, 1)
y = Y1.reshape(-1, 1)
model = sm.OLS(x, y)
fit = model.fit()
y_pred = model.predict(x)
错误读作:
--> 161 y_pred = model.predict(x)
ValueError: shapes (10,1) and (10,1) not aligned: 1 (dim 1) != 499 (dim 0)
过去半小时我的头一直在撞墙,请帮忙。
【问题讨论】:
-
除此之外:statsmodels 要求将因变量或结果变量放在首位,即
OLS(y, x)
标签: python numpy statsmodels