# Model based Collaborative Filtering implemented with Tensorflow
Main recommend system algorithms are listed below.
## 1. Collaborative filtering
### based on neighbors
- based on user
- based on item
idea: find the top similar user/item, recommend what they related with weight(similarity)
### **based on models**
**what this repo implementes**
idea: user/item matrix decomposition, with **feature dim**
## Content based recommend algorithm
With all item features know, find the relationship bewteen user and features, based on user's behavior history.
Different from neighbor based collaborative filtering algorithm. Content based recommend algorithm **take user behavior history into consideration**, while neighbor based collaborative filtering algorithm ignore this.
## Hybrid algorithm
Combine collaborative filtering and content based recommend algorithm, diminishes the shortage of each algorithm. It works like making recommend from each algorithm, and combine them with weights.
# 2. Implementation
## Preprocessing
load the MovieLens 100K Dataset, parse, devide into train/validation dataset, transform to a USER\_NUM \* MOVIE\_NUM matrix with train dataset, ie `train_matrix` in code.
## Tensor Initialization
Set up `tf_train_matrix`, `tf_user_features`, `tf_item_features` tensor, which could be understood as:
```
tf_train_matrix = tf_user_features * tf_item_features.T
```
## Loss Definition
In one word, `train_loss`, which is the training objective, is defined as,
```
train_loss = 0.1 * train_diff_loss + 0.1 * train_user_loss + 0.1 * train_item_loss
```
`train_user_loss` and `train_item_loss` are the regulation terms, root/sum/square of the tf\_user\_features and tf\_item\_features, which prevents overfitting.
`train_diff_loss` is the root squared error of `tf_train_matrix` and `tf_user_features * tf_item_features.T`. You might notice that tf_train_matrix doesn't cover all, since it
s quite common(even mostly) that some users didn't see some movies. So These blanks are fill with the average rating of this movie. If nobody see this movie, rating it 3.
Their weights are all equal, 0.1, which is empirical and observation. Why not all 1, because I want loss smaller which makes me feel good. Big loss is always scary, isn't it?
## Evaluation
### Average Abs Error
`train_avg_dist` and `val_avg_dist` means the average abs rating error between prediction and ground truth.
### Accuracy
`train_equal_num`, `train_equal_ratio`, `val_equal_num`, `val_equal_ratio` stands for the right prediction num and it's ratio of train/test dataset.
## Training
It won't take too much time. I set a lot of scalars to watch in Tensorboard during training. Names of scalars need well organized to utilize the group scalar in Tensorboard.
## Result
The best accuracy is 33.59%, the best average abs error is 0.9294 before overfitting, which means 1/3 prediction are right, and average prediction is 1 rating distance from ground truth, seems to be acceptable in suggestion area.
<img src='./assets/eva-dist.png'>
<img src='./assets/eva-equal.png'>
没有合适的资源?快使用搜索试试~ 我知道了~
基于模型的协同过滤算法的纯TensorFlow实现.zip
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共5个文件
png:2个
md:1个
ipynb:1个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
需积分: 5 0 下载量 136 浏览量
2024-05-19
21:56:10
上传
评论
收藏 267KB ZIP 举报
温馨提示
协同过滤算法(Collaborative Filtering)是一种经典的推荐算法,其基本原理是“协同大家的反馈、评价和意见,一起对海量的信息进行过滤,从中筛选出用户可能感兴趣的信息”。它主要依赖于用户和物品之间的行为关系进行推荐。 协同过滤算法主要分为两类: 基于物品的协同过滤算法:给用户推荐与他之前喜欢的物品相似的物品。 基于用户的协同过滤算法:给用户推荐与他兴趣相似的用户喜欢的物品。 协同过滤算法的优点包括: 无需事先对商品或用户进行分类或标注,适用于各种类型的数据。 算法简单易懂,容易实现和部署。 推荐结果准确性较高,能够为用户提供个性化的推荐服务。 然而,协同过滤算法也存在一些缺点: 对数据量和数据质量要求较高,需要大量的历史数据和较高的数据质量。 容易受到“冷启动”问题的影响,即对新用户或新商品的推荐效果较差。 存在“同质化”问题,即推荐结果容易出现重复或相似的情况。 协同过滤算法在多个场景中有广泛的应用,如电商推荐系统、社交网络推荐和视频推荐系统等。在这些场景中,协同过滤算法可以根据用户的历史行为数据,推荐与用户兴趣相似的商品、用户或内容,从而提高用户的购买转化率、活跃度和社交体验。 未来,协同过滤算法的发展方向可能是结合其他推荐算法形成混合推荐系统,以充分发挥各算法的优势。
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 5 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/d7864c98224046ec9a7f43fa6207c84e_qq_51320133.jpg!1)
生瓜蛋子
- 粉丝: 3872
- 资源: 6140
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)