推荐系统算法-矩阵分解(MF)
Main Idea
每个user或item表示为K维向量,
分别组成user矩阵P和item矩阵Q,
令M为user与item交互矩阵。
使用FunkSVD方法进行矩阵分解:M = PQ
。
目标函数采用均方误差(MSE),使用梯度下降法优化。
参考:https://blog.csdn.net/qq_19446965/article/details/82079367
Environments
- python 3.8
- pytorch 1.70
Dataset
- Amazon(2014) http://jmcauley.ucsd.edu/data/amazon/links.html
- Yelp(2020) https://www.yelp.com/dataset
For example:
data/ratings_Digital_Music.csv
(Amazon Digital Music: rating only)
注:本实验将数据集按0.8/0.1/0.1的比例划分为训练集、验证集、测试集。
数据集前三列分别为用户id、产品id、评分(1~5)。
若使用json格式的amazon(或yelp)数据集,
可使用data_preprocess.py
预处理。
For example:
python data_preprocess.py --data_path Digital_Music_5.json --data_source amazon --save_file amazon_music_ratings.csv
Running
Train and evaluate the model
python main.py --dataset_file data/ratings_Digital_Music.csv
Experiment
Dataset | number of users | number of items | MSE | MSE of balanced test |
---|---|---|---|---|
movielens-small (100,836) | 610 | 9724 | 0.804585 | 1.879120 |
Amazon Digital Music small (64,706) | 5541 | 3568 | 0.900899 | 2.436231 |
Amazon Digital Music (836,006) | 478235 | 266414 | 0.875224 | 3.566706 |
Amazon Clothing, Shoes and Jewelry (5,748,919) | 3117268 | 1136004 | 1.512551 | 3.266632 |
Yelp (8,021,121) | 1968703 | 209393 | 2.171064 | 2.429343 |
*MSE of balanced test: 数据集划分时,验证集与测试集中,每个分值对应的样本数相等。
Analysis of Dataset
对数据集的评分分布进行了统计: