This class implements a generic rule set (LHS -> RHS), serving as the parent
class for ImplicationSet. It provides common functionality for
managing, filtering, and exporting rules.
new()Initialize a RuleSet
RuleSet$new(...)...A rules object (from arules) or named arguments:
name (string), attributes (character vector),
lhs and rhs (sparse matrices), I (incidence matrix),
quality (data.frame), confidence (numeric vector, backward compat).
A new RuleSet object.
get_attributes()Get the names of the attributes
RuleSet$get_attributes()A character vector with the names of the attributes used in the rules.
[()Get a subset of the rule set
RuleSet$[(idx)idx(integer or logical vector) Indices of the rules to extract or remove. If logical vector, only TRUE elements are retained and the rest discarded.
A new RuleSet with only the rules given by the idx indices.
to_arules()Convert to arules format
RuleSet$to_arules(quality = TRUE)quality(logical) Compute/include the interest measures for each rule?
A rules object as used by package arules.
add()Add a precomputed rule set
RuleSet$add(...)...A RuleSet object, or a pair lhs, rhs of dgCMatrix.
Nothing, just updates the internal field.
cardinality()Cardinality: Number of rules in the set
RuleSet$cardinality()The cardinality of the rule set.
is_empty()Empty set
RuleSet$is_empty()TRUE if the set of rules is empty, FALSE otherwise.
size()Size: number of attributes in each of LHS and RHS
RuleSet$size()A matrix with two columns: the number of attributes present in each of the LHS and RHS of each rule.
A string with all the rules in the set.
get_quality()Get quality metrics
RuleSet$get_quality()A data.frame with the quality metrics for each rule.
to_latex()Export to LaTeX
RuleSet$to_latex(
print = TRUE,
ncols = 1,
numbered = TRUE,
numbers = seq_len(self$cardinality())
)print(logical) Print to output?
ncols(integer) Number of columns for the output.
numbered(logical) If TRUE (default), implications will be numbered in the output.
numbers(vector) If numbered, use these elements to enumerate the implications. The default is to enumerate 1, 2, ..., but can be changed.
A string in LaTeX format that prints nicely all the rules.
get_LHS_matrix()Get internal LHS matrix
RuleSet$get_LHS_matrix()A sparse matrix representing the LHS of the rules in the set.
get_RHS_matrix()Get internal RHS matrix
RuleSet$get_RHS_matrix()A sparse matrix representing the RHS of the rules in the set.
filter()Filter rules by attributes in LHS and RHS
RuleSet$filter(
lhs = NULL,
not_lhs = NULL,
rhs = NULL,
not_rhs = NULL,
drop = FALSE
)lhs(character vector) Names of the attributes to filter the LHS by. If NULL, no filtering is done on the LHS.
not_lhs(character vector) Names of the attributes to not include in the LHS. If NULL (the default), it is not considered at all.
rhs(character vector) Names of the attributes to filter the RHS by. If NULL, no filtering is done on the RHS.
not_rhs(character vector) Names of the attributes to not include in the RHS. If NULL (the default), it is not considered at all.
drop(logical) Remove the rest of attributes in RHS?
A RuleSet (or subclass) that is a subset of the current set, only with those rules which have the attributes in lhs and rhs in their LHS and RHS, respectively.
get_implications()Extract the implications with confidence 1
RuleSet$get_implications()An ImplicationSet object containing only the rules with confidence 1.
support()Compute support of each rule
RuleSet$support()A vector with the support of each rule.
confidence()Compute the confidence of each rule
RuleSet$confidence()A numeric vector with the confidence of each rule.
to_json()Export the rule set to JSON
RuleSet$to_json(file = NULL, return_list = FALSE)file(character) The path of the file to save the JSON to.
return_list(logical) If TRUE, returns the list representation instead of the JSON string.
A JSON string representing the rule set, or a list if return_list is TRUE.
clone()The objects of this class are cloneable with this method.
RuleSet$clone(deep = FALSE)deepWhether to make a deep clone.