prune.rulelist | R Documentation |
prune
rules of a rulelistPrune the rulelist by suggesting to keep first 'k' rules based on metrics computed by calculate
## S3 method for class 'rulelist'
prune(
tree,
metrics_to_exclude = NULL,
stop_expr_string = "relative__cumulative_coverage >= 0.9",
min_n_rules = 1,
...
)
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 |
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.
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
rulelist, tidy, augment, predict, calculate, prune, reorder
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.