Phase4.py 文件源码

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

项目:Collaborative-Filtering-recommendation 作者: LunaBlack 项目源码 文件源码
def userSim(data_matrix):
    n = np.shape(data_matrix)[0]  # ?userNum
    userSimArr = np.zeros(shape=(n, n))  # ???????????????,???

    for i in range(n):
        for j in range(i+1, n):
            overLap = np.nonzero(np.logical_and(data_matrix[i, :]>0, data_matrix[j, :]>0))[0]
            if len(overLap) > 1:
                sim = computeSim(data_matrix[i, overLap], data_matrix[j, overLap])
            else:
                sim = 0
            userSimArr[i][j] = sim
            userSimArr[j][i] = sim

    userSimArr = np.nan_to_num(userSimArr)
    return userSimArr


# ?????????
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号