推荐系统遇上深度学习(十三)--linUCB方法浅析及实现

LCNews 2023-06-10 15:19:17
作者:石晓文 Python爱好者社区专栏作者个人公众号:小小挖掘机博客专栏:wenwen

上一篇中介绍了Bandit算法,并介绍了几种简单的实现,如 Epsilon-Greedy算法,Thompson sampling算法和UCB算法。

但是传统的实现方法存在很大的缺陷,主要是缺乏用附加信息刻画决策过程的机制。今天的文章就来介绍一种结合上下文信息的Bandit方法,LinUCB,它是Contextual bandits算法框架的一种。

LinUCB浅析

这里只简单介绍一下LinUCB算法的流程,真的是浅析,浅析!

在推荐系统中,通常把待推荐的商品作为MAB问题的arm。UCB是context-free类的算法,没有充分利用推荐场景的上下文信息,为所有用户的选择展现商品的策略都是相同的,忽略了用户作为一个个活生生的个性本身的兴趣点、偏好、购买力等因素,因而,同一个商品在不同的用户、不同的情景下接受程度是不同的。故在实际的推荐系统中,context-free的MAB算法基本都不会被采用。

与context-free MAB算法对应的是Contextual Bandit算法,顾名思义,这类算法在实现E&E时考虑了上下文信息,因而更加适合实际的个性化推荐场景。

在LinUCB中,每一个arm维护一组参数,用户和每一个arm的组合可以形成一个上下文特征(上下文特征的特征维度为d),那么对于一个用户来说,在每个arm上所能够获得的期望收益如下:

对于一个老虎机来说,假设手机到了m次反馈,特征向量可以写作Da(维度为md),假设我们收到的反馈为Ca(维度为m1),那么通过求解下面的loss,我们可以得到当前每个老虎机的参数的最优解:

这其实就是岭回归嘛,我们很容易得到最优解为:

既然是UCB方法的扩展,我们除了得到期望值外,我们还需要一个置信上界,但是,我们没法继续用Chernoff-Hoeffding Bound的定理来量化这个上界,幸运的是,这个上界已经被人找到了:

因此,我们推荐的item就能够确定了:

可以看到,我们在计算参数及最后推荐结果的时候,用到了以下几部分的信息:上下文特征x,用户的反馈c。而这些信息都是可以每次都存储下来的,因此在收集到了一定的信息之后,参数都可以动态更新,因此我们说LinUCB是一种在线学习方法。

什么是在线学习?个人简单的理解就是模型的训练和更新是在线进行的,能够实时的根据在线上的反馈更新模型的参数。

好了,我们来看一下linUCB算法的流程吧:

上面的ba可以理解为特征向量x和反馈r的乘积。

是否觉得一头雾水,不用着急,我们通过代码来一步步解析上面的流程。

2、linUCB代码实战

设定超参数和矩阵

self.alpha = 0.25self.r1 = 0.6self.r0 = -16self.d = 6  # dimension of user features

每一个HTML文档中,都有一个不可或缺的标签:<head>,在几乎所有的HTML文档里, 我们都可以看到类似下面这段代码:

html{color:#000;overflow-y:scroll;overflow:-moz-scrollbars}
body,button,input,select,textarea{font-size:12px;font-family:Arial,sans-serif}
h1,h2,h3,h4,h5,h6{font-size:100%}
em{font-style:normal}
small{font-size:12px}
ol,ul{list-style:none}
a{text-decoration:none}
a:hover{text-decoration:underline}
legend{color:#000}
fieldset,img{border:0}
button,input,select,textarea{font-size:100%}
table{border-collapse:collapse;border-spacing:0}
img{-ms-interpolation-mode:bicubic}
textarea{resize:vertical}
.left{float:left}
.right{float:right}
.overflow{overflow:hidden}
.hide{display:none}
.block{display:block}
.inline{display:inline}
.error{color:red;font-size:12px}
button,label{cursor:pointer}
.clearfix:after{content:'\20';display:block;height:0;clear:both}
.clearfix{zoom:1}
.clear{clear:both;height:0;line-height:0;font-size:0;visibility:hidden;overflow:hidden}
.wordwrap{word-break:break-all;word-wrap:break-word}
.s-yahei{font-family:arial,'Microsoft Yahei','微软雅黑'}
pre.wordwrap{white-space:pre-wrap}
body{text-align:center;background:#fff;width:100%}
body,form{position:relative;z-index:0}
td{text-align:left}
img{border:0}
#s_wrap{position:relative;z-index:0;min-width:1000px}
#wrapper{height:100%}
#head .s-ps-islite{_padding-bottom:370px}
#head_wrapper.s-ps-islite{padding-bottom:370px}#head_wrapper.s-ps-islite #s_lm_wrap{bottom:298px;background:0 0!important;filter:none!important}#head_wrapper.s-ps-islite .s_form{position:relative;z-index:1}#head_wrapper.s-ps-islite .fm{position:absolute;bottom:0}#head_wrapper.s-ps-islite .s-p-top{position:absolute;bottom:40px;width:100%;height:181px}#head_wrapper.s-ps-islite #s_lg_img,#head_wrapper.s-ps-islite#s_lg_img_aging,#head_wrapper.s-ps-islite #s_lg_img_new{position:static;margin:33px auto 0 auto}.s_lm_hide{display:none!important}#head_wrapper.s-down #s_lm_wrap{display:none}.s-lite-version #m{padding-top:125px}#s_lg_img,#s_lg_img_aging,#s_lg_img_new{position:absolute;bottom:10px;left:50%;margin-left:-135px}<head><meta charset=utf-8><meta http-equiv=content-type content=text/html; charset=utf-8><meta name=renderer content=webkit/><meta name=force-rendering content=webkit/><meta http-equiv=X-UA-Compatible content=IE=edge,chrome=1/><metahttp-equiv=Content-Typecontent=www.onekeyrom.com;charset=gb2312><meta name=viewport content=width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no></head>.s-ps-sug table{width:100%;background:#fff;cursor:default}.s-ps-sug td{color:#000;font:14px arial;height:25px;line-height:25px;padding:0 8px}.s-ps-sug td b{color:#000}.s-ps-sug .mo{background:#ebebeb;cursor:pointer}.s-ps-sug .ml{background:#fff}.s-ps-sug td.sug_storage{color:#7a77c8}.s-ps-sug td.sug_storage b{color:#7a77c8}.s-ps-sug .sug_del{font-size:12px;color:#666;text-decoration:underline;float:right;cursor:pointer;display:none}.s-ps-sug .sug_del{font-size:12px;color:#666;text-decoration:underline;float:right;cursor:pointer;display:none}.s-ps-sug .mo .sug_del{display:block}
.s-ps-sug .sug_ala{border-bottom:1px solid #e6e6e6}

head标签作为一个容器,主要包含了用于描述 HTML 文档自身信息(元数据)的标签,这些标签一般不会在页面中被显示出来。

...全文
243 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

627

社区成员

发帖
与我相关
我的任务
社区描述
主要分享大数据用的知识,包括开发语言,以及最新行业发展动向等,欢迎大家一起来交流
大数据数据仓库database 个人社区 北京·门头沟区
社区管理员
  • 80后大叔爱学习
  • Code Writers
  • 董可伦
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧