这次使用的SQL界面工具-SQL workbench
create table userbehavior(
userID int,
itemID int,
categoryID int,
bahaviortype text,
timestamp int
);
load data infile "C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/UserBehavior.csv"
into table userbehavior
fields terminated by ','
lines terminated by '\n';
我们看一下这个数据大概的样子:
select * from userbehavior limit 10;
根据字段内容进行分析后,将UserID,ItemID,TimeStamp设置成联合主键,经验证,不存在数据重复。
select UserID,ItemID,TimeStamp from userbehavior
GROUP BY UserID,ItemID,TimeStamp having count(1)>1;
select count(userID), count(itemID), count(categoryID), count(bahaviortype), count(timesstamp)
from userbehavior;
这里数据实在太大,达到了100150807,为了快速的完成,这里只采用了500000
这里的数据是一个时间戳,我们需要将这个数据转换到我们日常常用的时间格式
create table usertest2(
select * from userbehavior limit 500000
);
# 时间进行转换到日常格式
UPDATE usertest set datee = FROM_UNIXTIME(timesstamp,'%Y-%m-%d'), Timee = FROM_UNIXTIME(timesstamp,'%h');
#增加两个列
alter table userbehavior change Date datee date;
alter table userbehavior change Timee Timee varchar(10);
select max(datee), min(datee) from usertest;
这里的时间是2017-12-03年到2017-09-11的之间的数据
create view user_p as
select userID, itemID,
sum(case when bahaviortype = 'pv' then 1 else 0 end) as click,
sum(case when bahaviortype = 'fav' then 1 else 0 end) as favor,
sum(case when bahaviortype = 'buy' then 1 else 0 end) as buy,
sum(case when bahaviortype = 'cart' then 1 else 0 end) as buycar from usertest group by userID, itemID
;
SELECT * FROM day01.user_p;
这里是创建了一个视图,方便数据的简化和操作,关于视图的知识可以看下面两篇文章:
视图1:https://www.w3school.com.cn/sql/sql_view.asp
SQL视图的作用:https://blog.csdn.net/weixin_34037515/article/details/92609031
漏斗分析:详细介绍
# 分析每种情况下的转化率
create view user_p as
select userID, itemID,
sum(case when bahaviortype = 'pv' then 1 else 0 end) as click,
sum(case when bahaviortype = 'fav' then 1 else 0 end) as favor,
sum(case when bahaviortype = 'buy' then 1 else 0 end) as buy,
sum(case when bahaviortype = 'cart' then 1 else 0 end) as buycar from usertest group by userID, itemID
;
#click量449357
select sum(click) from user_p;
# 有buy量的行为的数目5066
select sum(buy) from user_p where click>0 and buy>0 and favor=0 and buycar=0;
# 有加buycar的行为数目 11956
select sum(buycar) from user_p where click>0 and buy=0 and favor=0 and buycar>0;
# 有favor行为的数目 4482
select sum(favor) from user_p where click>0 and buy=0 and favor>0 and buycar=0;
# 有favor并且buy 443
select sum(buy) from user_p where click>0 and buy>0 and favor>0 and buycar=0;
#有加buycar并且有buy行为 1467
select sum(buycar) from user_p where click>0 and buy>0 and favor=0 and buycar>0;
# 有加购和favor的数目: 298
select sum(favor)+sum(buy) from user_p where click>0 and buy=0 and favor>0 and buycar>0;
# 有加购和favor的数目: 145
select sum(favor)+sum(buy) from user_p where click>0 and buy>0 and favor>0 and buycar>0;
由此我们可以看出,从浏览量到直接购买转化率才1.01%,而浏览后有加购物车行为的购买转化率是12.27%,有收藏行为的转化率是9.88%,所以顾客有收藏或者加购物车的行为之后,这时候再购买的转化率达到了48.66%,说明会提升转化率,所以我们需要从产品交互界面、营销机制等方面让用户去多加购,多收藏。同时我们发现浏览后加购的转化率是12.27%,并且加购后到购买转化率为12.27%相比收藏后的转化率来说是更高的,所以引导加购行为更容易,效率更高。
当然我们也从中发现了一个巨大的问题,就是用户从点击量到下一层操作中,转化率都很低,说明出用户花了大量的时间去浏览商品,而真正下单的却很少,我们也都知道淘宝天猫的大部分用户都是女性,那女性逛街是非常厉害的,一下午甚至是一天,为什么呢?是因为女性往往购物不是买自己需要什么,而是自己喜欢什么,也就是所谓的闲着没事瞎逛,所以对于淘宝天猫这种购物平台,商品的推荐功能显得尤为重要,如果能够推荐用户喜欢的商品,那自然会下单,如果不喜欢也就只能是看看而已。
1、浏览量前20的商品类
select categoryID, count(categoryID) as clicknumber
from usertest where bahaviortype='pv'
group by categoryID order by clicknumber desc limit 20;
select categoryID, count(categoryID) as buynumber
from usertest where bahaviortype='buy'
group by categoryID order by buynumber desc limit 20;
我们将两者相同的商品ID查找出来:
我们发现前面曝光率比较高的商品,也出现在购买量比较多的列表当中,所以说明我们推荐系统展示的商品是和我们用户的需求相关的,20个商品种类中有6个商品是能够满足用户的需求的,当然,这里只有前20个的商品种类,数量不够有说服力,但是很说明问题
接下来我们对每个商品进行细分,看下曝光的具体商品和购买的商品是否有相关性
计算点击量前20的商品的购买量
select * from
(select itemID, count(bahaviortype) as buynumber
from usertest where bahaviortype='buy' group by itemID
) as a where itemID in
(select itemID from (select *, count(categoryID) as clicknumber
from usertest where bahaviortype='pv'
group by categoryID order by clicknumber desc limit 20) t);
select * from
(select itemID, count(bahaviortype) as buynumber
from usertest where bahaviortype='pv' group by itemID
) as a where itemID in
(select itemID from (select *, count(categoryID) as buynumber
from usertest where bahaviortype='buy'
group by categoryID order by buynumber desc limit 20) t);
点击量前20的商品购买了基本只有一个购买量,我们反看购买量前20的商品,点击量基本都是在20一下,在点击量里面是比较少的,说明推荐系统确实是不给力,没有给用户推荐到想要购买的商品
因此可以得出结论:推荐的商品顾客并不喜欢购买,由于高浏览量并没有带来购买,所以转化率低
同时我们还发现,商品3104240、1309498、1360115、2028325是商品购买量比较高的商品,所以可能需要提高这些商品的曝光率
总结:
1.优化推荐机制,把更多流量给到顾客愿意购买的商品
2.通过更好的商品推荐,页面交互,积分会员等功能等降低流失率
3.引导加购,可以加强营销机制引导顾客加购,比如加购物车联系客服领优惠券
RFM是3个指标的缩写,最近一次消费时间间隔(Recency),消费频率(Frequency),消费金额(Monetary)。通过这3个指标对用户分类。
接下来就需要利用SQL语句,计算每个用户的最近一次消费时间间隔和消费频率,消费金额由于数据缺失,我就使用随机数生成一列用来代替价格。
alter table usertest add price float;
update usertest set price=ceil(rand()*199);
select * from usertest limit 10;
1、计算最近因此消费时间间隔(R)
R = 数据统计时间-用户最新消费时间
F = 用户购买次数总和
M=商品价格
我们查看一下最近的时间是什么时候?
select datee from usertest order by datee desc;
这里把数据集中最新的时间定为数据统计时间为2017-12-03时间
select userID, datediff('2017-12-03', max(datee))+1 as R, count(bahaviortype) as F, price
from usertest where bahaviortype = 'buy' group by userID;
我们先找到RFM的各个值的最大和最小值,然后给R和F以及价格的价值打分
select max(F) from
(select userID, datediff('2017-12-03', max(datee))+1 as R, count(bahaviortype) as F, price
from usertest where bahaviortype = 'buy' group by userID order by R desc) t;
select min(F) from
(select userID, datediff('2017-12-03', max(datee))+1 as R, count(bahaviortype) as F, price
from usertest where bahaviortype = 'buy' group by userID order by R desc) t;
select min(price) from
(select userID, datediff('2017-12-03', max(datee))+1 as R, count(bahaviortype) as F, price
from usertest where bahaviortype = 'buy' group by userID order by R desc) t;
select max(price) from
(select userID, datediff('2017-12-03', max(datee))+1 as R, count(bahaviortype) as F, price
from usertest where bahaviortype = 'buy' group by userID order by R desc) t;
select min(R) from
(select userID, datediff('2017-12-03', max(datee))+1 as R, count(bahaviortype) as F, price
from usertest where bahaviortype = 'buy' group by userID order by R desc) t;
select max(R) from
(select userID, datediff('2017-12-03', max(datee))+1 as R, count(bahaviortype) as F, price
from usertest where bahaviortype = 'buy' group by userID order by R desc) t;
然后我们分别对这些数据进行打分,将分数新建字段,并将结果新建一个表,方面后面价值用户分析
create table RFM(
select *,
(
case when R <= 2 then 4
when R between 3 and 4 then 3
when R between 5 and 7 then 2
when R between 8 and 9 then 1 end
) as Rscore,
(
case when F >= 19 then 4
when F between 13 and 18 then 3
when F between 7 and 12 then 2
when F between 1 and 6 then 1 end
) as Fscore,
(
case when M between 1 and 50 then 1
when M between 51 and 100 then 2
when M between 101 and 150 then 3
when M between 151 and 199 then 4 end
) as Mscore
from
(select userID, datediff('2017-12-03', max(datee))+1 as R, count(bahaviortype) as F, price as M
from usertest where bahaviortype = 'buy' group by userID) t);
select avg(Rscore), avg(Fscore), avg(Mscore) from rfm;
我们将高于均值的定位高,低于均值的定位低,所以,根据三个特征的高低不同排序,定位不同的价值用户
select classuser, count(userID) as peoplenumber from
(select userID,
(
case when Rscore>'3.0625' and Fscore > '1.0998' and Mscore > '2.4807' then '重要价值用户'
when Rscore>'3.0625' and Fscore <= '1.0998' and Mscore > '2.4807' then '重要发展用户'
when Rscore<='3.0625' and Fscore > '1.0998' and Mscore > '2.4807' then '重要保持用户'
when Rscore<='3.0625' and Fscore <= '1.0998' and Mscore > '2.4807' then '重要挽留用户'
when Rscore>'3.0625' and Fscore > '1.0998' and Mscore < '2.4807' then '一般价值用户'
when Rscore>'3.0625' and Fscore <= '1.0998' and Mscore <= '2.4807' then '一般发展用户'
when Rscore<='3.0625' and Fscore > '1.0998' and Mscore <= '2.4807' then '一般保持用户'
when Rscore<='3.0625' and Fscore <= '1.0998' and Mscore <= '2.4807' then '一般挽留用户' end
) as classuser
from rfm) t group by classuser;
1.流量高的商品并不是购买量高的商品,高流量的商品购买量低导致了整体的流量转化率低,也就是推荐展示的逻辑并没有以销售为导向。
2.从用户行为路径中发现,用户浏览后直接购买的转化率较低,而通过加购,收藏等行为后购买的转化率会提升,故需要引导顾客积极加购或者收藏,且对比转化率后发现加购物车所带来的转化是最好的。
3.用户主要集中在重要发展用户和重要挽留用户,以及一般发展用户和一般挽留用户,四者加总占用户数的92%
4.建议算法部门优先展示购买量TOP10的商品类给顾客,例如2735466、1464116、4145813等,如果说浏览量高的商品是新品或者近期主推的商品,是否可以考虑和TOP10购买的商品按照类目合理搭配销售,提升转化率和连带率。
5.需积极引导顾客加购物车或者收藏宝贝,对于界面设计部门是考虑如何交互能够让顾客更愿意点击,对于运营部门,可以设置机制引导,例如加购联系客服送5元无门槛优惠券,加购送小样赠品等的机制来引导。
7.对于重要发展用户,其消费频率低,但最近消费距离现在时间较短,因此要想办法提高他的消费频率,通过CRM的红包发放、会员权益奖励、短信提醒优惠等方式提升消费频率。
8.对于重要挽留用户,最近消费时间距离现在较远、消费频率低。这种用户有即将流失的危险。建议通过APP推送、短信和邮件等形式发放有偿问卷主动联系用户,调查清楚哪里出了问题,制定相应的挽回策略
在这个博文上面上进行了一些改进和修改,详细的分析可以查阅下面这篇博文。
参考博文:https://zhuanlan.zhihu.com/p/121530969