找到线性预测的置信区间:numpy乘法误差

时间:2018-08-25 20:11:36

标签: python linear-regression confidence-interval

我有数据矩阵X,我适合线性模型,尤其是ransac = linear_model.RANSACRegressor()

我发现系数为: coef = ransac.estimator_.coef_

现在,我正在尝试查找预测的置信区间,因此我需要计算: enter image description here

但是,在计算之后,它应该始终为正值

c = np.ones(X.shape[2]) # a vector of ones
XTX = np.matmul(np.transpose(np.matrix(X)), np.matrix(X))
# find the bit inside square root
np.matmul( np.matmul(np.transpose(c),np.linalg.inv(XTX) ) ,  c.reshape((c.shape[0],1)) )

但是,这是一个负值,甚至不可能...我该如何解决这个问题?

分步细分:

c = X[0]
c = np.reshape(c , (c.shape[0],1))
ct = np.reshape(c , (1, c.shape[0]))
XTX = np.matmul(np.transpose(np.matrix(X)), np.matrix(X))
XTXinv = np.linalg.inv(XTX)
XTXinvc = np.matmul(XTXinv, c)
ctXTXinvc = np.matmul(ct, XTXinvc)
# ctXTXinvc is negative

0 个答案:

没有答案