[英]Inability to discretize data in R for Association Rules (apriori)
Good day, 美好的一天,
I have been trying to use arules and apriori in R for my data but to no avail. 我一直在尝试在R中使用规则和先验数据,但无济于事。
For instance, my data are from excel (csv format) and it has 1000 experiment with 1 and 0. 例如,我的数据来自excel(csv格式),它有1000个实验(分别为1和0)。
As you can see, discretize seems to destroy the data for the column and I have been googling for solution but I could not really find the right solution to this. 如您所见,离散化似乎破坏了该列的数据,我一直在寻找解决方案,但我找不到真正合适的解决方案。
What is the solution to this?? 有什么解决方案?
Thank you in advance! 先感谢您!
Try it in the veins of 尝试一下
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.