我有数据矩阵X
,我适合线性模型,尤其是ransac = linear_model.RANSACRegressor()
。
我发现系数为:
coef = ransac.estimator_.coef_
但是,在计算之后,它应该始终为正值
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