0

Good day,

I have been trying to use arules and apriori in R for my data but to no avail.

For instance, my data are from excel (csv format) and it has 1000 experiment with 1 and 0.

enter image description here

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!

lukeA
  • 53,097
  • 5
  • 97
  • 100
Jin
  • 1
  • Welcome to SO. You could improve your question. Hover of the R tag and read [how to provide minimal reproducible examples in R](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example#answer-5963610). Then edit & improve it accordingly. A good post usually provides minimal input data, the desired output data & code tries - all copy-paste-run'able in a new/clean R session. – lukeA Oct 15 '16 at 11:14

1 Answers1

0

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
lukeA
  • 53,097
  • 5
  • 97
  • 100