arulesSequences 序列模式挖掘包

实验数据:

实验文件

 

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
library(arulesSequences)
 
tmp_data<-data.frame(item=factor(c("A","B","A","C","B")))#必须是factor
tmp_data.tran<-as(tmp_data,"transactions")
transactionInfo(tmp_data.tran)$sequenceID<-c(1,1,2,3,4,4)
transactionInfo(tmp_data.tran)$eventID<-c(10,10,20,30,50,40,50)
transactionInfo(tmp_data.tran)
 
#lab1:基本约束support(认为0.1)
s_result<-cspade(tmp_data.tran,parameter = list(support = 0.75),control = list(verbose = TRUE))
inspect(s_result)
#   items      support
# 1 <{item=A}>    1.00
# 2 <{item=B}>    1.00
# 3 <{item=A}, 
#    {item=B}>    1.00
# 4 <{item=A,  
#     item=B}>    0.75
# 5 <{item=B}, 
#    {item=B}>    0.75
# 6 <{item=A,  
#     item=B}, 
#    {item=B}>    0.75
# 7 <{item=A}, 
#    {item=A}>    1.00
# 8 <{item=B}, 
#    {item=A}>    0.75
 
#lab2:maxlen约束:每一个序列的event最多只能为n(每一个序列中的“{}”号最多只能为n个)
#英文解释 maxlen: an integer value specifying the maximum number of elements of a sequence (default 10 range > 0).
#element就是指event。所以:sequence包含event(element),event包含item
s_result<-cspade(tmp_data.tran,parameter = list(support = 0.75,maxlen=1),control = list(verbose = TRUE))
inspect(s_result)
#   items      support
# 1 <{item=A}>    1.00
# 2 <{item=B}>    1.00
# 3 <{item=A,  
#     item=B}>    0.75
 
#lab3:maxsize约束:每一个序列的每个event内部最多只能有n个item(每一个序列中的每个{}内部最多有n个items)
#英文解释maxsize: an integer value specifying the maximum number of items of an element of a sequence(default 10,range > 0).
#element就是指event。所以:sequence包含event(element),event包含item
s_result<-cspade(tmp_data.tran,maxsize=1),control = list(verbose = TRUE))
inspect(s_result)
#   items      support
# 1 <{item=A}>    1.00
# 2 <{item=B}>    1.00
# 3 <{item=A}, 
#    {item=B}>    1.00
# 4 <{item=B}, 
#    {item=B}>    0.75
# 5 <{item=A}, 
#    {item=A}>    1.00
# 6 <{item=B}, 
#    {item=A}>    0.75
 
#lab4:mingap:所有的相邻的两个eventID的差大于mingap
#英文解释mingap: an integer value specifying the minimum time difference between consecutive elements of a sequence (default none,range >= 0).
s_result<-cspade(tmp_data.tran,mingap=19),control = list(verbose = TRUE))
inspect(s_result)
#   items      support
# 1  <a href="http://4seohunt.biz/rep/bannerweb.upstate.edu">bannerweb.upstate.edu</a> <{item=A}>     1.00
# 2 <{item=B}>    1.00
# 3 <{item=A}, 
#    {item=B}>    1.00
# 4 <{item=A,  
#     item=B}>    0.75
# 5 <{item=B}, 
#    {item=B}>    0.75
# 6 <{item=A,  
#     item=B}, 
#    {item=B}>    0.75
#分析:缺少了实验lab1中的
# 7 <{item=A}, 
#    {item=A}>    1.00
#eventid只差分别是:sid=1时,eventid=30-10=20>19。sid=2时,eventid=30-20=10不>19。sid=3时,eventid=40-10=30>19。sid=4时,eventid=40-30=10不>19。即supp=2/4=0.5
# 8 <{item=B}, 
#    {item=A}>    0.75
#eventid只差分别是:sid=1时,eventid=30-10=20>19。sid=2时,无b->a。sid=3时,eventid=40-30=10不>19。sid=4时,eventid=40-30=10不>19。即supp=1/4=0.25
 
#lab5:maxgap:所有的相邻的两个eventID的差小于等于maxgap
#英文解释maxgap: an integer value specifying the maximum time difference between consecutive elements of a sequence (default none,range >= 0).
s_result<-cspade(tmp_data.tran,maxgap=19),control = list(verbose = TRUE))
inspect(s_result)
#   items      support
# 1 <{item=A}>    1.00
# 2 <{item=B}>    1.00
# 3 <{item=A}, 
#    {item=B}>    0.75
# 4 <{item=A,  
#     item=B}>    0.75
# 5 <{item=B}, 
#    {item=A}>    0.75
#分析:和实验lab1中数据的差别
#lab1中
# 3 <{item=A}, 
#    {item=B}>    1
#lab5中
# 3 <{item=A}, 
#    {item=B}>    0.75
#eventid只差分别是:sid=1时,eventid=30-20=10小于等于19,30-10=20不小于等于19。sid=2时,50-20=30不小于等于19,50-30=20不小于等于19,30-20=10小于等于19。sid=3时,eventid=30-10=20不小于等于19。sid=4时,eventid=40-30=10不小于等于19,50-40=10小于等于19。即supp=3/4=0.75
 
#lab6:maxwin:
#--------

相关文章

自1998年我国取消了福利分房的政策后,房地产市场迅速开展蓬...
文章目录获取数据查看数据结构获取数据下载数据可以直接通过...
网上商城系统MySql数据库设计
26个来源的气象数据获取代码
在进入21世纪以来,中国电信业告别了20世纪最后阶段的高速发...