使用arulesSequences在R中进行cSPADE数据挖掘 - 转换为"事务"格式

时间:2014-12-10 07:51:09

标签: r arules

我无法将数据转换为cSPADE兼容格式。

我的数据框看起来像 -

 key type1 type2 type3 
 A-1  A     B     C
 B-2  P     Q    NA
 C-3  X     NA   NA

当我使用时, dataset1<- as(dataset, "transactions") 并运行 -

rules<- cspade(dataset1, parameter = list(support = 0.4), control = list(verbose = TRUE))

它抛出错误 - Error in cspade(dataset1, parameter = list(support = 0.4), control = list(verbose = TRUE)) : slot transactionInfo: missing 'sequenceID' or 'eventID'

有人可以帮助将上述数据集转换为cSPADE兼容格式吗?

1 个答案:

答案 0 :(得分:3)

itry:

此格式的源数据集:

1 3 A B C
2 2 P Q    
3 1 X

第一列是序列的id,第二列是序列的长度,然后是序列的元素。 然后:

data <- read_baskets(con = "./input_file.txt", info = c("sequenceID","eventID","SIZE"))
rules<- cspade(data, parameter = list(support = 0.4), control = list(verbose = TRUE))

让我知道这是否有效。

这是我的输出:

parameter specification:
support : 0.4
maxsize :  10
maxlen  :  10

algorithmic control:
bfstype  : FALSE
verbose  :  TRUE
summary  : FALSE
tidLists : FALSE

preprocessing ... 1 partition(s), 0 MB [0.1s]
mining transactions ... 0 MB [0.06s]
reading sequences ... [0s]

total elapsed time: 0.16s

 > inspect(rules)
items   support 
1 <{B}> 0.3333333 
2 <{C}> 0.3333333 
3 <{Q}> 0.3333333 
4 <{B,   
 C}> 0.3333333