我试着预测c,下面的代码,我收到了错误:
import statsmodels.api as sm
a=[1,2,3,4,5,6,7,8,9,10]
b=[2,4,6,8,10,12,14,16,18,20]
model=sm.OLS(a,sm.add_constant(b)).fit()
c=[200]
c=sm.add_constant(c)
print (model.predict(c))
ValueError:形状(1,1)和(2,)未对齐:1(暗淡1)!= 2(暗淡0)
如果我把C = [2,200],我可以成功地预测数字,但是,当我只是输入一个值时我得到错误。我可以预测一个值吗?
答案 0 :(得分:0)
c不应该是矢量,因为它是标量。您正在尝试预测c的相应Y值,代码应为:
import statsmodels.api as sm
a=[1,2,3,4,5,6,7,8,9,10]
b=[2,4,6,8,10,12,14,16,18,20]
model=sm.OLS(a,sm.add_constant(b)).fit()
c=200
print (model.predict(c))