R编程 - 市场篮子分析

时间:2017-07-24 17:11:51

标签: r

运行inspect命令后,我收到错误

  

插槽中的错误(x,s)[i]:下标越界。

basket_rules <- apriori(txn, parameter = list(sup = 0.005, conf = 0.01, target="rules"))
basket.sorted <- sort(basket_rules, by = "lift")
itemFrequencyPlot(txn, topN = 25)
inspect(basket.sorted[1:5])

任何人都可以帮我吗?

1 个答案:

答案 0 :(得分:1)

basket.sorted大概少于5个规则,因此5 超出范围。参见例如

library(arules)
data("Adult")
basket_rules <- apriori(Adult, parameter = list(sup = 0.9, conf = 0.5, target="rules"))
basket.sorted <- sort(basket_rules, by = "lift")
inspect(basket.sorted[1:5])
# Error in slot(x, s)[i] : subscript out of bounds
basket.sorted
# set of 2 rules
inspect(basket.sorted[1:2])
#     lhs    rhs                 support   confidence lift
# [1] {}  => {capital-gain=None} 0.9173867 0.9173867  1   
# [2] {}  => {capital-loss=None} 0.9532779 0.9532779  1