开发者

When I convert a matrix into "transactions" for use with the arules package all of my values become 0

I am trying to ao apply the apriori algorithm to a binary matrix, but all of my values are returning 0.

I performed a summary function on the matrix to confirm that it has non-zero values. I tried coercing into the transactions form using:

trans<-as(a,"transactions")

and I tried applying apriori directly to the matrix using:

test<-apriori(a,parameter=list(support=.02,confidence=0,minlen=3,maxlen=3))

in both cases I got the same result seen below.

Anyone else experienced this?

Thanks

parameter specification:
 confidence minval smax arem  aval originalSupport support minlen maxlen target   ext
          0    0.1    1 none FALSE            TRUE    0.02      3      3  rules FALSE

algorithmic control:
 filter tree heap memopt load sort verbose
    0.1 TRUE TRUE  FALSE TRUE    2    TRUE

apriori - find association rules with the apriori algorithm
version 4.21 (2004.05.09)        (c) 1996-2004   Christian Borgelt
set item appearances ...[0 item(s)] done [0.00s].
set transactions ...[0 item(s), 1286 transaction(s)] done [0.00s].
Error in apriori(a,开发者_运维技巧 parameter = list(support = 0.02, confidence = 0, minlen = 3,  : 

In addition: Warning message:
In asMethod(object) :
  'NA's coerced to 'FALSE' in coercion to logical sparse


I have played around with arules package some and might be able to offer some help. First you should make sure that the

trans<-as(a,"transactions")

is returning a itemMatrix-class. The apiori() function will automatically coerce your object into a itemMatrix (the sprase data back bone of the arules library). Try

inspect(a[1:5])

to see that is a transaction matrix.

But your problem might be even simpler then that.

Your code:

test<-apriori(a,parameter=list(support=.02,confidence=0,minlen=3,maxlen=3))

Take a look back at the documentation or the original paper. But this is my understanding:

support == percent the entire item appears in the data. (left hand set LHS and right hand set RHS)

confidence == When the LHS is present how often does the RHS appear. in other words how confident are you in the rule

So your confidence parameter will always return no rules. Try 0 < confidence >= 100

test<-apriori(a,parameter=list(support=.02,confidence=0.9,minlen=3,maxlen=3))

or better is to coerce into the transaction and then apply.

trans<-as(a,"transactions")
test<-apriori(trans,parameter=list(support=.02,confidence=0.9,minlen=3,maxlen=3))

That is saying that get me the rules where entire item set appears in .02% of the data and the association rule holds true at least 90% of the time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜