Understanding matrix factorization for recommendation
http://nicolas-hug.com/blog/matrix_facto_4
import numpy as np import surprise # run 'pip install scikit-surprise' to install surprise from surprise.model_selection import cross_validate class MatrixFacto(surprise.AlgoBase): '''A basic rating prediction algorithm based on matrix factorization.''' def __init__(self, learning_rate, n_epochs, n_factors): self.lr = learning_rate # learning rate for SGD self.n_epochs = n_epochs # number of iterations of SGD self.n_factors = n_factors # number of factors def fit(self, trainset): '''Learn the vectors p_u and q_i with SGD''' print('Fitting data with SGD...') # Randomly initialize the user and item factors. p = np.random.normal(0, .1, (trainset.n_users, self.n_factors)) q = np.random.normal(0, .1, (trainset.n_items, self.n_factors)) # SGD procedure for _ in range(self.n_epochs): for u, i, r_ui in trainset.all_ratings(): err = r_ui - np.dot(p[u], q[i]) # Update vectors p_u and q_i p[u] += self.lr * err * q[i] q[i] += self.lr * err * p[u] # Note: in the update of q_i, we should actually use the previous (non-updated) value of p_u. # In practice it makes almost no difference. self.p, self.q = p, q self.trainset = trainset def estimate(self, u, i): '''Return the estmimated rating of user u for item i.''' # return scalar product between p_u and q_i if user and item are known, # else return the average of all ratings if self.trainset.knows_user(u) and self.trainset.knows_item(i): return np.dot(self.p[u], self.q[i]) else: return self.trainset.global_mean # data loading. We'll use the movielens dataset (https://grouplens.org/datasets/movielens/100k/) # it will be downloaded automatically. data = surprise.Dataset.load_builtin('ml-100k') #data.split(2) # split data for 2-folds cross validation algo = MatrixFacto(learning_rate=.01, n_epochs=10, n_factors=10) #surprise.evaluate(algo, data, measures=['RMSE']) cross_validate(algo, data, measures=['RMSE', 'MAE'], cv=5, verbose=True)
Understanding matrix factorization for recommendation的更多相关文章
- Matrix Factorization SVD 矩阵分解
Today we have learned the Matrix Factorization, and I want to record my study notes. Some kownledge ...
- 关于NMF(Non-negative Matrix Factorization )
著名的科学杂志<Nature>于1999年刊登了两位科学家D.D.Lee和H.S.Seung对数学中非负矩阵研究的突出成果.该文提出了一种新的矩阵分解思想――非负矩阵分解(Non-nega ...
- Matrix Factorization, Algorithms, Applications, and Avaliable packages
矩阵分解 来源:http://www.cvchina.info/2011/09/05/matrix-factorization-jungle/ 美帝的有心人士收集了市面上的矩阵分解的差点儿全部算法和应 ...
- 机器学习技法:15 Matrix Factorization
Roadmap Linear Network Hypothesis Basic Matrix Factorization Stochastic Gradient Descent Summary of ...
- 《Non-Negative Matrix Factorization for Polyphonic Music Transcription》译文
NMF(非负矩阵分解),由于其分解出的矩阵是非负的,在一些实际问题中具有非常好的解释,因此用途很广.在此,我给大家介绍一下NMF在多声部音乐中的应用.要翻译的论文是利用NMF转录多声部音乐的开山之作, ...
- 机器学习技法笔记:15 Matrix Factorization
Roadmap Linear Network Hypothesis Basic Matrix Factorization Stochastic Gradient Descent Summary of ...
- Non-negative Matrix Factorization 非负矩阵分解
著名的科学杂志<Nature>于1999年刊登了两位科学家D.D.Lee和H.S.Seung对数学中非负矩阵研究的突出成果.该文提出了一种新的矩阵分解思想――非负矩阵分解(Non-nega ...
- 【RS】Sparse Probabilistic Matrix Factorization by Laplace Distribution for Collaborative Filtering - 基于拉普拉斯分布的稀疏概率矩阵分解协同过滤
[论文标题]Sparse Probabilistic Matrix Factorization by Laplace Distribution for Collaborative Filtering ...
- 【RS】List-wise learning to rank with matrix factorization for collaborative filtering - 结合列表启发排序和矩阵分解的协同过滤
[论文标题]List-wise learning to rank with matrix factorization for collaborative filtering (RecSys '10 ...
随机推荐
- 【GStreamer开发】GStreamer基础教程06——媒体格式和pad的Capabilities
目标 Pad的Capabilities是一个GStreamer element的基础,因为framework大部分时间是自动处理的,所以我们几乎感觉不到它的存在.本教程比较偏向原理,介绍了 ...
- ffmpeg.编译(20191129)
1.一步步实现windows版ijkplayer系列文章之一——Windows10平台编译ffmpeg 4.0.2,生成ffplay - HarlanC - 博客园.html(https://www. ...
- Eclipse+TestNG搭建接口自动化测试框架
一.环境安装 1.前提 安装好jdk 配置好Java环境变量 安装Eclips 这些网上都有,就不再详细介绍. 资源分享链接:http://pan.baidu.com/s/1v9Fw6 2.安装Tes ...
- Eureka 源码分析
启动server服务,或者发现服务都使用了@EnableDiscoveryClient注解和eureka.instance.client.service-url.defaultZone /** * A ...
- java8 : 流
package day02.com.offcn.test; import java.io.IOException; import java.nio.charset.Charset; import ja ...
- 长乐培训Day9
T1 立方数 题目 [题目描述] 作为XX战队的狂热粉丝,MdZzZZ看到了自己心仪的队伍在半决赛落败,顿时心灰意冷.看着自己手中的从黄牛那里抢来的天价总决赛门票,MdZzZZ觉得去鸟巢已经没有意义了 ...
- Linux的常用命令及快捷键
常用快捷键 1 终端中的快捷键 ctrl+a 回到行首,ctrl+e回到行尾 ctrl+n 代码候选 常用命令
- golang 管理 pidfile
Pidfile 存储了进程的进程 id.一般情况下 pidfile 有以下几个作用: 其他进程可以读取 pidfile 获取运行进程的 pid(当然也可以通过其他命令 动态获取) 在启动进程前先检查 ...
- 谷歌chrome浏览器提示“喔唷 崩溃啦”的解决方案
原因分析:有可能是注册列表被一些卫士类优化工具或杀毒软件优化了. 解决方案:1. 卸载谷歌浏览器. ①开始→控制面板→添加或删除程序→找到谷歌浏览器卸载(卸载时勾选删除数据) ② 进入注册列表删除谷歌 ...
- Python通用爬虫,聚焦爬虫概念理解
通用爬虫:百度.360.搜狐.谷歌.必应....... 原理: (1)抓取网页 (2)采集数据 (3)数据处理 (4)提供检索服务 百度爬虫:Baiduspider 通用爬虫如何抓取新网站? (1)主 ...