这篇文章是如何使用几种不同的矩阵分解算法计算相关艺术家。最近我们被客户要求撰写关于的矩阵分解法推荐系统研究报告,包括一些图形和统计输出。代码用Python编写,以交互方式可视化结果。
加载数据
这可以使用Pandas加载到稀疏矩阵中:
# read in triples of user/artist/playcount from the input datasetdata = pandas.read_table("usersha1-artmbid-artname-plays.tsv",
usecols=[0, 2, 3],
names=['user', 'artist', 'plays'])# map each artist and user to a unique numeric valuedata['user'] = data['user'].astype("category")data['artist'] = data['artist'].astype("category")# create a sparse matrix of all the artist/user/play triplesplays = coo_matrix((data['plays'].astype(float),
(data['artist'].cat.codes,
data['user'].cat.codes)))
这里返回的矩阵有300,000名艺术家和360,000