1

我在用 ols 类调整方程 y = b 0 + b 1 x 1 + b 2 x 2时遇到问题

编码:

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

有人可以帮助我吗?

4

1 回答 1

1

尝试将您定义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,但传入的是一个单列矩阵,因此会出现错误。

于 2013-04-03T21:01:29.007 回答