一、分析背景和目的
分析背景:如今,电商在我们的日常生活中扮演着越来越重要的角色,它给我们的生活带来了极大的便利,基本足不出户就能就能就能买到我们所需的各种生活物资,淘宝作为我国最最大的电商平台,绝大多数人都在上面买过东西,特别是在如今爆发病毒疫情的特殊时期,大家都居家隔离的情况下,网上购买生活物资更是必不可少,相信未来我们也会更加的喜爱和依赖网上购物。
分析目的:用户在网上购物会产生了一系列的行为,用户行为分析是营销工作的首要环节,指挥着营销活动的走向,之所以分析用户行为,是为了找到用户行为的特征,从而为企业的经营提供支持。与PC端相比,移动终端上的网络接入可以随时随地进行。并且还具有丰富的背景数据,如用户的位置信息、访问时间的规律性等。下面主要是对用户行为数据的分析。
二、数据集简介
数据集来源于阿里云天池平台的数据,主要记录了客户的购买行为,包括点击、收藏、加入购物车和购买商品。
字段理解:本数据集主要包含user_id,item_id,
behavior_type,user_geohash,item_category,time等字段,具体解释如下表所示
字段 | 字段描述 | 注释 |
---|---|---|
user_id | 用户id | 脱敏用户信息 |
item_id | 商品id | 脱敏商品信息 |
behavior_type | 用户行为类型 | 1、2、3和4分别对应点击、收藏、加入购物车和购买商品 |
user_geohash | 纬度 | 行为发生时的用户位置,可能为空 |
item_category | 品类id | 商品所属的品类 |
time | 行为发生的时间 | 最近行为发生的时间 |
数据集来源:User Behavior Data on Taobao App
https://tianchi.aliyun.com/dataset/dataDetail?dataId=46
三、数据清洗
由于数据体量比较大,在自己的电脑上运行的很慢,这里随机选取数据集的300万条数据进行分析,并将其保存到表user_behavior中。
1、首先在mysql中建表并导入数据:
#建表并导入数据
create table if not exists users(
user_id varchar(20) default null,
item_id varchar(20) default null,
behavior_type int default null,
user_geohash varchar(20) default null,
item_category varchar(20) default null,
times varchar(20) default null
);
#导入数据
load data infile "C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/user_behavior.csv"
into table users
fields terminated by ","
ignore 1 lines;
查看整体情况如图所2、检查数据的完整性即检查字段是否存在空值:
#检查完整性(即检查字段是否存在空值):
select
sum((case when user_id="" then 1 else 0 end)) as user_id_null,
sum((case when item_id="" then 1 else 0 end)) as item_id_null,
sum((case when behavior_type="" then 1 else 0 end)) as behavior_type_null,
sum((case when user_geohash="" then 1 else 0 end)) as user_geohash_null,
sum((case when item_category="" then 1 else 0 end)) as item_category_null,
sum((case when times="" then 1 else 0 end )) as times_null
from users;
且由于表中的user_geohash字段空值太多,且后面也不用这个字段,将这个字段删除
alter table users drop column user_geohash;
3、检查是否有重复值
select
count(distinct(user_id)) as user_id,
count(distinct(item_id)) as item_id,
count(distinct(behavior_type)) as behavior_type,
count(distinct(item_id)) as item_id
from users;
由于用户可以同时下多个订单,多个用户可以买相同的商品,所以字段是可以有重复值的
4、观察到times字段中的日期和小时存在于一列中,这里将其分为两列,新增加两个字段,字段名分别为user_date和user_hour。
#创建user_date,user_time两个新字段
alter table users add user_date varchar(20) not null;
alter table users add user_time varchar(20) not null;
#user_date取字段times文本型字段的前10位字符
update users set user_date=substring(times,1,10);
#user_time取字段times文本型字段的后2位字符
update users set user_time=substring(times,12,13);
#将user_date字段类型更改为date类型
alter table users modify user_date date ;
5、转化字段:将behavior_type的1-4转换为点击、收藏、加购和支付。
#将behavior_type字段类型转换成字符串型
alter table users modify behavior_type varchar(20);
# 转化字段,将1,2,3,4分别转换为点击、收藏、加购和支付
update users set behavior_type =replace(behavior_type,1,"点击");
update users set behavior_type =replace(behavior_type,2,"收藏");
update users set behavior_type =replace(behavior_type,3,"加入购物车");
update users set behavior_type =replace(behavior_type,4,"购买商品");
查看表格如图所示:
6,创建一个weeks字段,求出每天对应的星期,用于后面的分析:
#创建一个星期字段
alter table users add weeks varchar(30) null;
update users set weeks=date_format(user_date,"%W");
select * from users limit 10;
再查看一遍整体数据
四、构建模型与分析
分析思路
如图所示为构建的数据分析框架,不同观察的维度,去衡量事物发展的指标,并使用RFM模型挖掘潜在客户的价值,为运营提供方向。
指标分析
(一). 平台整体运营分析
- 流量类分析
1.PV、UV、人均点击量、人均收藏加购量、人均购买量
PV:即页面点击数(Page View)为分析时间段内所有用户产生的所有点击次数。
UV:即独立访客数(Unique View/Visitor),所有登录过的用户的总数
人均点击量:计算公式=页面点击数PV/独立访客数UV
人均收藏/加购:计算公式=(收藏+加购)总人数/独立访客数UV
人均购买量:计算公式=购买人数/独立访客数UV
# 页面点击数PV,独立访客数UV,人均点击量,人均收藏加购量,人均购买量
select
(select count(behavior_type) from users where behavior_type = '点击') as '页面点击数PV',
count(distinct user_id) as '独立访客数UV',
(select count(behavior_type) from users where behavior_type = '点击')/count(distinct user_id) as '人均点击量',
(select count(behavior_type) from users where behavior_type ='收藏' or behavior_type ='加入购物车')/count(distinct user_id) as '人均收藏/加购量',
(select count(behavior_type) from users where behavior_type = '购买商品')/count(distinct user_id) as '人均购买量'
from users;
结果:
由图中可知,PV为2826967,UV为9979,人均点击量为283.29次,人均收藏/加购为14.4次,人均购买量为3次
2.跳失率
跳失率:显示顾客通过相应入口进入,只访问了一个页面就离开的访问次数占该入口总访问次数的比例,这里指的是那些只产生点击行为,没有参与加购、收藏、购买等一系列其他购物行为的用户除以总用户。
跳失率 = 只浏览了一个页面的访客数/ 总访客数
#只产生点击行为的用户数
SELECT COUNT(DISTINCT user_id) FROM users
WHERE user_id not in