0

再会,

我一直在尝试在 R 中使用 arules 和 apriori 作为我的数据,但无济于事。

例如,我的数据来自 excel(csv 格式),它有 1000 个实验,1 和 0。

在此处输入图像描述

如您所见,离散化似乎破坏了列的数据,我一直在谷歌搜索解决方案,但我真的找不到正确的解决方案。

这个有什么解决办法??

先感谢您!

4

1 回答 1

0

尝试一下

library(arules)
data("iris")
head(iris, 3)
#   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
# 1          5.1         3.5          1.4         0.2  setosa
# 2          4.9         3.0          1.4         0.2  setosa
# 3          4.7         3.2          1.3         0.2  setosa
for(i in 1:4) iris[,i] <- discretize(iris[,i],  "frequency", categories=3)
head(iris, 3)
#   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
# 1    [4.3,5.5)   [3.3,4.4]      [1,3.0)   [0.1,1.0)  setosa
# 2    [4.3,5.5)   [3.0,3.3)      [1,3.0)   [0.1,1.0)  setosa
# 3    [4.3,5.5)   [3.0,3.3)      [1,3.0)   [0.1,1.0)  setosa
trans <- as(iris, "transactions")
rules <- apriori(trans, appearance = list(rhs = paste("Species",levels(iris$Species), sep="="), default = "lhs")) 
inspect(rules)
#    lhs                         rhs                    support confidence     lift
# 1  {Petal.Length=[5,6.9]}   => {Species=virginica}  0.2933333  0.9565217 2.869565
# 2  {Petal.Width=[1.7,2.5]}  => {Species=virginica}  0.3066667  0.9583333 2.875000
# 3  {Petal.Width=[1.0,1.7)}  => {Species=versicolor} 0.3200000  0.9230769 2.769231
# 4  {Petal.Length=[3,5.0)}   => {Species=versicolor} 0.3200000  0.8888889 2.666667
# 5  {Petal.Length=[1,3.0)}   => {Species=setosa}     0.3333333  1.0000000 3.000000
# 6  {Petal.Width=[0.1,1.0)}  => {Species=setosa}     0.3333333  1.0000000 3.000000
于 2016-10-15T11:13:18.097 回答