LinearRegressionTest.py 文件源码

python
阅读 38 收藏 0 点赞 0 评论 0

项目:MachineLearningAlgorithm 作者: lining0806 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号