解析 - 多元回归OLS班级

2024-10-01 09:27:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我在调整方程时遇到了问题 y=b0+b1x1+b2x2

代码:

xs = numpy.loadtxt('teste.csv', skiprows=1, dtype=float, delimiter=';', 
     usecols=(0,1))

y = log(xs[:,0])
x = 1/xs[:,1]
x2 = (1/xs[:,1])**2

mymodel = ols.ols(y,x,'y',['x1', 'x2'])
mymodel.summary()`

我有个错误:

print '''% -5s          % -5.6f     % -5.6f     % -5.6f     % -5.6f''' % tuple([self.x_varnm[i],self.b[i],self.se[i],self.t[i],self.p[i]])
IndexError: index out of bounds

有人能帮我吗?你知道吗


Tags: csv代码selfnumpyb0mymodel方程x2
1条回答
网友
1楼 · 发布于 2024-10-01 09:27:03

尝试将x定义为:

x = 1/xs[:,1:2] # slice to keep (n, 1) shape
x2 = (1/xs[:,1:2])**2
x = np.hstack((x, x2))

您告诉ols期望x有一个两列的矩阵,但是传入了一个,因此出现了错误。你知道吗

相关问题 更多 >