def lwlr(testPoint, xMat, yMat, k=1.0):
m = np.shape(xMat)[0]
weights = np.matrix(np.eye(m)) # ??????
for j in range(m):
diffMat = testPoint-xMat[j, :]
weights[j, j] = np.exp(diffMat*diffMat.T/(-2.0*k**2)) # ???
print weights
xTx = xMat.T*(weights*xMat)
if np.linalg.det(xTx) == 0.0:
print 'This matrix is singular, cannot do inverse'
return
ws = xTx.I*(xMat.T*(weights*yMat))
return testPoint*ws
LinearRegressionTest.py 文件源码
python
阅读 38
收藏 0
点赞 0
评论 0
评论列表
文章目录