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

# S3 method for 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

Value

A dataframe. See Details.

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.

See also

Examples

model_c5 = C50::C5.0(species ~.,
                     data = palmerpenguins::penguins,
                     trials = 5,
                     rules = TRUE
                     )
tidy_c5 = tidy(model_c5)
tidy_c5
#> ---- Rulelist --------------------------------
#> ▶ Keys: trial_nbr
#> ▶ Number of distinct keys: 5
#> ▶ Number of rules: 26
#> ▶ Model type: C5
#> ▶ Estimation type: classification
#> ▶ Is validation data set: FALSE
#> 
#> 
#>    rule_nbr trial_nbr LHS                         RHS   support confidence  lift
#>       <int>     <int> <chr>                       <fct>   <int>      <dbl> <dbl>
#>  1        1         1 ( island == 'Biscoe' ) & (… Gent…     122      0.992   2.8
#>  2        2         1 ( bill_length_mm <= 43.3 )… Adel…      68      0.986   2.2
#>  3        3         1 ( island == 'Dream' ) & ( … Chin…      48      0.98    5  
#>  4        4         1 ( bill_length_mm > 42.3 ) … Chin…      34      0.944   4.8
#>  5        5         1 ( flipper_length_mm <= 206… Adel…     213      0.698   1.6
#>  6        1         2 ( bill_length_mm <= 40.8 )  Adel…      86      0.989   3  
#>  7        2         2 ( island == 'Torgersen' )   Adel…      39      0.976   2.9
#>  8        3         2 ( island == 'Biscoe' ) & (… Adel…      32      0.971   2.9
#>  9        4         2 ( island == 'Dream' ) & ( … Chin…      87      0.910   3.9
#> 10        5         2 ( island == 'Biscoe' )      Gent…     183      0.816   1.9
#> # ℹ 16 more rows
#> ----------------------------------------------

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