prune.rulelist: 'prune' rules of a rulelist

View source: R/rulelist.R

prune.rulelistR Documentation

prune rules of a rulelist

Description

Prune the rulelist by suggesting to keep first 'k' rules based on metrics computed by calculate

Usage

## S3 method for class 'rulelist'
prune(
  tree,
  metrics_to_exclude = NULL,
  stop_expr_string = "relative__cumulative_coverage >= 0.9",
  min_n_rules = 1,
  ...
)

Arguments

tree

A rulelist

metrics_to_exclude

(character vector or NULL) Names of metrics not to be calculated. See calculate for the list of default metrics.

stop_expr_string

(string default: "relative__cumulative_coverage >= 0.9") Parsable condition

min_n_rules

(positive integer) Minimum number of rules to keep

...

Named list of custom metrics passed to calculate

Details

  1. Metrics are computed using calculate. 2. Relative metrics (prepended by 'relative__') are calculated by dividing each metric by its max value. 3. The first rule in rulelist order which meets the 'stop_expr_string' criteria is stored (say 'pos'). Print method suggests to keep rules until pos.

Value

Object of class 'prune_ruleslist' with these components: 1. pruned: ruleset keeping only first 'pos' rows. 2. n_pruned_rules: pos. If stop criteria is never met, then pos = nrow(ruleset) 3. n_total_rules: nrow(ruleset), 4. metrics_df: Dataframe with metrics and relative metrics 5. stop_expr_string

See Also

rulelist, tidy, augment, predict, calculate, prune, reorder

Examples

library("magrittr")
model_c5  = C50::C5.0(Attrition ~., data = modeldata::attrition, rules = TRUE)
tidy_c5   = tidy(model_c5) %>%
            set_validation_data(modeldata::attrition, "Attrition") %>%
            set_keys(NULL)

#' prune with defaults
prune_obj = prune(tidy_c5)
#' note that all other metrics are visible in the print output
prune_obj
plot(prune_obj)
prune_obj$pruned

#' prune with a different stop_expr_string threshold
prune_obj = prune(tidy_c5,
                  stop_expr_string = "relative__cumulative_coverage >= 0.2"
                  )
prune_obj #' as expected, has smaller then 10 rules as compared to default args
plot(prune_obj)
prune_obj$pruned

#' prune with a different stop_expr_string metric
st = "relative__cumulative_overlap <= 0.7 & relative__cumulative_overlap > 0"
prune_obj = prune(tidy_c5, stop_expr_string = st)
prune_obj #' as expected, has smaller then 10 rules as compared to default args
plot(prune_obj)
prune_obj$pruned


tidyrules documentation built on June 30, 2024, 1:07 a.m.