arulesSequences包作序列模式的關聯分析

實驗數據:web

數據格式....

實驗文件:spa

 

?
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","B","A","B","A","C","A","B","C","B","A","B","A","A","B","A","B")))#必須是factor
tmp_data.tran<-as(tmp_data,"transactions")
transactionInfo(tmp_data.tran)$sequenceID<-c(1,1,1,1,1,2,2,2,2,2,2,3,3,3,4,4,4,4)
transactionInfo(tmp_data.tran)$eventID<-c(10,10,20,30,30,20,20,30,30,30,50,10,30,40,30,30,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,parameter = list(support = 0.75,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,parameter = list(support = 0.75,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,parameter = list(support = 0.75,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:
#--------
相關文章
相關標籤/搜索