/DeepCTR-1

Primary LanguagePython

dos2unix工具:windows下编辑过的文件在linux上可能会存在^M 符号, 在linux上直接调用dos2unix filename即可消除末尾的换行符号

可参考的离散化方法: round(log(x*x+1))

#pytorch dnn_ctr 参考链接 The framework to deal with ctr problem

details: https://zhuanlan.zhihu.com/p/32885978

FNN's introduction and api: https://zhuanlan.zhihu.com/p/33045184

PNN's introduction and api: https://zhuanlan.zhihu.com/p/33177517

DeepFM's introduction and api: https://zhuanlan.zhihu.com/p/33479030

AFM's introduction and api: https://zhuanlan.zhihu.com/p/33540686

NFM's introduction and api: https://zhuanlan.zhihu.com/p/33587540

DCN's introduction and api: https://zhuanlan.zhihu.com/p/33619389

短视频原始数据地址: local: zb2620 /data/code/douyinData hdfs: http://10.8.26.21:50070/explorer.html#/user/hadoop/icmechallenge2019

短视频/广告特征工程参考: https://zhuanlan.zhihu.com/p/38341881

  1. 对于uid这类特别稀疏的原始特征,不需要直接进行one-hot编码而导致特征维度急剧膨胀, 可以考虑通过对uid进行出现的样本数量统计,或者使用uid的转化率或者正样本数来对uid来进行表示
  2. 两两特征组合后,如果稀疏程度较高,也通过统计特征来进行压缩

推荐系统特征类型分类:

  1. 用户与视频的基本属性特征 1.1.类别变量 category_features = ['uid', 'user_city', 'item_id', 'author_id', 'item_city', 'channel', 'music_id', 'device', ] 高稀疏变量: uid, item_id, author_id, music_id, device 一般稀疏变量: user_city, item_city, channel

    1.2.连续变量

    continuous_features = ['time', 'duration_time'] # track2_time作品发布时间,作品时长

  2. 视频内容特征: 2.1 NLP title特征: (word, frequence) 2.2 视频人脸特征: gender, beauty, relative_position 2.3 音频特征: embedding向量,128维 2.4 视觉特征:

3.数据探索 3.1.各字段值个数 训练集中总记录数:19622340 各特征下值的个数如下: uid_distinct: 70711 user_city_distinct: 396 item_id_distinct: 3687157 author_id_distinct: 778113 item_city_distinct: 456 channel_distinct: 5 finish_distinct: 2 like_distinct: 2 music_id_distinct: 82840 device_distinct: 71681 其中:uid,user_city, item_id,author_id,item_city, music_id,device因值太多,用其统计学特征代替 uid的衍生特征:uid_playCnt---一个用户观看的视频数,表示uid本身的活跃程度 item_id的衍生特征: itemid_playCnt---每个视频被多少用户观看,表示item本身的受欢迎程度 author_id的衍生特征: authorid_Cnt---训练集中author出现的次数,代表作者本身的受欢迎程度 music_id的衍生特征: musicid_Cnt---训练集中music出现的次数,代表music_id的受欢迎程度 device的衍生特征:device_Cnt---训练集中device出现的次数

duration_time各区间记录数统计如下:
0,(0,60],(60,300],(300+)各区间记录数统计如下:224,19621510,383,223
300+视频,看下用户对它的一些点击行为情况,从以下数据中未看出异常,可能是duration_time列中存在脏数据
解决办法:1、舍弃duration_time 300+的视频
         2、将超过duration_time 300+的视频时长认为设定为300

+-----+---------+-------+---------+---------+-------+------+----+--------+------+-----------+-------------+ | uid|user_city|item_id|author_id|item_city|channel|finish|like|music_id|device| time|duration_time| +-----+---------+-------+---------+---------+-------+------+----+--------+------+-----------+-------------+ |29413| -1|3598380| 812434| 10| 2| 0| 0| 1022| 3682|53086717097| 70000| | 9238| 289|1985642| 129138| 141| 0| 0| 0| 972| 16293|53085903230| 571| |33265| -1|1985636| 280611| 11| 1| 0| 0| 272| 9168|53084556540| 564| |12661| -1|1985637| 93924| 3| 1| 0| 0| -1| 19370|53086274761| 480| |10429| 97|1985638| 794202| 17| 3| 1| 0| -1| 8628|53085855309| 555| |16766| 44|1985639| 368499| 88| 0| 0| 0| 12890| 51361|53086958883| 555| |39435| -1|1985640| 25553| -1| 1| 0| 0| -1| 40136|53081969555| 575| |32537| 18|1985641| 319548| 17| 0| 0| 0| 16234| 18553|53087022039| 595| |32318| 188|1985642| 129138| 141| 0| 0| 0| 972| 10588|53085903230| 571| | 370| 13| 640772| 443619| 75| 0| 0| 0| 468| 638|53087124356| 620| | 581| 108| 640773| 11233| 217| 0| 1| 0| -1| 12848|53087135138| 450| | 3483| 26| 640774| 754| 112| 0| 0| 0| -1| 59917|53087123508| 436| | 8196| 228| 640775| 641537| 66| 0| 0| 0| -1| 60336|53087111569| 613| | 8198| 248| 640776| 362561| 191| 0| 0| 0| 68| 33327|53087072689| 640| | 4054| 24| 640772| 443619| 75| 0| 0| 0| 468| 43300|53087124356| 620| |11959| 71| 640773| 11233| 217| 0| 0| 0| -1| 8977|53087135138| 450| | 9657| 140| 640773| 11233| 217| 0| 0| 0| -1| 5690|53087135138| 450| | 235| 21| 640772| 443619| 75| 0| 1| 0| 468| 30|53087124356| 620| | 1200| 159| 640774| 754| 112| 0| 1| 0| -1| 22911|53087123508| 436| | 9555| 237| 640774| 754| 112| 0| 1| 0| -1| 9309|53087123508| 436| | 165| 91| 640774| 754| 112| 0| 0| 0| -1| 5356|53087123508| 436| | 3710| 43| 640774| 754| 112| 0| 0| 0| -1| 1968|53087123508| 436| | 3090| 25| 640773| 11233| 217| 0| 0| 0| -1| 6831|53087135138| 450| |12309| 70| 640774| 754| 112| 0| 1| 0| -1| 4660|53087123508| 436| | 2928| 228| 640774| 754| 112| 0| 1| 0| -1| 50765|53087123508| 436| | 1422| 18| 640773| 11233| 217| 0| 0| 0| -1| 21734|53087135138| 450| | 4115| 68| 640774| 754| 112| 0| 1| 0| -1| 10361|53087123508| 436| | 4351| 322| 640774| 754| 112| 0| 1| 0| -1| 41114|53087123508| 436| |10215| 106| 640774| 754| 112| 0| 0| 0| -1| 1749|53087123508| 436| | 2339| 246| 640774| 754| 112| 0| 1| 0| -1| 13436|53087123508| 436| |13855| 153| 640774| 754| 112| 0| 1| 0| -1| 7462|53087123508| 436| | 7723| 91| 640773| 11233| 217| 0| 1| 0| -1| 19654|53087135138| 450| | 7894| 100| 640774| 754| 112| 0| 0| 0| -1| 45218|53087123508| 436| | 5176| 134| 640774| 754| 112| 0| 1| 0| -1| 10675|53087123508| 436| | 1844| 106| 640776| 362561| 191| 0| 0| 0| 68| 6280|53087072689| 640| | 3513| 248| 640774| 754| 112| 0| 1| 0| -1| 3800|53087123508| 436| | 1519| 252| 640776| 362561| 191| 0| 0| 0| 68| 42671|53087072689| 640| |12312| 45| 640773| 11233| 217| 0| 1| 0| -1| 48840|53087135138| 450| |13657| 31| 640774| 754| 112| 0| 1| 0| -1| 13469|53087123508| 436| | 1585| 175| 640774| 754| 112| 0| 1| 0| -1| 10536|53087123508| 436| | 909| 286| 640774| 754| 112| 0| 1| 0| -1| 17395|53087123508| 436| |10766| 75| 640774| 754| 112| 0| 1| 0| -1| 42859|53087123508| 436| | 4511| 89| 640773| 11233| 217| 0| 0| 0| -1| 5367|53087135138| 450| | 4445| 23| 640774| 754| 112| 0| 0| 0| -1| 11811|53087123508| 436| | 1586| 70| 640774| 754| 112| 0| 0| 0| -1| 19164|53087123508| 436| |11284| 115| 640773| 11233| 217| 0| 0| 0| -1| 8828|53087135138| 450| | 2808| 35| 640773| 11233| 217| 0| 0| 0| -1| 365|53087135138| 450| | 820| 292| 640774| 754| 112| 0| 1| 0| -1| 6315|53087123508| 436| |13350| 13| 640774| 754| 112| 0| 1| 0| -1| 23949|53087123508| 436| | 455| 127| 640776| 362561| 191| 0| 0| 0| 68| 11824|53087072689| 640| | 5592| 91| 640773| 11233| 217| 0| 0| 0| -1| 2432|53087135138| 450| | 5517| 20| 640774| 754| 112| 0| 1| 0| -1| 828|53087123508| 436| | 4809| 166| 640773| 11233| 217| 0| 1| 0| -1| 3953|53087135138| 450| |13278| 51| 640774| 754| 112| 0| 0| 0| -1| 44554|53087123508| 436| | 33| 97| 640774| 754| 112| 0| 0| 0| -1| 19243|53087123508| 436| | 4666| 10| 640773| 11233| 217| 0| 1| 0| -1| 12312|53087135138| 450| |18508| 102| 640772| 443619| 75| 0| 0| 0| 468| 10846|53087124356| 620| | 1546| 183| 640774| 754| 112| 0| 0| 0| -1| 35896|53087123508| 436| |15596| 292| 640774| 754| 112| 0| 1| 0| -1| 39610|53087123508| 436| | 2341| 19| 640772| 443619| 75| 0| 0| 0| 468| 10007|53087124356| 620| | 2063| 91| 640774| 754| 112| 0| 1| 0| -1| 633|53087123508| 436| |12037| 143| 640773| 11233| 217| 0| 1| 0| -1| 34664|53087135138| 450| | 5650| 199| 640773| 11233| 217| 0| 0| 0| -1| 2972|53087135138| 450| |13994| 22| 640774| 754| 112| 0| 1| 0| -1| 14481|53087123508| 436| |14062| 214| 640773| 11233| 217| 0| 1| 0| -1| 21668|53087135138| 450| | 7912| 159| 640774| 754| 112| 0| 1| 0| -1| 48253|53087123508| 436| |14414| 26| 640774| 754| 112| 0| 1| 0| -1| 60985|53087123508| 436| | 4271| 27| 640773| 11233| 217| 0| 1| 0| -1| 7922|53087135138| 450| | 8996| 121| 640774| 754| 112| 0| 1| 0| -1| 13956|53087123508| 436| |14605| 248| 640772| 443619| 75| 0| 0| 0| 468| 30976|53087124356| 620| | 2106| 81| 640774| 754| 112| 0| 0| 0| -1| 1870|53087123508| 436| | 5292| 31| 640772| 443619| 75| 0| 0| 0| 468| 9261|53087124356| 620| | 8303| 3| 640774| 754| 112| 0| 1| 0| -1| 35922|53087123508| 436| | 1836| 45| 640774| 754| 112| 0| 0| 0| -1| 6127|53087123508| 436| | 5914| 253| 640773| 11233| 217| 0| 1| 0| -1| 1914|53087135138| 450| | 3188| 264| 640774| 754| 112| 0| 1| 0| -1| 44423|53087123508| 436| | 5516| 159| 640774| 754| 112| 0| 0| 0| -1| 33682|53087123508| 436| | 4459| 143| 640774| 754| 112| 0| 1| 0| -1| 24008|53087123508| 436| | 9066| 179| 640774| 754| 112| 0| 0| 0| -1| 4098|53087123508| 436| | 8837| 183| 640774| 754| 112| 0| 1| 0| -1| 10542|53087123508| 436| | 1218| 83| 640773| 11233| 217| 0| 0| 0| -1| 44052|53087135138| 450| |11479| 250| 640776| 362561| 191| 0| 0| 0| 68| 3901|53087072689| 640| | 1726| 343| 640774| 754| 112| 0| 1| 0| -1| 47870|53087123508| 436| | 6105| 191| 640774| 754| 112| 0| 0| 0| -1| 11288|53087123508| 436| |16063| 38| 640776| 362561| 191| 0| 0| 0| 68| 44716|53087072689| 640| | 6021| 138| 640773| 11233| 217| 0| 0| 0| -1| 32102|53087135138| 450| |14090| 45| 640774| 754| 112| 0| 1| 0| -1| 11360|53087123508| 436| | 422| 200| 640774| 754| 112| 0| 1| 0| -1| 591|53087123508| 436| |10560| 18| 640774| 754| 112| 0| 0| 0| -1| 7851|53087123508| 436| | 3442| 84| 640773| 11233| 217| 0| 0| 0| -1| 34094|53087135138| 450| | 1121| 110| 640774| 754| 112| 0| 0| 0| -1| 12460|53087123508| 436| |20420| 76| 640774| 754| 112| 0| 1| 0| -1| 1258|53087123508| 436| | 2147| 17| 640774| 754| 112| 0| 1| 0| -1| 9547|53087123508| 436| | 1671| 180| 640773| 11233| 217| 0| 0| 0| -1| 10136|53087135138| 450| | 2499| 10| 640774| 754| 112| 0| 1| 0| -1| 7716|53087123508| 436| | 3672| 26| 640774| 754| 112| 0| 0| 0| -1| 627|53087123508| 436| | 6214| 92| 640773| 11233| 217| 0| 0| 0| -1| 11106|53087135138| 450| | 3683| 186| 640774| 754| 112| 0| 1| 0| -1| 10904|53087123508| 436| | 7527| 105| 640774| 754| 112| 0| 1| 0| -1| 1094|53087123508| 436| | 161| -1| 640774| 754| 112| 1| 1| 1| -1| 24940|53087123508| 436| | 1994| 228| 640774| 754| 112| 0| 0| 0| -1| 16141|53087123508| 436| | 6230| 177| 640774| 754| 112| 0| 1| 0| -1| 7790|53087123508| 436| |17538| 110| 640774| 754| 112| 0| 1| 0| -1| 1083|53087123508| 436| | 2302| 253| 640774| 754| 112| 0| 1| 0| -1| 19624|53087123508| 436| | 9660| 103| 640774| 754| 112| 0| 1| 0| -1| 15558|53087123508| 436| |23848| 92| 640776| 362561| 191| 0| 1| 0| 68| 7450|53087072689| 640| |10896| 143| 640774| 754| 112| 0| 0| 0| -1| 10763|53087123508| 436| | 6834| 110| 640774| 754| 112| 0| 1| 0| -1| 30538|53087123508| 436| | 594| 193| 640774| 754| 112| 0| 0| 0| -1| 30577|53087123508| 436| | 2315| 35| 640773| 11233| 217| 0| 1| 0| -1| 4534|53087135138| 450| | 1070| 120| 640774| 754| 112| 0| 0| 0| -1| 31690|53087123508| 436| | 6005| 81| 640772| 443619| 75| 0| 0| 0| 468| 52698|53087124356| 620| | 9651| 40| 640774| 754| -1| 0| 1| 0| -1| 4772|53087123508| 436| | 2804| 137| 640776| 362561| 191| 0| 1| 0| 68| 5212|53087072689| 640| | 7919| 248| 640774| 754| 112| 0| 1| 0| -1| 6158|53087123508| 436| | 2313| 237| 640774| 754| 112| 0| 1| 0| -1| 4432|53087123508| 436| | 4904| 9| 640774| 754| 112| 0| 1| 0| -1| 2596|53087123508| 436| | 5875| 97| 640774| 754| 112| 0| 0| 0| -1| 8167|53087123508| 436| |10138| 144| 640773| 11233| 217| 0| 0| 0| -1| 1741|53087135138| 450| | 3690| 220| 640774| 754| 112| 0| 1| 0| -1| 11416|53087123508| 436| | 9521| 138| 640774| 754| 112| 0| 0| 0| -1| 32251|53087123508| 436| | 2102| 25| 640774| 754| 112| 0| 0| 0| -1| 5462|53087123508| 436| | 9478| 213| 640774| 754| 112| 0| 1| 0| -1| 7896|53087123508| 436| |11633| 49| 640774| 754| 112| 0| 0| 0| -1| 3623|53087123508| 436| | 6233| 19| 640773| 11233| 217| 0| 0| 0| -1| 10827|53087135138| 450| | 1624| 83| 640774| 754| 112| 0| 1| 0| -1| 36794|53087123508| 436| | 7256| 18| 640774| 754| 112| 0| 1| 0| -1| 11888|53087123508| 436| | 5841| 61| 640774| 754| 112| 0| 0| 0| -1| 13111|53087123508| 436| |12842| 178| 640774| 754| 112| 0| 1| 0| -1| 40859|53087123508| 436| | 4545| 115| 640773| 11233| 217| 0| 0| 0| -1| 618|53087135138| 450| | 9536| 140| 640773| 11233| 217| 0| 0| 0| -1| 15206|53087135138| 450| | 624| 26| 640774| 754| 112| 0| 1| 0| -1| 4058|53087123508| 436| |19921| 118| 640773| 11233| 217| 0| 1| 0| -1| 42014|53087135138| 450| | 1097| 95| 640774| 754| 112| 0| 1| 0| -1| 3784|53087123508| 436| |18186| 95| 640774| 754| 112| 0| 1| 0| -1| 16473|53087123508| 436| | 1597| 47| 640774| 754| 112| 0| 1| 0| -1| 52598|53087123508| 436| | 7032| 237| 640774| 754| 112| 0| 1| 0| -1| 45307|53087123508| 436| | 5109| 35| 640773| 11233| 217| 0| 0| 0| -1| 1159|53087135138| 450| | 1349| 51| 640774| 754| 112| 0| 1| 0| -1| 185|53087123508| 436| | 7053| 129| 640774| 754| 112| 0| 1| 0| -1| 8290|53087123508| 436| | 2901| 54| 640774| 754| 112| 0| 0| 0| -1| 50696|53087123508| 436| |17694| 227| 640774| 754| 112| 0| 1| 0| -1| 44023|53087123508| 436| |15692| 109| 640774| 754| 112| 0| 1| 0| -1| 540|53087123508| 436| | 3172| 10| 640774| 754| 112| 0| 1| 0| -1| 44505|53087123508| 436| |15662| 29| 640774| 754| 112| 0| 0| 0| -1| 10570|53087123508| 436| | 9609| 31| 640774| 754| 112| 0| 0| 0| -1| 38263|53087123508| 436| | 3755| 181| 640774| 754| 112| 0| 1| 0| -1| 52539|53087123508| 436| | 6213| 234| 640774| 754| 112| 0| 1| 0| -1| 34380|53087123508| 436| | 8095| 187| 640774| 754| 112| 0| 1| 0| -1| 2636|53087123508| 436| | 623| 43| 640774| 754| 112| 0| 0| 0| -1| 4836|53087123508| 436| | 2740| 29| 640774| 754| 112| 0| 1| 0| -1| 4041|53087123508| 436| | 8437| 84| 640774| 754| 112| 0| 1| 0| -1| 15557|53087123508| 436| | 5979| 315| 640774| 754| 112| 0| 1| 0| -1| 13957|53087123508| 436| | 2357| 327| 640774| 754| 112| 0| 1| 0| -1| 52723|53087123508| 436| | 5027| 123| 640774| 754| 112| 0| 0| 0| -1| 51228|53087123508| 436| | 3702| 99| 640774| 754| 112| 0| 1| 0| -1| 15381|53087123508| 436| | 2285| 13| 640773| 11233| 217| 0| 0| 0| -1| 3909|53087135138| 450| | 2520| 167| 640773| 11233| 217| 0| 0| 0| -1| 28330|53087135138| 450| | 2168| 225| 640773| 11233| 217| 0| 0| 0| -1| 34800|53087135138| 450| | 3472| 16| 640774| 754| 112| 0| 0| 0| -1| 15734|53087123508| 436| | 3632| 140| 640774| 754| 112| 0| 0| 0| -1| 6408|53087123508| 436| | 6846| 59| 640774| 754| 112| 0| 0| 0| -1| 6568|53087123508| 436| | 9039| 123| 640776| 362561| 191| 0| 1| 0| 68| 42911|53087072689| 640| | 9468| 180| 640773| 11233| 217| 0| 1| 0| -1| 37408|53087135138| 450| | 1146| 62| 640772| 443619| 75| 0| 1| 0| 468| 19530|53087124356| 620| |13893| 143| 640774| 754| 112| 0| 0| 0| -1| 33039|53087123508| 436| | 5252| 259| 640773| 11233| 217| 0| 0| 0| -1| 53493|53087135138| 450| | 9568| 318| 640774| 754| 112| 0| 0| 0| -1| 1318|53087123508| 436| | 1341| 137| 640774| 754| 112| 0| 1| 0| -1| 1246|53087123508| 436| | 3558| 144| 640773| 11233| 217| 0| 0| 0| -1| 29436|53087135138| 450| | 2330| 280| 640774| 754| 112| 0| 0| 0| -1| 31261|53087123508| 436| |13140| 116| 640774| 754| 112| 0| 0| 0| -1| 6097|53087123508| 436| | 3208| 5| 640773| 11233| 217| 0| 0| 0| -1| 2494|53087135138| 450| | 2729| 119| 640774| 754| 112| 0| 1| 0| -1| 1211|53087123508| 436| |13523| 114| 640772| 443619| 75| 0| 0| 0| 468| 33955|53087124356| 620| | 2056| 7| 640774| 754| 112| 0| 0| 0| -1| 17830|53087123508| 436| | 447| 262| 640774| 754| 112| 0| 0| 0| -1| 45630|53087123508| 436| | 1774| 135| 640774| 754| 112| 0| 1| 0| -1| 958|53087123508| 436| | 773| 214| 640773| 11233| 217| 0| 0| 0| -1| 697|53087135138| 450| | 3655| 18| 640774| 754| 112| 0| 0| 0| -1| 3504|53087123508| 436| |14894| 249| 640773| 11233| 217| 0| 1| 0| -1| 15640|53087135138| 450| | 2052| 61| 640774| 754| 112| 0| 1| 0| -1| 5536|53087123508| 436| |12139| 160| 640772| 443619| 75| 0| 0| 0| 468| 6680|53087124356| 620| | 6867| 0| 640773| 11233| 217| 0| 0| 0| -1| 11423|53087135138| 450| |13214| 149| 640774| 754| 112| 0| 0| 0| -1| 22586|53087123508| 436| | 3096| 110| 640774| 754| 112| 0| 0| 0| -1| 60331|53087123508| 436| | 825| 106| 640774| 754| 112| 0| 0| 0| -1| 30416|53087123508| 436| | 3583| 216| 640774| 754| 112| 0| 1| 0| -1| 9442|53087123508| 436| | 3452| 49| 640774| 754| 112| 0| 1| 1| -1| 224|53087123508| 436| | 4696| 129| 640774| 754| 112| 0| 1| 0| -1| 32982|53087123508| 436| | 1365| 24| 640774| 754| 112| 0| 1| 0| -1| 18304|53087123508| 436| | 53| 15| 640774| 754| 112| 0| 0| 0| -1| 19355|53087123508| 436| | 4329| 326| 640776| 362561| 191| 0| 0| 0| 68| 21093|53087072689| 640| | 6493| 99| 640774| 754| 112| 0| 1| 0| -1| 35392|53087123508| 436| | 6266| 30| 640774| 754| 112| 0| 1| 0| -1| 34674|53087123508| 436| | 2975| 99| 640774| 754| 112| 0| 0| 0| -1| 10496|53087123508| 436| |11677| 134| 640774| 754| 112| 0| 0| 0| -1| 22729|53087123508| 436| |10994| 213| 640773| 11233| 217| 0| 0| 0| -1| 14970|53087135138| 450| | 8994| 62| 640774| 754| 112| 0| 1| 0| -1| 18376|53087123508| 436| |13704| 159| 640774| 754| 112| 0| 0| 0| -1| 20701|53087123508| 436| | 2439| 117| 640774| 754| 112| 0| 1| 0| -1| 5533|53087123508| 436| |10905| 54| 640774| 754| 112| 0| 1| 0| -1| 4160|53087123508| 436| | 4821| 16| 640773| 11233| 217| 0| 1| 0| -1| 8519|53087135138| 450| |12008| 123| 640773| 11233| 217| 0| 1| 0| -1| 32175|53087135138| 450| | 268| 26| 640773| 11233| 217| 0| 1| 1| -1| 53096|53087135138| 450| | 5812| 37| 640774| 754| 112| 0| 0| 0| -1| 51364|53087123508| 436| | 5651| 1| 640773| 11233| 217| 0| 0| 0| -1| 9171|53087135138| 450| | 541| 153| 640774| 754| 112| 0| 1| 0| -1| 47182|53087123508| 436| | 1727| 187| 640774| 754| 112| 0| 1| 0| -1| 3989|53087123508| 436| | 5785| 38| 640774| 754| 112| 0| 1| 0| -1| 5224|53087123508| 436| |19425| 116| 640774| 754| 112| 0| 1| 0| -1| 4566|53087123508| 436| | 3636| 26| 640774| 754| 112| 0| 0| 0| -1| 744|53087123508| 436| |14473| 172| 640774| 754| 112| 0| 0| 0| -1| 17126|53087123508| 436| |17146| 130| 640774| 754| 112| 0| 1| 0| -1| 10197|53087123508| 436| | 3196| 215| 640774| 754| 112| 0| 1| 0| -1| 34085|53087123508| 436| |19487| 233| 640774| 754| 112| 0| 1| 0| -1| 20165|53087123508| 436| | 6166| 233| 640774| 754| 112| 0| 1| 0| -1| 33598|53087123508| 436| | 1750| 266| 640774| 754| 112| 0| 1| 0| -1| 44393|53087123508| 436| | 4947| 45| 640774| 754| 112| 0| 0| 0| -1| 8936|53087123508| 436| | 6883| -1| 640773| 11233| 217| 1| 1| 0| -1| 47083|53087135138| 450| | 427| 108| 640773| 11233| 217| 0| 0| 0| -1| 42754|53087135138| 450| | 7843| 53| 640774| 754| 112| 0| 1| 0| -1| 142|53087123508| 436| | 7712| 81| 640776| 362561| 191| 0| 0| 0| 68| 5579|53087072689| 640| +-----+---------+-------+---------+---------+-------+------+----+--------+------+-----------+-------------+

300+视频对应的item_id个数为:13,分别如下 +-------+ |item_id| +-------+ |1985642| | 640776| |1985637| |1985638| | 640774| |1985636| | 640775| | 640773| | 640772| |1985639| |1985640| |1985641| |3598380| +-------+

-------4.统计并汇总用户行为数据-------

uid出现次数 +-----+-------+ | uid|uid_Cnt| +-----+-------+ |19530| 1086| |37307| 977| |43714| 2046| |64822| 56| |15727| 1863| |34759| 474| |12940| 2379| | 6654| 1119| | 5156| 777| |26623| 173| +-----+-------+ only showing top 10 rows

device出现次数 +------+----------+ |device|device_Cnt| +------+----------+ | 7240| 518| | 25591| 678| | 37111| 774| | 6336| 551| | 35982| 960| | 6357| 2467| | 18654| 262| | 65251| 234| | 15790| 375| | 68610| 293| +------+----------+ only showing top 10 rows

authorid出现次数 +---------+------------+ |author_id|authorid_Cnt| +---------+------------+ | 33717| 602| | 32396| 778| | 51415| 106| | 1959| 4449| | 2142| 163| | 114206| 176| | 66176| 89| | 51607| 80| | 456314| 1| | 48875| 252| +---------+------------+ only showing top 10 rows

musicic出现次数 +--------+-----------+ |music_id|musicid_Cnt| +--------+-----------+ | 463| 448| | 833| 899| | 1088| 999| | 4935| 487| | 5803| 200| | 2659| 762| | 2122| 1126| | 1238| 143| | 5156| 939| | 4519| 344| +--------+-----------+ only showing top 10 rows

+--------+----------------+----------------+----------------+ |music_id|avg(musicid_Cnt)|min(musicid_Cnt)|max(musicid_Cnt)| +--------+----------------+----------------+----------------+ | 463| 448.0| 448| 448| | 833| 899.0| 899| 899| | 1088| 999.0| 999| 999| | 4935| 487.0| 487| 487| | 5803| 200.0| 200| 200| | 2659| 762.0| 762| 762| | 2122| 1126.0| 1126| 1126| | 1238| 143.0| 143| 143| | 5156| 939.0| 939| 939| | 4519| 344.0| 344| 344| | 19204| 147.0| 147| 147| | 2142| 537.0| 537| 537| | 7754| 221.0| 221| 221| | 7554| 26.0| 26| 26| | 63645| 3.0| 3| 3| | 17753| 7.0| 7| 7| | 7880| 114.0| 114| 114| | 14570| 2.0| 2| 2| | 3794| 111.0| 111| 111| | 471| 191.0| 191| 191| +--------+----------------+----------------+----------------+ only showing top 20 rows

music_id缺失的次数 +--------+-----------+ |music_id|musicid_Cnt| +--------+-----------+ | -1| 12582361| +--------+-----------+

+-------+------------------+------------------+-----------------+------------------+------------------+-----------------+-----------------+-------------------+------------------+--------------------+--------------------+------------------+------------------+------------------+-----------------+-----------------+------------------+-----------------+------------------+ |summary| item_id| uid| music_id| author_id| device| user_city| item_city| channel| finish| like| time| duration_time| uid_Cnt| device_Cnt| authorid_Cnt| musicid_Cnt| uid_playCnt| itemid_playCnt| item_pub_hour| +-------+------------------+------------------+-----------------+------------------+------------------+-----------------+-----------------+-------------------+------------------+--------------------+--------------------+------------------+------------------+------------------+-----------------+-----------------+------------------+-----------------+------------------+ | count| 19622340| 19622340| 19622340| 19622340| 19622340| 19622340| 19622340| 19622340| 19622340| 19622340| 19622340| 19622340| 19622340| 19622340| 19622340| 19622340| 19622340| 19622340| 19622340| | mean| 945663.4316979015|20874.206741448776|1745.486482804803| 98588.15998953235|21192.814770409645|92.24465338996266| 85.8824486274318|0.23568177903348939|0.3799067287591592|0.011004905633069247|5.308579815596791E10|11.163496555456689|1071.7839095643028|1062.7905935785436|5136.068913595423|8075786.957287867|1071.7839095643028|335.1756304293983|14.261599177264282| | stddev|1119026.8912257631|17182.085975392976|6606.642532386829|160969.00959521194| 17963.75187430432|88.50646209328728|78.42522135794351| 0.5169881748618554|0.4853633877913087| 0.10432544387511664| 2896765.2642502156|17.293735644059243|1093.3537296153363|1086.2365103994316|32472.84396591834|6024845.404531386|1093.3537296153363|748.5501175346003|6.7039681986613475| | min| 0| 0| -1| 0| 0| -1| -1| 0| 0| 0| 53015373867| 0| 1| 1| 1| 1| 1| 1| 0| | max| 4122688| 70710| 89777| 850307| 75084| 395| 460| 4| 1| 1| 53087170005| 70000| 10389| 10389| 276186| 12582361| 10389| 6911| 23| +-------+------------------+------------------+-----------------+------------------+------------------+-----------------+-----------------+-------------------+------------------+--------------------+--------------------+------------------+------------------+------------------+-----------------+-----------------+------------------+-----------------+------------------+

返回各列名和数据类型 [('item_id', 'int'), ('uid', 'int'), ('music_id', 'int'), ('author_id', 'int'), ('device', 'int'), ('user_city', 'int'), ('item_city', 'int'), ('channel', 'int'), ('finish', 'int'), ('like', 'int'), ('time', 'bigint'), ('duration_time', 'int'), ('uid_Cnt', 'bigint'), ('device_Cnt', 'bigint'), ('authorid_Cnt', 'bigint'), ('musicid_Cnt', 'bigint'), ('uid_playCnt', 'bigint'), ('itemid_playCnt', 'bigint'), ('item_pub_hour', 'int')] uid和finish的相关性: 0.040810676846246334 uid和like的相关性: -5.006362230075233e-05 user_city和finish的相关性: 0.07851029116638375 user_city和like的相关性: -0.0256154464641795 item_id和finish的相关性: -0.1064028505946855 item_id和like的相关性: 0.026502140129480198 author_id和finish的相关性: -0.05436068091303562 author_id和like的相关性: 0.021548955060519202 item_city和finish的相关性: 0.011321715928472248 item_city和like的相关性: 0.00021257142688209968 channel和finish的相关性: -0.14879415908767432 channel和like的相关性: 0.05605561072719165 music_id和finish的相关性: -0.023164347434264487 music_id和like的相关性: 0.01647598897138186 device和finish的相关性: 0.039109108704480436 device和like的相关性: -0.0010804991053058569 duration_time和finish的相关性: 0.0037283700283176893 duration_time和like的相关性: -0.0007436769076451733

各代码文件功能 explore_spark.py: 行为数据探索:首先通过上述数据特征探索,了解数据分布情况,再对衍生变量进行分箱,分箱方法主要是百分比分箱,各变量的分箱百分比略有不同,主要通过观察数据分布决定 explore_nlp_spark.py: title数据探索:运用pyspark中LDA数据模型训练title的主题分布向量,这里对得到的主题分布向量进行了两种方式的处理: (1)将主题分布向量直接转化为由50列组成的dataframe,每列的值即为该向量维度上对应的值 (2)根据主题分布向量自定义函数,得到最可能的topicID,得到的dataframe仅含有item_id和topicID两列 最终采用方式(2),原因为:首先方式(1)中的dataframe本身占用的内存大,处理速度慢,其次方式(2)更符合LDA处理的思维 explore_face_spark.py face数据探索:转化为datagrame,查看数据缺失值的比例 上述三个文件处理后的数据保存在hdfs上

preprocess_spark.py: 数据预处理:为deepfm的输入做准备,主要分为两步 (1)读取上述三个文件处理后的数据,并进行拼接,注意点是:拼接后由于item相关数据不能完全覆盖训练集中出现的item, 因此有些列会存在缺失的情况------相应处理:类别变量缺失填充-1,连续变量缺失用均值填充 查看每一列的缺失比例 +---------------+------------------+------------------+---------------------------+---------------------------+---------------------------+---------------------------+ |item_id_missing| gender_missing| beauty_missing|relative_position_0_missing|relative_position_1_missing|relative_position_2_missing|relative_position_3_missing| +---------------+------------------+------------------+---------------------------+---------------------------+---------------------------+---------------------------+ | 0.0|0.4585474015575519|0.4585474015575519| 0.4585474015575519| 0.4585474015575519| 0.4585474015575519| 0.4585474015575519| +---------------+------------------+------------------+---------------------------+---------------------------+---------------------------+---------------------------+ 如下表:gender缺失用-1填充,其余连续变量用均值填充 +-------+------+----------+-------------------+-------------------+-------------------+-------------------+ |item_id|gender|beauty |relative_position_0|relative_position_1|relative_position_2|relative_position_3| +-------+------+----------+-------------------+-------------------+-------------------+-------------------+ |48318 |-1 |0.53386056|0.36806366 |0.22114637 |0.26097575 |0.20240699 | |1192644|-1 |0.53386056|0.36806366 |0.22114637 |0.26097575 |0.20240699 | +-------+------+----------+-------------------+-------------------+-------------------+-------------------+ (2)类别变量 ca_col = [ 'channel','item_pub_hour','device_Cnt_bin','authorid_Cnt_bin','musicid_Cnt_bin',
'uid_playCnt_bin','itemid_playCnt_bin','user_city_score_bin','item_city_score_bin' ,'title_topic'] 需要进行标准化的连续变量 co_col = ['duration_time_feature',] 不需要进行标准化的连续变量 co_col_undeal1=['relative_position_0','relative_position_1','relative_position_2','relative_position_3',
'beauty',] 以上划分的依据如下:可见co_col_undeal1中的变量其数据分布比较稳定,基本在0-1之间,因此可以不做标准化处理 +-------+------------------+------------------+-------------------+-------------------+-------------------+-------------------+-------------------+ |summary| item_id| gender| beauty|relative_position_0|relative_position_1|relative_position_2|relative_position_3| +-------+------------------+------------------+-------------------+-------------------+-------------------+-------------------+-------------------+ | count| 4089623| 2214337| 2214337| 2214337| 2214337| 2214337| 2214337| | mean|2059311.2247016411|0.2579282195980106| 0.5338605889057859|0.36806366374709815| 0.2211463805417202|0.26097574598220147|0.20240698469452587| | stddev|1194621.9088045224|0.4374943880443843|0.08075274466371174|0.18938630252081418|0.13640456668506504| 0.1865488852564881|0.14544104908615763| | min| 1| 0| 0.25| 0.0| 0.0| 0.0056| 0.0047| | max| 4122599| 1| 1.13| 0.9889| 0.9828| 1.0| 1.0| +-------+------------------+------------------+-------------------+-------------------+-------------------+-------------------+-------------------+ 进而,根据相关处理,进一步得到feature_index,feature_value