zoukankan      html  css  js  c++  java
  • 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","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:
    #--------
  • 相关阅读:
    常用正则表达式(数字、字符、固定格式)
    阿里云serverless使用笔记
    http的get请求与post请求区别
    HTTPS各版本安全策略HTTPS1_1_TLS1_0、HTTPS2_TLS1_0、HTTPS2_TLS1_2
    REST式的web服务
    JAVA Remote Object
    AJAX的核心XMLHttpRequest对象
    SQL中TOP,LIMIT,ROWNUM的用法
    半双工模式和全双工模式
    win7系统网卡驱动正常,网线连接设备正常,但电脑右下角网络图片显示一直在转圈或者显示一个黄色感叹号的解决办法
  • 原文地址:https://www.cnblogs.com/einyboy/p/3203175.html
Copyright © 2011-2022 走看看