predict.rulelist: 'predict' method for a rulelist

View source: R/rulelist.R

predict.rulelistR Documentation

predict method for a rulelist

Description

Predicts rule_nbr applicable (as per the order in rulelist) for a row_nbr (per key) in new_data

Usage

## S3 method for class 'rulelist'
predict(object, new_data, multiple = FALSE, ...)

Arguments

object

A rulelist

new_data

(dataframe)

multiple

(flag, default: FALSE) Whether to output all rule numbers applicable for a row. If FALSE, the first satisfying rule is provided.

...

unused

Details

If a row_nbr is covered more than one rule_nbr per 'keys', then rule_nbr appearing earlier (as in row order of the rulelist) takes precedence.

Output Format

  • When multiple is FALSE(default), output is a dataframe with three or more columns: row_number (int), columns corresponding to 'keys', rule_nbr (int).

  • When multiple is TRUE, output is a dataframe with three or more columns: row_number (int), columns corresponding to 'keys', rule_nbr (list column of integers).

  • If a row number and 'keys' combination is not covered by any rule, then rule_nbr column has missing value.

Value

A dataframe. See Details.

See Also

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

Examples

model_c5 = C50::C5.0(species ~.,
                     data = palmerpenguins::penguins,
                     trials = 5,
                     rules = TRUE
                     )
tidy_c5 = tidy(model_c5)
tidy_c5

output_1 = predict(tidy_c5, palmerpenguins::penguins)
output_1 # different rules per 'keys' (`trial_nbr` here)

output_2 = predict(tidy_c5, palmerpenguins::penguins, multiple = TRUE)
output_2 # `rule_nbr` is a list-column of integer vectors


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