Learn R Programming

tidyrules

tidyrules R package provides a framework to work with decision rules. Rules can be extracted from supported models, augmented with (custom) metrics using validation data, manipulated using standard dataframe operations, reordered and pruned based on a metric, predict on unseen (test) data. Utilities include; Creating a rulelist manually, Exporting a rulelist as a SQL case statement and so on. The package offers two classes; rulelist and ruleset based on dataframe.

website: https://talegari.github.io/tidyrules/

Example

library(tidyrules)
model_c5 = C50::C5.0(Species ~ ., data = iris, rules = TRUE)
pander::pandoc.table(tidy(model_c5), split.tables = 120)
#> 
#> ----------------------------------------------------------------------------------------------
#>  rule_nbr   trial_nbr              LHS                  RHS       support   confidence   lift 
#> ---------- ----------- ---------------------------- ------------ --------- ------------ ------
#>     1           1        ( Petal.Length <= 1.9 )       setosa       50        0.9808     2.9  
#> 
#>     2           1       ( Petal.Length > 1.9 ) & (   versicolor     48         0.96      2.9  
#>                         Petal.Length <= 4.9 ) & (                                             
#>                            Petal.Width <= 1.7 )                                               
#> 
#>     3           1         ( Petal.Width > 1.7 )      virginica      46        0.9583     2.9  
#> 
#>     4           1         ( Petal.Length > 4.9 )     virginica      46        0.9375     2.8  
#> ----------------------------------------------------------------------------------------------

Installation

You can install the released version of tidyrules from CRAN with:

install.packages("tidyrules")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("talegari/tidyrules")

Copy Link

Version

Install

install.packages('tidyrules')

Monthly Downloads

268

Version

0.2.7

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

KS Srikanth

Last Published

June 29th, 2024

Functions in tidyrules (0.2.7)

predict.rulelist

predict method for a rulelist
predict_all_rulelist

with or without keys
predict_all_nokeys_rulelist

as the name says
prune.rulelist

prune rules of a rulelist
prune

predict_nokeys_rulelist

as the name says
strSplitSingle

String split a string
print.prune_rulelist

Print method for prune_rulelist class
tidy.C5.0

Get the rulelist from a C5 model
strReplaceReduce

Sequential string replace
strTail

Vectorized semantic equivalent of tail for a string
predict_rulelist

with or without keys
rulelist

Rulelist
reorder

reorder generic
reorder.rulelist

Reorder the rules/rows of a rulelist
removeEmptyLines

Remove empty lines
print.rulelist

Print method for rulelist class
tidy

print.ruleset

Print method for ruleset class
set_validation_data

Add validation_data to a rulelist
strHead

Vectorized semantic equivalent of 'head' for a string
tidy.cubist

Get the rulelist from a cubist model
tidy.rpart

ruleset

Ruleset
set_keys

Set keys for a rulelist
tidy.constparty

Get the rulelist from a party model
varSpec

Get variable specification for a Cubist/C5 object
to_sql_case

Extract SQL case statement from a rulelist
as_rulelist

as_rulelist generic from tidyrules package
augment

as_rulelist.data.frame

as_rulelist method for a data.frame
addBackquotes

Add backquotes
augment.rulelist

Augment a rulelist
as_ruleset

Get a ruleset from a rulelist
plot.rulelist

Plot method for rulelist
package_tidyrules

tidyrules
plot.prune_rulelist

Plot method for prune_rulelist class
predict.ruleset

predict method for a ruleset
convert_rule_flavor

Convert a R parsable rule to python/sql parsable rule
calculate.rulelist

calculate metrics for a rulelist
calculate

augment_regr_no_keys

as the name says
augment_regr_keys

as the name says
positionSpaceOutsideSinglequotes

Position of space outside single quotes
augment_class_no_keys

as the name says
augment_class_keys

as the name says