1

I converted some rules to a dataframe with the DATAFRAME() fx from arules package. I deleted some rules and I want to convert back to class rules. I looked for documentation but I cannot find anything to do this.

I already tried to coerce:

as(df_br_two, "rules") Error in as(df_br_two, "rules") : no method or default for coercing “data.frame” to “rules”

I need to convert back to rules so I can plot the rules with arulesViz. Can anyone help me?

Elisa
  • 11
  • 1

2 Answers2

0

I don't think that you can change the data.frame back to a rules structure, at least not simply. However, if what you want to do is eliminate some of the rules, you can leave them as rules and edit easily. For example,

library(arules)
data("Adult")
rules <- apriori(Adult, 
    parameter = list(supp = 0.7, conf = 0.9, target = "rules"))
rules

set of 17 rules

Now let's eliminate the first and third rules

rules = rules[-c(1,3)]
rules

set of 15 rules

G5W
  • 36,531
  • 10
  • 47
  • 80
  • Thanks! the thing is it's much more complex like that to eliminate some rules, but you gave me the idea to make a copy of the rules, change that copy to DF and get the indexes of the rules I need to delete, and then delete them in the original rules. Although, I would like to convert them back to rules, this is another approach. Thanks! – Elisa Apr 14 '19 at 15:20
0

The rCBA package has a function called frametoRules.

This function will take a dataframe that was just converted from a rules back to rules. The only downside is that the function doesn't work consistently.

https://github.com/jaroslav-kuchar/rCBA/issues/6

This is the link to the issue.

Maybe you get lucky and it works for you? Who knows?


# Make sure that your dataframe is in this format :

data.frame(
           "rules" = {lhs} => {rhs},
           "support" = 0.5,
           "confidence" = 0.5,
           "lift" = 1.0)
)

newrules <- frametoRules(dataframe)


Good luck!

More Documentation: https://www.rdocumentation.org/packages/rCBA/versions/0.4.3/topics/frameToRules

Hansel Palencia
  • 1,006
  • 9
  • 17