-->

R-转换交易格式的数据集,为序列挖掘篮格式(R-convert transaction format

2019-10-19 07:11发布

原始表

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/>

需要-

从尺寸400000的数据集挖掘活动的最高发生的序列

上面的例子应该显示

[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包?

当前分贝格式 - 交易与3列等样品上方。

Answer 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


文章来源: R-convert transaction format dataset to basket format for sequence mining