【发布时间】:2020-02-13 12:13:23
【问题描述】:
我正在尝试使用 SVD 根据购买情况进行图书推荐。我正在使用一个矩阵,其中列是书籍,行是用户名和内容,如果他/她购买了有问题的书(如果用户购买了则为 1,如果他没有购买则为 0 [我不知道是否这是最好的选择])。 我还创建了一个 cosine_similarity 矩阵,我可以在其中根据用户的购买情况查看用户之间的相似度。
# Matrix with users as rows, products as columns and count as content
df_matrix = pd.pivot_table(order_df, values='count', index='username', columns='product')
# Replace all NaN contents with 0
df_matrix_dummy = df_matrix.copy().fillna(0)
#Compute the cosine similarity matrix using the dummy matrix
cosine_sim = cosine_similarity(df_matrix_dummy, df_matrix_dummy)
#Convert into pandas dataframe
cosine_sim = pd.DataFrame(cosine_sim, index=df_matrix.index, columns=df_matrix.index)
reader = Reader()
# Famous SVD algorithm
algo = SVDpp()
data = Dataset.load_from_df(order_df[['username', 'product', 'count']], reader)
# Divide the data into train and test (80-20)
trainset, testset = train_test_split(data, test_size=0.2)
algo.train(trainset)
由于我是这种技术的新手,我的问题是如何在训练 SVD 后获得推荐列表。
【问题讨论】:
标签: python python-2.7 machine-learning svd recommender-systems