首页 / 更多教程 / 用户收视习惯聚类分析
用户收视习惯聚类分析
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了用户收视习惯聚类分析,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4776字,纯文字阅读大概需要7分钟。
内容图文
数据挖掘测试实例
用户收视习惯聚类分析
用户收视习惯在不同的小时段,不同的星期,会呈现不一样的特色,我们现在要做的就是将用户IPTV数据按照每小时收视时长进行聚类分析
测试样本:
2013 年 6 月 6 日(星期四,非假日)南京地区当天观看过 IPTV 的用户
用户数: 269745 人
数据准备:
1. 创建临时表
select s_userid,s_hour,s_timeleninto tmp_user_hour_len from tst_fct_d20130606_4 where s_city_id=1
2 、生成目标表
select s_userid,
(case when s_hour=‘00‘ then s_timelen else 0 end)as hour00 ,
(case when s_hour=‘01‘ then s_timelen else 0 end)as hour01 ,
(case when s_hour=‘02‘ then s_timelen else 0 end)as hour02 ,
(case when s_hour=‘03‘ then s_timelen else 0 end)as hour03 ,
(case when s_hour=‘04‘ then s_timelen else 0 end)as hour04 ,
(case when s_hour=‘05‘ then s_timelen else 0 end)as hour05 ,
(case when s_hour=‘06‘ then s_timelen else 0 end)as hour06 ,
(case when s_hour=‘07‘ then s_timelen else 0 end)as hour07 ,
(case when s_hour=‘08‘ then s_timelen else 0 end)as hour08 ,
(case when s_hour=‘09‘ then s_timelen else 0 end)as hour09 ,
(case when s_hour=‘10‘ then s_timelen else 0 end)as hour10 ,
(case when s_hour=‘11‘ then s_timelen else 0 end) ashour11 ,
(case when s_hour=‘12‘ then s_timelen else 0 end)as hour12 ,
(case when s_hour=‘13‘ then s_timelen else 0 end)as hour13 ,
(case when s_hour=‘14‘ then s_timelen else 0 end)as hour14 ,
(case when s_hour=‘15‘ then s_timelen else 0 end)as hour15 ,
(case when s_hour=‘16‘ then s_timelen else 0 end)as hour16 ,
(case when s_hour=‘17‘ then s_timelen else 0 end)as hour17 ,
(case when s_hour=‘18‘ then s_timelen else 0 end)as hour18 ,
(case when s_hour=‘19‘ then s_timelen else 0 end)as hour19 ,
(case when s_hour=‘20‘ then s_timelen else 0 end)as hour20 ,
(case when s_hour=‘21‘ then s_timelen else 0 end)as hour21 ,
(case when s_hour=‘22‘ then s_timelen else 0 end)as hour22 ,
(case when s_hour=‘23‘ then s_timelen else 0 end)as hour23 into user_hour_len_nj_20130606
from tmp_user_hour_len
3 、在 211 服务器上导出文件到本地
bcp user_hour_len_nj_20130606 outuser_hour_len_nj_20130606.txt -UXXX -PXXX -SXXX -c -t ‘|‘ -r ‘\n‘
4 、提取前 200 个实例进行测试
分析方法:
采用 k 均值算法进行聚类分析
数据源格式:
属性集:
属性集包含 24 个时段的详细信息,格式如下 ( 这里 real 也可以为 numeric) :
@relation cluster
@attribute H00 real
@attribute H01 real
@attribute H02 real
@attribute H03 real
@attribute H04 real
@attribute H05 real
@attribute H06 real
@attribute H07 real
@attribute H08 real
@attribute H09 real
@attribute H10 real
@attribute H11 real
@attribute H12 real
@attribute H13 real
@attribute H14 real
@attribute H15 real
@attribute H16 real
@attribute H17 real
@attribute H18 real
@attribute H19 real
@attribute H20 real
@attribute H21 real
@attribute H22 real
@attribute H23 real
数据集:
数据集包含每个用户的订购信息,格式如下:
@data
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,12,0
0,0,0,0,0,0,0,0,0,0,0,0,26,59,16,0,0,0,50,55,56,58,59,10
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,34,59,59,18,0
57,35,0,0,0,0,20,0,0,0,0,0,0,0,15,59,59,59,59,59,59,58,54,35
.....
测试过程:
打开 weka explorer , open file 打开特征文件 ( 如 example_cluster_ID_H24_200.arff) ,然后选择 cluster ,选择算法 SimpleKmeans ,选择距离方法 Euclidean distance (orsimilarity) function. 迭代次数 maxIterations=500, 类数目 numcluster=5 (或 3,4 都可以), seed=10,start
numcluster=5 时,得出如下结果
1 )
650) this.width=650;" width="206" height="163" src="/e/u261/themes/default/images/spacer.gif" />
这里代表所聚的各个类中的样本条数、数量占整个样本集的百分比。
2 )
650) this.width=650;" width="541" height="472" src="/e/u261/themes/default/images/spacer.gif" />
Number of iterations: 7
Within cluster sum of squared errors:228.6644541918032
Within cluster sum of squared errors ,代表簇内距离,这个值越小,聚类效果越好(当然聚类数越多这个值越小)。在不改变聚类数量的前提下,调整 seed 值可以改变上面 squared errors 值的大小,使得簇内距离越小,聚类效果越好。
参数说明:
参数选择窗口如下:
650) this.width=650;" width="448" height="459" src="/e/u261/themes/default/images/spacer.gif" />
参数说明:
displayStdDevs
是否显示数字属性标准差和名词属性个数
distanceFunction
用于比较实例的距离函数,包括马氏距离、欧氏距
离、明氏距离等(默认
:weka.core.EuclideanDistance
)。
dontReplaceMissingValues
是否不使用
mean/mode
替换全部丢失的值。
maxIterations
最大迭代次数
numClusters
所聚的类数
preserveInstancesOrder
是否预先排列实例的顺序
seed
设定的随机种子值
QuestionS :
1 、如何找出哪个 ID 聚到了哪一类中;
A: 针对训练样本,在聚类结果右击点击 “Visualizecluster assignments” ,在弹出的窗口中点击 save ,则可保存一个 arff 文件,在这个文件中每个样本最后一个属性值即 (“@attributeCluster”) 给出了详细划入的簇类别;
另外,第一个数值为训练样本的标号。
以文件的部分数据为例 (save_file_ID2Class.arff) ,如下:
----------------------------------------------------------------------------------------------------------------
@attributeH22 numeric
@attributeH23 numeric
@attributeCluster {cluster0,cluster1,cluster2,cluster3}
@data
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,12,0,cluster1
1,0,0,0,0,0,0,0,0,0,0,0,0,26,59,16,0,0,0,50,55,56,58,59,10,cluster2
2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,34,59,59,18,0,cluster2
3,57,35,0,0,0,0,20,0,0,0,0,0,0,0,15,59,59,59,59,59,59,58,54,35,cluster3
----------------------------------------------------------------------------------------------------------------
本文出自 “用户流失统计” 博客,谢绝转载!
原文:http://9309062.blog.51cto.com/9299062/1652804
内容总结
以上是互联网集市为您收集整理的用户收视习惯聚类分析全部内容,希望文章能够帮你解决用户收视习惯聚类分析所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。