代码之家  ›  专栏  ›  技术社区  ›  hpesoj626

捕获arules::inspect as data.frame的输出

  •  0
  • hpesoj626  · 技术社区  · 6 年前

    "Zero frequent items" when using the eclat to mine frequent itemsets 操作人员对分组/分组感兴趣,这取决于它们在一起排序的频率。此分组可由 arules::inspect 功能。

    library(arules)
    dataset <- read.transactions("8GbjnHK2.txt", sep = ";", rm.duplicates = TRUE)
    f <- eclat(dataset, 
               parameter = list(
                 supp = 0.001, 
                 maxlen = 17, 
                 tidLists = TRUE))
    inspect(head(sort(f, by = "support"), 10))
    

    数据集可从下载 https://pastebin.com/8GbjnHK2 .

    但是,输出不能作为数据帧轻松保存到另一个对象。

    out <- inspect(f)
    

    那么我们如何捕获 inspect(f) 用作数据帧?

    2 回复  |  直到 6 年前
        1
  •  1
  •   hpesoj626    6 年前

    我们可以使用这些方法 labels 提取关联/分组和 quality 提取质量度量(支持和计数)。然后我们可以使用 cbind 将这些数据存储到数据帧中。

    out <- cbind(labels = labels(f), quality(f))
    head(out)
    
    #              labels  support count
    # 1 {3031093,3059242} 0.001010    16
    # 2 {3031096,3059242} 0.001073    17
    # 3 {3060614,3060615} 0.001010    16
    # 4 {3022540,3072091} 0.001010    16
    # 5 {3061698,3061700} 0.001073    17
    # 6 {3031087,3059242} 0.002778    44
    
        2
  •  0
  •   Michael Hahsler    6 年前

    将项集强制为data.frame也会创建所需的输出。

    > head(as(f, "data.frame"))
                  items     support count
    1 {3031093,3059242} 0.001010101    16
    2 {3031096,3059242} 0.001073232    17
    3 {3060614,3060615} 0.001010101    16
    4 {3022540,3072091} 0.001010101    16
    5 {3061698,3061700} 0.001073232    17
    6 {3031087,3059242} 0.002777778    44