当前位置:网站首页>spark:页面单跳转换率统计(案例)
spark:页面单跳转换率统计(案例)
2022-08-02 08:28:00 【一个人的牛牛】
目录
介绍
如果用户在一次Session过程中访问的页面路径为3,9,10,那么页面3跳到页面9叫一次单跳,单跳转化率就是统计页面点击的概率。
如:计算3-9的单跳转化率,先获取符合条件的Session对于页面3的访问次数A,然后获取符合条件的Session中访问页面3又接着访问页面9的次数B,那么 B/A 就是3-9的页面单跳转化率。
根据这个指标可以去尝试分析整个网站,产品,各个页面的表现,及时作出更改。
数据准备
数据说明:
时间_用户ID_sessionID_页面ID_动作时间_搜索_点击(品类ID、产品ID)_下单(品类ID、产品ID)_支付(品类ID、产品ID)_城市ID
可以根据数据格式模拟生成数据,也可以在网站爬!
没有数据可以私聊我。
代码实现
import org.apache.spark.{SparkConf, SparkContext} object TopThree { def main(args: Array[String]): Unit = { //TODO 创建环境 val sparkConf = new SparkConf().setMaster("local[*]").setAppName("TOP") val sc = new SparkContext(sparkConf) //TODO 单跳转换率 //读取日志文件 val rdd = sc.textFile("datas/action.txt") val dataRDD = rdd.map( action => { val datas = action.split("_") UserVisitAction( datas(0), datas(1).toLong, datas(2), datas(3).toLong, datas(4), datas(5), datas(6).toLong, datas(7).toLong, datas(8), datas(9), datas(10), datas(11), datas(12).toLong ) } ) dataRDD.cache() //TODO 计算分母 val pageCount = dataRDD.map( action => { (action.page_id, 1L) } ).reduceByKey(_ + _).collect().toMap //println(pageCount) //TODO 计算分子 //根据session分组 val sessionRDD = dataRDD.groupBy(_.session_id) //根据时间排序 val mapRDD = sessionRDD.mapValues( iter => { val sortList = iter.toList.sortBy(_.action_time) val flowIds = sortList.map(_.page_id) val pageflowIds = flowIds.zip(flowIds.tail) pageflowIds.map( t => { (t, 1) } ) } ) val flatRDD = mapRDD.map(_._2).flatMap(list => list) val datacountRDD = flatRDD.reduceByKey(_ + _) //计算:分子/分母 datacountRDD.foreach{ case ((pageid1,pageid2),sum) => { val lon = pageCount.getOrElse(pageid1, 0L) println(s"${pageid1}到${pageid2}单跳转换率为:" + (sum.toDouble/lon)) } } //TODO 关闭环境 sc.stop() } //用户访问动作表 case class UserVisitAction( date: String,//日期 user_id: Long,//用户ID session_id: String,//SessionID page_id: Long,//页面ID action_time: String,//动作的时间 search_keyword: String,//搜索关键词 click_category_id: Long,//商品品类ID click_product_id: Long,//商品ID order_category_ids: String,//订单中所有品类的ID集合 order_product_ids: String,//订单中所有商品的ID集合 pay_category_ids: String,//支付中所有品类的ID集合 pay_product_ids: String,//支付中所有商品的ID集合 city_id: Long//城市ID ) }
本文为学习笔记的记录
边栏推荐
- A little bit of knowledge - why do not usually cook with copper pots
- Shell becomes canonical and variable
- MySQL Workbench 安装及使用
- 积分商城商品供应商选择的三个要求
- openpyxl 单元格合并
- RetinaFace: Single-stage Dense Face Localisation in the Wild
- Three types of [OC learning notes] Block
- 不用Swagger,那我用啥?
- JSP页面中page指令contentPage/pageEncoding具有什么功能呢?
- postman使用方法
猜你喜欢
Postman download localization of installation and use
大厂外包,值得拥有吗?
How Engineers Treat Open Source --- A veteran engineer's heartfelt words
Application and case analysis of CASA model and CENTURY model
PyCharm usage tutorial (more detailed, picture + text)
Stop mental exhaustion Daily sharing
52. [Bool type input any non-0 value is not 1 version reason]
Redisson报异常attempt to unlock lock, not locked by current thread by node id解决方案
shell脚本
ip地址那点事(二)
随机推荐
查看变量的数据格式
The custom table form
第3周学习:ResNet+ResNeXt
Docker内MySQL主从复制学习,以及遇到的一些问题
UVM信息服务机制
测试时大量TIME_WAIT
Biotin hydrazide HCl|CAS:66640-86-6|Biotin-hydrazide hydrochloride
“蔚来杯“2022牛客暑期多校训练营4
Redisson实现分布式锁
Jenkins--部署--3.1--代码提交自动触发jenkins--方式1
Scala类型转换
shell中计算命令详解(expr、(())、 $[]、let、bc )
Postman download localization of installation and use
prometheus monitoring mysql_galera cluster
R language plotly visualization: use the plotly visualization model to predict the true positive rate (True positive) TPR and false positive rate (False positive) FPR curve under different thresholds
二分类和多分类
Detailed explanation of calculation commands in shell (expr, (()), $[], let, bc )
[OC学习笔记]Block三种类型
Ansible learning summary (11) - detailed explanation of forks and serial parameters of task parallel execution
OneNote Tutorial, How to Create More Spaces in OneNote?