我正在尝试制作一个简单的线性回归函数,但继续遇到
numpy.linalg.linalg.LinAlgError:奇异矩阵错误
现有功能(带调试打印):
def makeLLS(inputData, targetData):
print "In makeLLS:"
print " Shape inputData:",inputData.shape
print " Shape targetData:",targetData.shape
term1 = np.dot(inputData.T, inputData)
term2 = np.dot(inputData.T, targetData)
print " Shape term1:",term1.shape
print " Shape term2:",term2.shape
#print term1
#print term2
result = np.linalg.solve(term1, term2)
return result
带有我的测试数据的控制台输出是:
In makeLLS:
Shape trainInput1: (773, 10)
Shape trainTargetData: (773, 1)
Shape term1: (10, 10)
Shape term2: (10, 1)
然后它在 linalg.solve 行上出错。这是一个教科书线性回归函数,我似乎无法弄清楚它为什么会失败。
什么是奇异矩阵误差?