Each row corresponds to a rule. A rule can be copied into `dplyr::filter` to filter the observations corresponding to a rule

# S3 method for C5.0
tidyRules(object, ...)

Arguments

object

Fitted model object with rules

...

Other arguments (See details)

Value

A tibble where each row corresponds to a rule. The columns are: support, confidence, lift, lhs, rhs, n_conditions

Details

Optional named arguments:

  • laplace(flag, default: TRUE) is supported. This computes confidence with laplace correction as documented under 'Rulesets' here: [C5 doc](https://www.rulequest.com/see5-unix.html).

  • language (string, default: "r"): language where the rules are parsable. The allowed options is one among: r, python, sql

Examples

data("attrition", package = "modeldata") attrition <- tibble::as_tibble(attrition) c5_model <- C50::C5.0(Attrition ~., data = attrition, rules = TRUE) summary(c5_model)
#> #> Call: #> C5.0.formula(formula = Attrition ~ ., data = attrition, rules = TRUE) #> #> #> C5.0 [Release 2.07 GPL Edition] Thu Jun 4 17:35:29 2020 #> ------------------------------- #> #> Class specified by attribute `outcome' #> #> Read 1470 cases (31 attributes) from undefined.data #> #> Rules: #> #> Rule 1: (521/30, lift 1.1) #> EnvironmentSatisfaction in [Medium-Very_High] #> JobInvolvement in [Medium-Very_High] #> OverTime = No #> TrainingTimesLastYear > 1 #> WorkLifeBalance in [Better-Best] #> -> class No [0.941] #> #> Rule 2: (195/14, lift 1.1) #> JobRole = Research_Scientist #> OverTime = No #> -> class No [0.924] #> #> Rule 3: (1347/183, lift 1.0) #> TotalWorkingYears > 2 #> -> class No [0.864] #> #> Rule 4: (16, lift 5.9) #> JobLevel <= 1 #> MonthlyIncome <= 2468 #> OverTime = Yes #> TotalWorkingYears > 2 #> YearsAtCompany <= 3 #> -> class Yes [0.944] #> #> Rule 5: (13, lift 5.8) #> DailyRate <= 722 #> JobLevel <= 1 #> MonthlyIncome <= 2468 #> OverTime = Yes #> TotalWorkingYears > 2 #> -> class Yes [0.933] #> #> Rule 6: (9, lift 5.6) #> EnvironmentSatisfaction in [Low-Medium] #> MaritalStatus in {Divorced, Married} #> NumCompaniesWorked > 4 #> OverTime = Yes #> PerformanceRating = Excellent #> RelationshipSatisfaction in [Low-High] #> -> class Yes [0.909] #> #> Rule 7: (9, lift 5.6) #> EnvironmentSatisfaction in [Low-Medium] #> Gender = Male #> MaritalStatus in {Divorced, Married} #> NumCompaniesWorked > 4 #> OverTime = Yes #> PerformanceRating = Excellent #> -> class Yes [0.909] #> #> Rule 8: (6, lift 5.4) #> JobRole = Laboratory_Technician #> MaritalStatus = Single #> MonthlyIncome > 2468 #> OverTime = Yes #> TrainingTimesLastYear <= 2 #> -> class Yes [0.875] #> #> Rule 9: (14/1, lift 5.4) #> JobRole in {Laboratory_Technician, Sales_Representative} #> MonthlyIncome <= 2657 #> TotalWorkingYears <= 2 #> WorkLifeBalance in [Bad-Good] #> -> class Yes [0.875] #> #> Rule 10: (13/1, lift 5.4) #> Department = Sales #> MaritalStatus = Single #> OverTime = Yes #> YearsSinceLastPromotion > 1 #> -> class Yes [0.867] #> #> Rule 11: (5, lift 5.3) #> Age <= 44 #> OverTime = No #> TotalWorkingYears > 2 #> WorkLifeBalance = Bad #> YearsWithCurrManager <= 0 #> -> class Yes [0.857] #> #> Rule 12: (5, lift 5.3) #> EducationField = Life_Sciences #> EnvironmentSatisfaction in [Low-Medium] #> JobInvolvement = Low #> MonthlyIncome > 2468 #> OverTime = Yes #> -> class Yes [0.857] #> #> Rule 13: (5, lift 5.3) #> JobInvolvement = Low #> OverTime = No #> TotalWorkingYears <= 2 #> -> class Yes [0.857] #> #> Rule 14: (5, lift 5.3) #> Department = Sales #> JobInvolvement in [Low-Medium] #> JobSatisfaction in [Medium-High] #> MaritalStatus = Single #> OverTime = Yes #> YearsSinceLastPromotion <= 1 #> -> class Yes [0.857] #> #> Rule 15: (4, lift 5.2) #> JobRole in {Laboratory_Technician, Sales_Representative} #> TotalWorkingYears <= 2 #> TrainingTimesLastYear <= 1 #> -> class Yes [0.833] #> #> Rule 16: (4, lift 5.2) #> JobSatisfaction = High #> OverTime = No #> WorkLifeBalance = Bad #> YearsSinceLastPromotion > 6 #> -> class Yes [0.833] #> #> Rule 17: (4, lift 5.2) #> Department = Sales #> JobInvolvement = Very_High #> MaritalStatus = Single #> OverTime = Yes #> -> class Yes [0.833] #> #> Rule 18: (8/1, lift 5.0) #> EnvironmentSatisfaction = Low #> JobRole = Laboratory_Technician #> TotalWorkingYears <= 2 #> -> class Yes [0.800] #> #> Rule 19: (6/1, lift 4.7) #> JobRole = Human_Resources #> TotalWorkingYears <= 2 #> -> class Yes [0.750] #> #> Rule 20: (35/10, lift 4.4) #> OverTime = Yes #> TotalWorkingYears <= 2 #> -> class Yes [0.703] #> #> Rule 21: (7/2, lift 4.1) #> OverTime = No #> TotalWorkingYears > 2 #> WorkLifeBalance = Bad #> YearsWithCurrManager <= 0 #> -> class Yes [0.667] #> #> Rule 22: (49/17, lift 4.0) #> Department = Sales #> MaritalStatus = Single #> OverTime = Yes #> -> class Yes [0.647] #> #> Rule 23: (6/2, lift 3.9) #> OverTime = No #> WorkLifeBalance = Bad #> YearsSinceLastPromotion > 6 #> -> class Yes [0.625] #> #> Rule 24: (57/31, lift 2.8) #> EnvironmentSatisfaction in [Low-Medium] #> MonthlyRate > 16620 #> OverTime = Yes #> -> class Yes [0.458] #> #> Default class: No #> #> #> Evaluation on training data (1470 cases): #> #> Rules #> ---------------- #> No Errors #> #> 24 134( 9.1%) << #> #> #> (a) (b) <-classified as #> ---- ---- #> 1218 15 (a): class No #> 119 118 (b): class Yes #> #> #> Attribute usage: #> #> 95.71% TotalWorkingYears #> 54.22% OverTime #> 40.20% EnvironmentSatisfaction #> 37.28% WorkLifeBalance #> 36.73% JobInvolvement #> 36.12% TrainingTimesLastYear #> 15.51% JobRole #> 4.56% MaritalStatus #> 3.88% MonthlyRate #> 3.33% Department #> 3.33% MonthlyIncome #> 1.63% JobLevel #> 1.63% YearsSinceLastPromotion #> 1.09% YearsAtCompany #> 0.88% DailyRate #> 0.82% NumCompaniesWorked #> 0.82% PerformanceRating #> 0.61% Gender #> 0.61% JobSatisfaction #> 0.61% RelationshipSatisfaction #> 0.48% YearsWithCurrManager #> 0.34% Age #> 0.34% EducationField #> #> #> Time: 0.0 secs #>
tidyRules(c5_model)
#> # A tibble: 24 x 8 #> id LHS RHS support confidence lift rule_number trial_number #> <int> <chr> <chr> <int> <dbl> <dbl> <int> <int> #> 1 1 EnvironmentSat… No 521 0.941 1.1 1 1 #> 2 2 JobRole == 'Re… No 195 0.924 1.1 2 1 #> 3 3 TotalWorkingYe… No 1347 0.864 1 3 1 #> 4 4 JobLevel <= 1 … Yes 16 0.944 5.9 4 1 #> 5 5 DailyRate <= 7… Yes 13 0.933 5.8 5 1 #> 6 6 EnvironmentSat… Yes 9 0.909 5.6 6 1 #> 7 7 EnvironmentSat… Yes 9 0.909 5.6 7 1 #> 8 8 JobRole == 'La… Yes 6 0.875 5.4 8 1 #> 9 9 JobRole %in% c… Yes 14 0.875 5.4 9 1 #> 10 10 Department == … Yes 13 0.867 5.4 10 1 #> # … with 14 more rows