将事务格式数据集转换为篮子格式以进行序列挖掘

时间:2014-02-01 08:24:32

标签: r data-mining arules

ORIGINAL TABLE

CELL NUMBER ----------ACTIVITY--------TIME<br/>
001................................call a................12.23<br/>
002................................call b................01.00<br/>
002................................call d................01.09<br/>
001................................call b................12.25<br/>
003................................call a................12.23<br/>
002................................call a................02.07<br/>
003................................call b................12.25<br/>

REQUIRED -

从大小为400,000的数据集中挖掘出最高的ACTIVITY序列

上面的例子应该显示

[call a-12.23,call b-12.25] frequency 2<br/>
[call b-01.00,call d-01.09,call a-02.07] frequency 1

我知道这可以使用arulesSequences来实现。我需要对数据集进行哪些转换以及如何使用arulesSequences包?

当前的db格式 - 事务,包含3列,如上面的示例。

1 个答案:

答案 0 :(得分:1)

df<-read.table(header=T,sep="|",text="CELL NUMBER|ACTIVITY|TIME
001|call a|12.23
002|call b|01.00
002|call d|01.09
001|call b|12.25
003|call a|12.23
002|call a|02.07
003|call b|12.25")


require(plyr) # for count() function
freqs<-count(df[,-1]) # [,-1] to exclude the CELL NUMBER column from the group
freqs[order(-freqs$freq),]
  ACTIVITY  TIME freq
2   call a 12.23    2
4   call b 12.25    2
1   call a  2.07    1
3   call b  1.00    1
5   call d  1.09    1

编辑 - 更新如下:

unique(ddply(freqs,.(-freq),summarise,calls=paste0("[",paste0(paste0(ACTIVITY,"-",TIME),collapse=","),"]","frequency",freq)))
#  -freq                                        calls
#1    -2        [call a-12.23,call b-12.25]frequency2
#3    -1 [call a-2.07,call b-1,call d-1.09]frequency1