Each row corresponds to a rule
# S3 method for rpart
tidy(x, ...)
rpart::rpart model
Other arguments (currently unused)
A rulelist object
For rpart rules, one should build the model without ordered factor variable. We recommend you to convert ordered factor to factor or integer class.
For rpart::rpart classification model:
Output columns are: rule_nbr
, LHS
, RHS
, support
, confidence
, lift
.
The rules are sorted in this order: desc(confidence)
, desc(lift)
,
desc(support)
.
For rpart::rpart regression(anova) model:
Output columns are: rule_nbr
, LHS
, RHS
, support
.
The rules are sorted in this order: desc(support)
.
model_class_rpart = rpart::rpart(Species ~ ., data = iris)
tidy(model_class_rpart)
#> ---- Rulelist --------------------------------
#> ▶ Keys: NULL
#> ▶ Number of rules: 3
#> ▶ Model type: rpart
#> ▶ Estimation type: classification
#> ▶ Is validation data set: FALSE
#>
#>
#> rule_nbr LHS RHS support confidence lift
#> <int> <chr> <fct> <int> <dbl> <dbl>
#> 1 1 ( Petal.Length < 2.45 ) seto… 50 0.981 2.94
#> 2 2 ( Petal.Length >= 2.45 ) & ( Petal.Wi… virg… 46 0.958 2.88
#> 3 3 ( Petal.Length >= 2.45 ) & ( Petal.Wi… vers… 54 0.893 2.68
#> ----------------------------------------------
model_regr_rpart = rpart::rpart(Sepal.Length ~ ., data = iris)
tidy(model_regr_rpart)
#> ---- Rulelist --------------------------------
#> ▶ Keys: NULL
#> ▶ Number of rules: 7
#> ▶ Model type: rpart
#> ▶ Estimation type: regression
#> ▶ Is validation data set: FALSE
#>
#>
#> rule_nbr LHS RHS support
#> <int> <chr> <dbl> <int>
#> 1 1 ( Petal.Length < 4.25 ) & ( Petal.Length < 3.4 ) & ( S… 5.17 33
#> 2 2 ( Petal.Length >= 4.25 ) & ( Petal.Length < 6.05 ) & (… 6.05 33
#> 3 3 ( Petal.Length >= 4.25 ) & ( Petal.Length < 6.05 ) & (… 6.60 25
#> 4 4 ( Petal.Length < 4.25 ) & ( Petal.Length < 3.4 ) & ( S… 4.73 20
#> 5 5 ( Petal.Length < 4.25 ) & ( Petal.Length >= 3.4 ) 5.64 20
#> 6 6 ( Petal.Length >= 4.25 ) & ( Petal.Length < 6.05 ) & (… 6.53 10
#> 7 7 ( Petal.Length >= 4.25 ) & ( Petal.Length >= 6.05 ) 7.58 9
#> ----------------------------------------------