├── .github ├── .gitignore └── workflows │ └── R-CMD-check.yaml ├── vignettes ├── .gitignore ├── .DS_Store └── articles │ ├── using_tidyrules_cache │ └── html │ │ └── __packages │ ├── .DS_Store │ └── tidyrules_schematic.png ├── .DS_Store ├── R ├── .DS_Store ├── ruleset.R └── package.R ├── man ├── .DS_Store ├── figures │ └── tidyrules_schematic.png ├── ruleset.Rd ├── augment_regr_keys.Rd ├── augment_class_keys.Rd ├── augment_regr_no_keys.Rd ├── augment_class_no_keys.Rd ├── print.prune_rulelist.Rd ├── predict_rulelist.Rd ├── predict_nokeys_rulelist.Rd ├── predict_all_rulelist.Rd ├── predict_all_nokeys_rulelist.Rd ├── plot.prune_rulelist.Rd ├── addBackquotes.Rd ├── removeEmptyLines.Rd ├── strSplitSingle.Rd ├── reorder.Rd ├── strReplaceReduce.Rd ├── as_ruleset.Rd ├── augment.Rd ├── prune.Rd ├── positionSpaceOutsideSinglequotes.Rd ├── as_rulelist.Rd ├── strHead.Rd ├── strTail.Rd ├── calculate.Rd ├── convert_rule_flavor.Rd ├── print.rulelist.Rd ├── print.ruleset.Rd ├── varSpec.Rd ├── tidy.Rd ├── predict.ruleset.Rd ├── package_tidyrules.Rd ├── plot.rulelist.Rd ├── to_sql_case.Rd ├── tidy.cubist.Rd ├── as_rulelist.data.frame.Rd ├── tidy.C5.0.Rd ├── set_keys.Rd ├── tidy.constparty.Rd ├── reorder.rulelist.Rd ├── tidy.rpart.Rd ├── set_validation_data.Rd ├── predict.rulelist.Rd ├── prune.rulelist.Rd ├── augment.rulelist.Rd ├── rulelist.Rd └── calculate.rulelist.Rd ├── tests ├── .DS_Store ├── testthat.R └── testthat │ ├── test-party.R │ ├── test-c5.R │ ├── test-rpart.R │ └── test-cubist.R ├── docs ├── reference │ ├── Rplot001.png │ ├── Rplot002.png │ ├── Rplot003.png │ ├── plot.rulelist-1.png │ ├── prune.rulelist-1.png │ ├── prune.rulelist-2.png │ ├── prune.rulelist-3.png │ ├── figures │ │ └── tidyrules_schematic.png │ ├── ruleset.html │ ├── augment_regr_keys.html │ ├── augment_class_keys.html │ ├── augment_regr_no_keys.html │ ├── augment_class_no_keys.html │ ├── predict_nokeys_rulelist.html │ ├── predict_rulelist.html │ ├── predict_all_nokeys_rulelist.html │ ├── predict_all_rulelist.html │ ├── print.prune_rulelist.html │ ├── plot.prune_rulelist.html │ ├── reorder.html │ └── ruleRToSQL.html ├── articles │ ├── tidyrules_schematic.png │ ├── using_tidyrules_files │ │ └── figure-html │ │ │ ├── unnamed-chunk-12-1.png │ │ │ └── unnamed-chunk-16-1.png │ ├── tidyrules_vignette_files │ │ └── figure-html │ │ │ ├── unnamed-chunk-11-1.png │ │ │ └── unnamed-chunk-12-1.png │ └── index.html ├── pkgdown.yml ├── link.svg ├── bootstrap-toc.css ├── docsearch.js ├── sitemap.xml ├── pkgdown.js ├── bootstrap-toc.js ├── 404.html └── authors.html ├── .gitignore ├── .travis.yml ├── cran-comments.md ├── .Rbuildignore ├── tidyrules.Rproj ├── NEWS.md ├── README.Rmd ├── DESCRIPTION ├── NAMESPACE └── README.md /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | -------------------------------------------------------------------------------- /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talegari/tidyrules/HEAD/.DS_Store -------------------------------------------------------------------------------- /R/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talegari/tidyrules/HEAD/R/.DS_Store -------------------------------------------------------------------------------- /man/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talegari/tidyrules/HEAD/man/.DS_Store -------------------------------------------------------------------------------- /tests/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talegari/tidyrules/HEAD/tests/.DS_Store -------------------------------------------------------------------------------- /vignettes/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talegari/tidyrules/HEAD/vignettes/.DS_Store -------------------------------------------------------------------------------- /vignettes/articles/using_tidyrules_cache/html/__packages: -------------------------------------------------------------------------------- 1 | dplyr 2 | testthat 3 | tidyrules 4 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(tidyrules) 3 | 4 | test_check("tidyrules") 5 | -------------------------------------------------------------------------------- /docs/reference/Rplot001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talegari/tidyrules/HEAD/docs/reference/Rplot001.png -------------------------------------------------------------------------------- /docs/reference/Rplot002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talegari/tidyrules/HEAD/docs/reference/Rplot002.png -------------------------------------------------------------------------------- /docs/reference/Rplot003.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talegari/tidyrules/HEAD/docs/reference/Rplot003.png -------------------------------------------------------------------------------- /vignettes/articles/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talegari/tidyrules/HEAD/vignettes/articles/.DS_Store -------------------------------------------------------------------------------- /docs/reference/plot.rulelist-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talegari/tidyrules/HEAD/docs/reference/plot.rulelist-1.png -------------------------------------------------------------------------------- /docs/articles/tidyrules_schematic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talegari/tidyrules/HEAD/docs/articles/tidyrules_schematic.png -------------------------------------------------------------------------------- /docs/reference/prune.rulelist-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talegari/tidyrules/HEAD/docs/reference/prune.rulelist-1.png -------------------------------------------------------------------------------- /docs/reference/prune.rulelist-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talegari/tidyrules/HEAD/docs/reference/prune.rulelist-2.png -------------------------------------------------------------------------------- /docs/reference/prune.rulelist-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talegari/tidyrules/HEAD/docs/reference/prune.rulelist-3.png -------------------------------------------------------------------------------- /man/figures/tidyrules_schematic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talegari/tidyrules/HEAD/man/figures/tidyrules_schematic.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | .Rprofile 6 | renv* 7 | *.Rproj 8 | .DS_Store 9 | using_tidyrules_cache -------------------------------------------------------------------------------- /vignettes/articles/tidyrules_schematic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talegari/tidyrules/HEAD/vignettes/articles/tidyrules_schematic.png -------------------------------------------------------------------------------- /docs/reference/figures/tidyrules_schematic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talegari/tidyrules/HEAD/docs/reference/figures/tidyrules_schematic.png -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # R for travis: see documentation at https://docs.travis-ci.com/user/languages/r 2 | 3 | language: R 4 | sudo: false 5 | cache: packages 6 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: '3.2' 2 | pkgdown: 2.1.1 3 | pkgdown_sha: ~ 4 | articles: 5 | articles/using_tidyrules: using_tidyrules.html 6 | last_built: 2025-02-04T18:22Z 7 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## R CMD check results 2 | 3 | 0 errors | 0 warnings | 1 note 4 | 5 | These are not spelling errors, it is standard terminology in rule based systems: 'rulelist', 'ruleset' 6 | -------------------------------------------------------------------------------- /docs/articles/using_tidyrules_files/figure-html/unnamed-chunk-12-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talegari/tidyrules/HEAD/docs/articles/using_tidyrules_files/figure-html/unnamed-chunk-12-1.png -------------------------------------------------------------------------------- /docs/articles/using_tidyrules_files/figure-html/unnamed-chunk-16-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talegari/tidyrules/HEAD/docs/articles/using_tidyrules_files/figure-html/unnamed-chunk-16-1.png -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^renv$ 2 | ^renv\.lock$ 3 | ^\.travis\.yml$ 4 | ^.*\.Rproj$ 5 | ^\.Rproj\.user$ 6 | docs 7 | ^README\.Rmd$ 8 | ^\.github$ 9 | ^vignettes/articles$ 10 | ^cran-comments\.md$ 11 | -------------------------------------------------------------------------------- /docs/articles/tidyrules_vignette_files/figure-html/unnamed-chunk-11-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talegari/tidyrules/HEAD/docs/articles/tidyrules_vignette_files/figure-html/unnamed-chunk-11-1.png -------------------------------------------------------------------------------- /docs/articles/tidyrules_vignette_files/figure-html/unnamed-chunk-12-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talegari/tidyrules/HEAD/docs/articles/tidyrules_vignette_files/figure-html/unnamed-chunk-12-1.png -------------------------------------------------------------------------------- /man/ruleset.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ruleset.R 3 | \name{ruleset} 4 | \alias{ruleset} 5 | \title{Ruleset} 6 | \description{ 7 | ruleset class is a piggyback class that inherits \link{rulelist} 8 | class for convenience of \link{print} and \link{predict} methods. 9 | } 10 | -------------------------------------------------------------------------------- /man/augment_regr_keys.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{augment_regr_keys} 4 | \alias{augment_regr_keys} 5 | \title{as the name says} 6 | \usage{ 7 | augment_regr_keys(x, new_data, y_name, weight, ...) 8 | } 9 | \description{ 10 | as the name says 11 | not to be exported 12 | } 13 | \keyword{internal} 14 | -------------------------------------------------------------------------------- /man/augment_class_keys.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{augment_class_keys} 4 | \alias{augment_class_keys} 5 | \title{as the name says} 6 | \usage{ 7 | augment_class_keys(x, new_data, y_name, weight, ...) 8 | } 9 | \description{ 10 | as the name says 11 | not to be exported 12 | } 13 | \keyword{internal} 14 | -------------------------------------------------------------------------------- /man/augment_regr_no_keys.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{augment_regr_no_keys} 4 | \alias{augment_regr_no_keys} 5 | \title{as the name says} 6 | \usage{ 7 | augment_regr_no_keys(x, new_data, y_name, weight, ...) 8 | } 9 | \description{ 10 | as the name says 11 | not to be exported 12 | } 13 | \keyword{internal} 14 | -------------------------------------------------------------------------------- /man/augment_class_no_keys.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{augment_class_no_keys} 4 | \alias{augment_class_no_keys} 5 | \title{as the name says} 6 | \usage{ 7 | augment_class_no_keys(x, new_data, y_name, weight, ...) 8 | } 9 | \description{ 10 | as the name says 11 | not to be exported 12 | } 13 | \keyword{internal} 14 | -------------------------------------------------------------------------------- /man/print.prune_rulelist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{print.prune_rulelist} 4 | \alias{print.prune_rulelist} 5 | \title{Print method for \code{prune_rulelist} class} 6 | \usage{ 7 | \method{print}{prune_rulelist}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{A 'prune_rulelist' object} 11 | 12 | \item{...}{unused} 13 | } 14 | \description{ 15 | Print method for \code{prune_rulelist} class 16 | } 17 | -------------------------------------------------------------------------------- /man/predict_rulelist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{predict_rulelist} 4 | \alias{predict_rulelist} 5 | \title{with or without keys} 6 | \usage{ 7 | predict_rulelist(rulelist, new_data) 8 | } 9 | \arguments{ 10 | \item{rulelist}{rulelist} 11 | 12 | \item{new_data}{new_data} 13 | } 14 | \value{ 15 | dataframe 16 | } 17 | \description{ 18 | uses predict_nokeys_rulelist 19 | } 20 | \keyword{internal} 21 | -------------------------------------------------------------------------------- /tidyrules.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | ProjectId: ce1e98ec-5f0c-4808-8786-3cb6ff69036f 3 | 4 | RestoreWorkspace: Default 5 | SaveWorkspace: Default 6 | AlwaysSaveHistory: Default 7 | 8 | EnableCodeIndexing: Yes 9 | UseSpacesForTab: Yes 10 | NumSpacesForTab: 2 11 | Encoding: UTF-8 12 | 13 | RnwWeave: Sweave 14 | LaTeX: pdfLaTeX 15 | 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | -------------------------------------------------------------------------------- /man/predict_nokeys_rulelist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{predict_nokeys_rulelist} 4 | \alias{predict_nokeys_rulelist} 5 | \title{as the name says} 6 | \usage{ 7 | predict_nokeys_rulelist(rulelist, new_data) 8 | } 9 | \arguments{ 10 | \item{rulelist}{rulelist} 11 | 12 | \item{new_data}{new_data} 13 | } 14 | \value{ 15 | dataframe 16 | } 17 | \description{ 18 | as the name says 19 | } 20 | \keyword{internal} 21 | -------------------------------------------------------------------------------- /man/predict_all_rulelist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{predict_all_rulelist} 4 | \alias{predict_all_rulelist} 5 | \title{with or without keys} 6 | \usage{ 7 | predict_all_rulelist(rulelist, new_data) 8 | } 9 | \arguments{ 10 | \item{rulelist}{rulelist} 11 | 12 | \item{new_data}{new_data} 13 | } 14 | \value{ 15 | dataframe 16 | } 17 | \description{ 18 | uses predict_all_nokeys_rulelist 19 | } 20 | \keyword{internal} 21 | -------------------------------------------------------------------------------- /man/predict_all_nokeys_rulelist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{predict_all_nokeys_rulelist} 4 | \alias{predict_all_nokeys_rulelist} 5 | \title{as the name says} 6 | \usage{ 7 | predict_all_nokeys_rulelist(rulelist, new_data) 8 | } 9 | \arguments{ 10 | \item{rulelist}{rulelist} 11 | 12 | \item{new_data}{new_data} 13 | } 14 | \value{ 15 | dataframe 16 | } 17 | \description{ 18 | as the name says 19 | } 20 | \keyword{internal} 21 | -------------------------------------------------------------------------------- /man/plot.prune_rulelist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{plot.prune_rulelist} 4 | \alias{plot.prune_rulelist} 5 | \title{Plot method for \code{prune_rulelist} class} 6 | \usage{ 7 | \method{plot}{prune_rulelist}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{A 'prune_rulelist' object} 11 | 12 | \item{...}{unused} 13 | } 14 | \value{ 15 | ggplot2 object (invisibly) 16 | } 17 | \description{ 18 | Plot method for \code{prune_rulelist} class 19 | } 20 | -------------------------------------------------------------------------------- /man/addBackquotes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{addBackquotes} 4 | \alias{addBackquotes} 5 | \title{Add backquotes} 6 | \usage{ 7 | addBackquotes(string) 8 | } 9 | \arguments{ 10 | \item{string}{character vector} 11 | } 12 | \value{ 13 | character vector 14 | } 15 | \description{ 16 | (vectorized) Add backquotes when a string has a space in it 17 | } 18 | \examples{ 19 | \donttest{ 20 | tidyrules:::addBackquotes(c("ab", "a b")) 21 | } 22 | 23 | } 24 | \keyword{internal} 25 | -------------------------------------------------------------------------------- /man/removeEmptyLines.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{removeEmptyLines} 4 | \alias{removeEmptyLines} 5 | \title{Remove empty lines} 6 | \usage{ 7 | removeEmptyLines(strings) 8 | } 9 | \arguments{ 10 | \item{strings}{A character vector} 11 | } 12 | \value{ 13 | A character vector 14 | } 15 | \description{ 16 | Remove empty strings from a character vector 17 | } 18 | \examples{ 19 | \donttest{ 20 | tidyrules:::removeEmptyLines(c("abc", "", "d")) 21 | } 22 | 23 | } 24 | \keyword{internal} 25 | -------------------------------------------------------------------------------- /man/strSplitSingle.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{strSplitSingle} 4 | \alias{strSplitSingle} 5 | \title{String split a string} 6 | \usage{ 7 | strSplitSingle(string, pattern) 8 | } 9 | \arguments{ 10 | \item{string}{A string} 11 | 12 | \item{pattern}{Passed as-is to 'stringr::str_split'} 13 | } 14 | \value{ 15 | A character vector 16 | } 17 | \description{ 18 | and return a character vector (not a list) 19 | } 20 | \examples{ 21 | \donttest{ 22 | tidyrules:::strSplitSingle("abc,d", ",") 23 | } 24 | 25 | } 26 | \keyword{internal} 27 | -------------------------------------------------------------------------------- /man/reorder.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{reorder} 4 | \alias{reorder} 5 | \title{reorder generic} 6 | \usage{ 7 | reorder(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{A \link{rulelist}} 11 | 12 | \item{...}{See \link{reorder.rulelist}} 13 | } 14 | \description{ 15 | reorder generic for rulelist 16 | } 17 | \seealso{ 18 | \link{rulelist}, \link{tidy}, \link[=augment.rulelist]{augment}, 19 | \link[=predict.rulelist]{predict}, \link[=calculate.rulelist]{calculate}, 20 | \link[=prune.rulelist]{prune}, \link[=reorder.rulelist]{reorder} 21 | } 22 | -------------------------------------------------------------------------------- /man/strReplaceReduce.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{strReplaceReduce} 4 | \alias{strReplaceReduce} 5 | \title{Sequential string replace} 6 | \usage{ 7 | strReplaceReduce(string, pattern, replacement) 8 | } 9 | \arguments{ 10 | \item{string}{string} 11 | 12 | \item{pattern}{pattern} 13 | 14 | \item{replacement}{replacement} 15 | } 16 | \value{ 17 | character vector 18 | } 19 | \description{ 20 | Sequential string replace via reduce 21 | } 22 | \examples{ 23 | \donttest{ 24 | tidyrules:::strReplaceReduce("abcd", c("ab", "dc"), c("cd", "ab")) 25 | } 26 | 27 | } 28 | \keyword{internal} 29 | -------------------------------------------------------------------------------- /man/as_ruleset.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ruleset.R 3 | \name{as_ruleset} 4 | \alias{as_ruleset} 5 | \title{Get a ruleset from a rulelist} 6 | \usage{ 7 | as_ruleset(rulelist) 8 | } 9 | \arguments{ 10 | \item{rulelist}{A \link{rulelist}} 11 | } 12 | \value{ 13 | A \link{ruleset} 14 | } 15 | \description{ 16 | Returns a ruleset object 17 | } 18 | \examples{ 19 | model_class_party = partykit::ctree(species ~ ., 20 | data = palmerpenguins::penguins 21 | ) 22 | as_ruleset(tidy(model_class_party)) 23 | 24 | } 25 | \seealso{ 26 | \link{rulelist} 27 | } 28 | -------------------------------------------------------------------------------- /man/augment.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{augment} 4 | \alias{augment} 5 | \title{\code{augment} is re-export of \link[generics:augment]{generics::augment} from 6 | \link[=package_tidyrules]{tidyrules} package} 7 | \usage{ 8 | augment(x, ...) 9 | } 10 | \arguments{ 11 | \item{x}{A \link{rulelist}} 12 | 13 | \item{...}{For methods to use} 14 | } 15 | \description{ 16 | See \link{augment.rulelist} 17 | } 18 | \seealso{ 19 | \link{rulelist}, \link{tidy}, \link[=augment.rulelist]{augment}, 20 | \link[=predict.rulelist]{predict}, \link[=calculate.rulelist]{calculate}, 21 | \link[=prune.rulelist]{prune}, \link[=reorder.rulelist]{reorder} 22 | } 23 | -------------------------------------------------------------------------------- /man/prune.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{prune} 4 | \alias{prune} 5 | \title{\code{prune} is re-export of \link[generics:prune]{generics::prune} from 6 | \link[=package_tidyrules]{tidyrules} package} 7 | \usage{ 8 | prune(tree, ...) 9 | } 10 | \arguments{ 11 | \item{tree}{A \link{rulelist}} 12 | 13 | \item{...}{See \link{prune.rulelist}} 14 | } 15 | \description{ 16 | See \link{prune.rulelist} 17 | } 18 | \seealso{ 19 | \link{rulelist}, \link{tidy}, \link[=augment.rulelist]{augment}, 20 | \link[=predict.rulelist]{predict}, \link[=calculate.rulelist]{calculate}, 21 | \link[=prune.rulelist]{prune}, \link[=reorder.rulelist]{reorder} 22 | } 23 | -------------------------------------------------------------------------------- /man/positionSpaceOutsideSinglequotes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{positionSpaceOutsideSinglequotes} 4 | \alias{positionSpaceOutsideSinglequotes} 5 | \title{Position of space outside single quotes} 6 | \usage{ 7 | positionSpaceOutsideSinglequotes(string) 8 | } 9 | \arguments{ 10 | \item{string}{A character vector} 11 | } 12 | \value{ 13 | A integer vector of positions 14 | } 15 | \description{ 16 | (vectorised) Detect the position of space in a string not within 17 | a pair of single quotes 18 | } 19 | \examples{ 20 | \donttest{ 21 | tidyrules:::positionSpaceOutsideSinglequotes(c("hello", "hel' 'o ")) 22 | } 23 | 24 | } 25 | \keyword{internal} 26 | -------------------------------------------------------------------------------- /man/as_rulelist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{as_rulelist} 4 | \alias{as_rulelist} 5 | \title{as_rulelist generic from \link[=package_tidyrules]{tidyrules} package} 6 | \usage{ 7 | as_rulelist(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{object to be coerced to a \link{rulelist}} 11 | 12 | \item{...}{for methods to use} 13 | } 14 | \value{ 15 | A \link{rulelist} 16 | } 17 | \description{ 18 | as_rulelist generic 19 | } 20 | \seealso{ 21 | \link{rulelist}, \link{tidy}, \link[=augment.rulelist]{augment}, 22 | \link[=predict.rulelist]{predict}, \link[=calculate.rulelist]{calculate}, 23 | \link[=prune.rulelist]{prune}, \link[=reorder.rulelist]{reorder} 24 | } 25 | -------------------------------------------------------------------------------- /man/strHead.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{strHead} 4 | \alias{strHead} 5 | \title{Vectorized semantic equivalent of 'head' for a string} 6 | \usage{ 7 | strHead(string, n) 8 | } 9 | \arguments{ 10 | \item{string}{string} 11 | 12 | \item{n}{(integer) Number of characters} 13 | } 14 | \value{ 15 | A string 16 | } 17 | \description{ 18 | Picks the substring starting from the first character 19 | } 20 | \details{ 21 | 'n' can be in the interval [-len + 1, len] (both ends inclusive) 22 | } 23 | \examples{ 24 | \donttest{ 25 | tidyrules:::strHead(c("string", "string2"), 2) 26 | tidyrules:::strHead(c("string", "string2"), -1) 27 | } 28 | 29 | } 30 | \keyword{internal} 31 | -------------------------------------------------------------------------------- /man/strTail.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{strTail} 4 | \alias{strTail} 5 | \title{Vectorized semantic equivalent of tail for a string} 6 | \usage{ 7 | strTail(string, n) 8 | } 9 | \arguments{ 10 | \item{string}{string} 11 | 12 | \item{n}{(integer) Number of characters} 13 | } 14 | \value{ 15 | A string 16 | } 17 | \description{ 18 | Picks the substring starting from the first character 19 | } 20 | \details{ 21 | 'n' can be in the interval [-len + 1, len] (both ends inclusive) 22 | } 23 | \examples{ 24 | \donttest{ 25 | tidyrules:::strTail(c("string", "string2"), 2) 26 | tidyrules:::strTail(c("string", "string2"), -1) 27 | } 28 | 29 | } 30 | \keyword{internal} 31 | -------------------------------------------------------------------------------- /man/calculate.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{calculate} 4 | \alias{calculate} 5 | \title{\code{calculate} is re-export of \link[generics:calculate]{generics::calculate} from 6 | \link[=package_tidyrules]{tidyrules} package} 7 | \usage{ 8 | calculate(x, ...) 9 | } 10 | \arguments{ 11 | \item{x}{A \link{rulelist}} 12 | 13 | \item{...}{See \link{calculate.rulelist}} 14 | } 15 | \description{ 16 | See \link{calculate.rulelist} 17 | } 18 | \seealso{ 19 | \link{rulelist}, \link{tidy}, \link[=augment.rulelist]{augment}, 20 | \link[=predict.rulelist]{predict}, \link[=calculate.rulelist]{calculate}, 21 | \link[=prune.rulelist]{prune}, \link[=reorder.rulelist]{reorder} 22 | } 23 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # tidyrules 0.2.7 2 | 3 | - Major rewrite of tidyrules 4 | - rulelist class introduced with many methods, mainly `predict` 5 | - breaking change: `tidyRules` function no longer exists! 6 | - Support added to `party` models 7 | 8 | # tidyrules 0.1.5 9 | 10 | - Maintenance release (replace package rsample with modeldata) 11 | 12 | # tidyrules 0.1.4 13 | 14 | - Added rules parsable in python and SQL (default: R) 15 | 16 | # tidyrules 0.1.3 17 | 18 | - Rules for rpart regression model ([issue](https://github.com/talegari/tidyrules/issues/8)) 19 | 20 | # tidyrules 0.1.2 21 | 22 | - Default option to compute confidence for C5 models is now implemented with laplace correction ([issue](https://github.com/talegari/tidyrules/issues/10)) 23 | -------------------------------------------------------------------------------- /man/convert_rule_flavor.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{convert_rule_flavor} 4 | \alias{convert_rule_flavor} 5 | \title{Convert a R parsable rule to python/sql parsable rule} 6 | \usage{ 7 | convert_rule_flavor(rule, flavor) 8 | } 9 | \arguments{ 10 | \item{rule}{(chr vector) R parsable rule(s)} 11 | 12 | \item{flavor}{(string) One among: 'python', 'sql'} 13 | } 14 | \value{ 15 | (chr vector) of rules 16 | } 17 | \description{ 18 | Convert a R parsable rule to python/sql parsable rule 19 | } 20 | \seealso{ 21 | \link{rulelist}, \link{tidy}, \link[=augment.rulelist]{augment}, \link[=predict.rulelist]{predict}, \link{to_sql_case} 22 | 23 | Other Auxiliary Rulelist Utility: 24 | \code{\link{to_sql_case}()} 25 | } 26 | \concept{Auxiliary Rulelist Utility} 27 | -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /man/print.rulelist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{print.rulelist} 4 | \alias{print.rulelist} 5 | \title{Print method for \link{rulelist} class} 6 | \usage{ 7 | \method{print}{rulelist}(x, banner = TRUE, ...) 8 | } 9 | \arguments{ 10 | \item{x}{A \link{rulelist} object} 11 | 12 | \item{banner}{(flag, default: \code{TRUE}) Should the banner be displayed} 13 | 14 | \item{...}{Passed to \code{tidytable::print}} 15 | } 16 | \value{ 17 | input \link{rulelist} (invisibly) 18 | } 19 | \description{ 20 | Prints \link{rulelist} attributes and first few rows. 21 | } 22 | \seealso{ 23 | \link{rulelist}, \link{tidy}, \link[=augment.rulelist]{augment}, 24 | \link[=predict.rulelist]{predict}, \link[=calculate.rulelist]{calculate}, 25 | \link[=prune.rulelist]{prune}, \link[=reorder.rulelist]{reorder} 26 | } 27 | -------------------------------------------------------------------------------- /man/print.ruleset.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ruleset.R 3 | \name{print.ruleset} 4 | \alias{print.ruleset} 5 | \title{Print method for ruleset class} 6 | \usage{ 7 | \method{print}{ruleset}(x, banner = TRUE, ...) 8 | } 9 | \arguments{ 10 | \item{x}{A \link{rulelist}} 11 | 12 | \item{banner}{(flag, default: \code{TRUE}) Should the banner be displayed} 13 | 14 | \item{...}{Passed to \code{print.rulelist}} 15 | } 16 | \value{ 17 | (invisibly) Returns the ruleset object 18 | } 19 | \description{ 20 | Prints the ruleset object 21 | } 22 | \examples{ 23 | model_class_party = partykit::ctree(species ~ ., 24 | data = palmerpenguins::penguins 25 | ) 26 | as_ruleset(tidy(model_class_party)) 27 | 28 | } 29 | \seealso{ 30 | \link{print.rulelist} 31 | } 32 | -------------------------------------------------------------------------------- /man/varSpec.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{varSpec} 4 | \alias{varSpec} 5 | \title{Get variable specification for a Cubist/C5 object} 6 | \usage{ 7 | varSpec(object) 8 | } 9 | \arguments{ 10 | \item{object}{Cubist/C5 object} 11 | } 12 | \value{ 13 | A tidytable with three columns: variable(character), type(character) 14 | and levels(a list-column). For numeric variables, levels are set to NA. 15 | } 16 | \description{ 17 | Obtain variable names, type (numeric, ordered, factor) and 18 | levels as a tidytable 19 | } 20 | \examples{ 21 | \dontrun{ 22 | data("attrition", package = "modeldata") 23 | cols_att = setdiff(colnames(attrition), c("MonthlyIncome", "Attrition")) 24 | 25 | cb_att = Cubist::cubist(x = attrition[, cols_att], 26 | y = attrition[["MonthlyIncome"]] 27 | ) 28 | varSpec(cb_att) 29 | } 30 | } 31 | \keyword{internal} 32 | -------------------------------------------------------------------------------- /man/tidy.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tidy.R 3 | \name{tidy} 4 | \alias{tidy} 5 | \title{\code{tidy} is re-export of \link[generics:tidy]{generics::tidy} from 6 | \link[=package_tidyrules]{tidyrules} package} 7 | \usage{ 8 | tidy(x, ...) 9 | } 10 | \arguments{ 11 | \item{x}{A supported model object} 12 | 13 | \item{...}{For model specific implementations to use} 14 | } 15 | \description{ 16 | \code{tidy} applied on a supported model fit creates a \link{rulelist}. 17 | \strong{See Also} section links to documentation of specific methods. 18 | } 19 | \seealso{ 20 | \link{rulelist}, \link{tidy}, \link[=augment.rulelist]{augment}, 21 | \link[=predict.rulelist]{predict}, \link[=calculate.rulelist]{calculate}, 22 | \link[=prune.rulelist]{prune}, \link[=reorder.rulelist]{reorder} 23 | 24 | Other Core Tidy Utility: 25 | \code{\link{tidy.C5.0}()}, 26 | \code{\link{tidy.cubist}()}, 27 | \code{\link{tidy.rpart}()} 28 | } 29 | \concept{Core Tidy Utility} 30 | -------------------------------------------------------------------------------- /man/predict.ruleset.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ruleset.R 3 | \name{predict.ruleset} 4 | \alias{predict.ruleset} 5 | \title{\code{predict} method for a \link{ruleset}} 6 | \usage{ 7 | \method{predict}{ruleset}(object, new_data, ...) 8 | } 9 | \arguments{ 10 | \item{object}{A \link{ruleset}} 11 | 12 | \item{new_data}{(dataframe)} 13 | 14 | \item{...}{unused} 15 | } 16 | \value{ 17 | A dataframe with three or more columns: \code{row_number} (int), columns 18 | corresponding to 'keys', \code{rule_nbr} (list column of integers). If a row 19 | number and 'keys' combination is not covered by any rule, then \code{rule_nbr} 20 | column has missing value. 21 | } 22 | \description{ 23 | Predicts multiple \code{rule_nbr}(s) applicable for a \code{row_nbr} (per 24 | key) in new_data 25 | } 26 | \examples{ 27 | model_c5 = C50::C5.0(species ~., 28 | data = palmerpenguins::penguins, 29 | trials = 5, 30 | rules = TRUE 31 | ) 32 | tidy_c5_ruleset = as_ruleset(tidy(model_c5)) 33 | tidy_c5_ruleset 34 | 35 | predict(tidy_c5_ruleset, palmerpenguins::penguins) 36 | 37 | } 38 | \seealso{ 39 | \link{predict.rulelist} 40 | } 41 | -------------------------------------------------------------------------------- /man/package_tidyrules.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/package.R 3 | \docType{package} 4 | \name{package_tidyrules} 5 | \alias{tidyrules} 6 | \alias{tidyrules-package} 7 | \alias{package_tidyrules} 8 | \title{\code{tidyrules}} 9 | \description{ 10 | \code{tidyrules} package provides a framework to work with decision 11 | rules. Rules can be extracted from supported models using \link{tidy}, augmented 12 | using validation data by \link[=augment.rulelist]{augment}, manipulated using 13 | standard dataframe operations, (modified) rulelists can be used to 14 | \link[=predict.rulelist]{predict} on unseen (test) data. Utilities include: 15 | Create a rulelist manually (\link[=as_rulelist.data.frame]{as_rulelist}), Export 16 | a rulelist to SQL (\link{to_sql_case}) and so on. The package offers two 17 | classes; \link{rulelist} and \link{ruleset} based on dataframe. 18 | } 19 | \seealso{ 20 | \link{rulelist}, \link{tidy}, \link[=augment.rulelist]{augment}, 21 | \link[=predict.rulelist]{predict} 22 | } 23 | \author{ 24 | \strong{Maintainer}: Srikanth Komala Sheshachala \email{sri.teach@gmail.com} 25 | 26 | Authors: 27 | \itemize{ 28 | \item Amith Kumar Ullur Raghavendra \email{amith54@gmail.com} 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /man/plot.rulelist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{plot.rulelist} 4 | \alias{plot.rulelist} 5 | \title{Plot method for rulelist} 6 | \usage{ 7 | \method{plot}{rulelist}(x, thres_cluster_rows = 1000, dist_metric = "jaccard", ...) 8 | } 9 | \arguments{ 10 | \item{x}{A \link{rulelist}} 11 | 12 | \item{thres_cluster_rows}{(positive integer) Maximum number of rows beyond 13 | which a x-side dendrogram is not computed} 14 | 15 | \item{dist_metric}{(string or function, default: "jaccard") Distance metric 16 | for y-side (\code{rule_nbr}) passed to \code{method} argument of \link[proxy:dist]{proxy::dist}} 17 | 18 | \item{...}{Arguments to be passed to \link[pheatmap:pheatmap]{pheatmap::pheatmap}} 19 | } 20 | \description{ 21 | Plots a heatmap with \code{rule_nbr}'s on x-side and clusters of 22 | \code{row_nbr}'s on y-side of a binary matrix with 1 if a rule is applicable for 23 | a row. 24 | } 25 | \details{ 26 | Number of clusters is set to min(number of unique rows in the 27 | row_nbr X rule_nbr matrix and thres_cluster_rows) 28 | } 29 | \examples{ 30 | library("magrittr") 31 | att = modeldata::attrition 32 | tidy_c5 = 33 | C50::C5.0(Attrition ~., data = att, rules = TRUE) \%>\% 34 | tidy() \%>\% 35 | set_validation_data(att, "Attrition") \%>\% 36 | set_keys(NULL) 37 | 38 | plot(tidy_c5) 39 | 40 | } 41 | -------------------------------------------------------------------------------- /man/to_sql_case.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{to_sql_case} 4 | \alias{to_sql_case} 5 | \title{Extract SQL case statement from a \link{rulelist}} 6 | \usage{ 7 | to_sql_case(rulelist, rhs_column_name = "RHS", output_colname = "output") 8 | } 9 | \arguments{ 10 | \item{rulelist}{A \link{rulelist} object} 11 | 12 | \item{rhs_column_name}{(string, default: "RHS") Name of the column in the 13 | rulelist to be used as RHS (WHEN some_rule THEN rhs) in the sql case 14 | statement} 15 | 16 | \item{output_colname}{(string, default: "output") Name of the output column 17 | created by the SQL statement (used in case ... AS output_column)} 18 | } 19 | \value{ 20 | (string invisibly) SQL case statement 21 | } 22 | \description{ 23 | Extract SQL case statement from a \link{rulelist} 24 | } 25 | \details{ 26 | As a side-effect, the SQL statement is cat to stdout. The output 27 | contains newline character. 28 | } 29 | \examples{ 30 | model_c5 = C50::C5.0(Attrition ~., data = modeldata::attrition, rules = TRUE) 31 | tidy(model_c5) 32 | to_sql_case(tidy(model_c5)) 33 | } 34 | \seealso{ 35 | \link{rulelist}, \link{tidy}, \link[=augment.rulelist]{augment}, \link[=predict.rulelist]{predict}, \link{convert_rule_flavor} 36 | 37 | Other Auxiliary Rulelist Utility: 38 | \code{\link{convert_rule_flavor}()} 39 | } 40 | \concept{Auxiliary Rulelist Utility} 41 | -------------------------------------------------------------------------------- /man/tidy.cubist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tidy.R 3 | \name{tidy.cubist} 4 | \alias{tidy.cubist} 5 | \title{Get the \link{rulelist} from a \link[Cubist:cubist.default]{cubist} model} 6 | \usage{ 7 | \method{tidy}{cubist}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{\link[Cubist:cubist.default]{Cubist::cubist} model} 11 | 12 | \item{...}{Other arguments (currently unused)} 13 | } 14 | \value{ 15 | A \link{rulelist} object 16 | } 17 | \description{ 18 | Each row corresponds to a rule per \code{committee} 19 | } 20 | \details{ 21 | \itemize{ 22 | \item The output columns are: \code{rule_nbr}, \code{committee}, \code{LHS}, \code{RHS}, \code{support}, \code{mean}, \code{min}, \code{max}, \code{error}. 23 | \item Rules are sorted in this order per committee: 24 | \code{error}, \code{desc(support)} 25 | } 26 | } 27 | \examples{ 28 | att = modeldata::attrition 29 | cols_att = setdiff(colnames(att), c("MonthlyIncome", "Attrition")) 30 | model_cubist = Cubist::cubist(x = att[, cols_att], 31 | y = att[["MonthlyIncome"]] 32 | ) 33 | tidy(model_cubist) 34 | 35 | } 36 | \seealso{ 37 | \link{rulelist}, \link{tidy}, \link[=augment.rulelist]{augment}, 38 | \link[=predict.rulelist]{predict}, \link[=calculate.rulelist]{calculate}, 39 | \link[=prune.rulelist]{prune}, \link[=reorder.rulelist]{reorder} 40 | 41 | Other Core Tidy Utility: 42 | \code{\link{tidy}()}, 43 | \code{\link{tidy.C5.0}()}, 44 | \code{\link{tidy.rpart}()} 45 | } 46 | \concept{Core Tidy Utility} 47 | -------------------------------------------------------------------------------- /man/as_rulelist.data.frame.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{as_rulelist.data.frame} 4 | \alias{as_rulelist.data.frame} 5 | \title{as_rulelist method for a data.frame} 6 | \usage{ 7 | \method{as_rulelist}{data.frame}(x, keys = NULL, model_type = NULL, estimation_type, ...) 8 | } 9 | \arguments{ 10 | \item{x}{dataframe to be coerced to a \link{rulelist}} 11 | 12 | \item{keys}{(character vector, default: NULL) column names which form the key} 13 | 14 | \item{model_type}{(string, default: NULL) Name of the model which generated 15 | the rules} 16 | 17 | \item{estimation_type}{(string) One among: 'regression', 18 | 'classification'} 19 | 20 | \item{...}{currently unused} 21 | } 22 | \value{ 23 | \link{rulelist} object 24 | } 25 | \description{ 26 | Convert a set of rules in a dataframe to a \link{rulelist} 27 | } 28 | \details{ 29 | Input dataframe should contain these columns: \code{rule_nbr}, \code{LHS}, 30 | \code{RHS}. Providing other inputs helps augment better. 31 | } 32 | \examples{ 33 | rules_df = tidytable::tidytable(rule_nbr = 1:2, 34 | LHS = c("var_1 > 50", "var_2 < 30"), 35 | RHS = c(2, 1) 36 | ) 37 | as_rulelist(rules_df, estimation_type = "regression") 38 | } 39 | \seealso{ 40 | \link{rulelist}, \link{tidy}, \link[=augment.rulelist]{augment}, 41 | \link[=predict.rulelist]{predict}, \link[=calculate.rulelist]{calculate}, 42 | \link[=prune.rulelist]{prune}, \link[=reorder.rulelist]{reorder} 43 | } 44 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | pull_request: 5 | branches: [main, master] 6 | 7 | name: R-CMD-check 8 | 9 | permissions: read-all 10 | 11 | jobs: 12 | R-CMD-check: 13 | runs-on: ${{ matrix.config.os }} 14 | 15 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 16 | 17 | strategy: 18 | fail-fast: false 19 | matrix: 20 | config: 21 | - {os: macos-latest, r: 'release'} 22 | - {os: windows-latest, r: 'release'} 23 | - {os: ubuntu-latest, r: 'release'} 24 | 25 | env: 26 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 27 | R_KEEP_PKG_SOURCE: yes 28 | 29 | steps: 30 | - uses: actions/checkout@v4 31 | - uses: r-lib/actions/setup-pandoc@v2 32 | 33 | - uses: r-lib/actions/setup-r@v2 34 | with: 35 | r-version: ${{ matrix.config.r }} 36 | http-user-agent: ${{ matrix.config.http-user-agent }} 37 | use-public-rspm: true 38 | 39 | - uses: r-lib/actions/setup-r-dependencies@v2 40 | with: 41 | extra-packages: any::rcmdcheck 42 | needs: check 43 | 44 | - uses: r-lib/actions/check-r-package@v2 45 | with: 46 | args: 'c("--no-manual", "--as-cran", "--no-vignettes", "--no-build-vignettes")' 47 | upload-snapshots: true 48 | build_args: 'c("--no-manual","--no-build-vignettes")' 49 | error-on: '"error"' 50 | -------------------------------------------------------------------------------- /man/tidy.C5.0.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tidy.R 3 | \name{tidy.C5.0} 4 | \alias{tidy.C5.0} 5 | \title{Get the \link{rulelist} from a \link[C50:C5.0]{C5} model} 6 | \usage{ 7 | \method{tidy}{C5.0}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{\link[C50:C5.0]{C50::C5.0} model fitted with \code{rules = TRUE}} 11 | 12 | \item{...}{Other arguments (See details)} 13 | } 14 | \value{ 15 | A \link{rulelist} object 16 | } 17 | \description{ 18 | Each row corresponds to a rule per \code{trial_nbr} 19 | } 20 | \details{ 21 | \itemize{ 22 | \item The output columns are: \code{rule_nbr}, \code{trial_nbr}, \code{LHS}, \code{RHS}, 23 | \code{support}, \code{confidence}, \code{lift}. 24 | \item Rules per \code{trial_nbr} are sorted in this order: \code{desc(confidence)}, 25 | \code{desc(lift)}, \code{desc(support)}. 26 | } 27 | 28 | Optional named arguments: 29 | \itemize{ 30 | \item \code{laplace} (flag, default: TRUE) is supported. This 31 | computes confidence with laplace correction as documented under 'Rulesets' 32 | here: \href{https://www.rulequest.com/see5-unix.html}{C5 doc}. 33 | } 34 | } 35 | \examples{ 36 | model_c5 = C50::C5.0(Attrition ~., data = modeldata::attrition, rules = TRUE) 37 | tidy(model_c5) 38 | 39 | } 40 | \seealso{ 41 | \link{rulelist}, \link{tidy}, \link[=augment.rulelist]{augment}, 42 | \link[=predict.rulelist]{predict}, \link[=calculate.rulelist]{calculate}, 43 | \link[=prune.rulelist]{prune}, \link[=reorder.rulelist]{reorder} 44 | 45 | Other Core Tidy Utility: 46 | \code{\link{tidy}()}, 47 | \code{\link{tidy.cubist}()}, 48 | \code{\link{tidy.rpart}()} 49 | } 50 | \concept{Core Tidy Utility} 51 | -------------------------------------------------------------------------------- /tests/testthat/test-party.R: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # This is the part of the 'tidyrules' R package hosted at 3 | # https://github.com/talegari/tidyrules with GPL-3 license. 4 | ################################################################################ 5 | 6 | context("test-party") 7 | 8 | # setup some models ---- 9 | data("penguins", package = "palmerpenguins") 10 | 11 | model_party_cl = partykit::ctree(species ~ .,data = penguins) 12 | model_party_cl 13 | tidy(model_party_cl) 14 | 15 | model_party_re = partykit::ctree(bill_length_mm ~ ., 16 | data = penguins 17 | ) 18 | model_party_re 19 | tidy(model_party_re) 20 | 21 | # function to check whether a rule is filterable 22 | ruleFilterable = function(rule, data){ 23 | dplyr::filter(data, eval(parse(text = rule))) 24 | } 25 | 26 | # function to check whether all rules are filterable 27 | allRulesFilterable = function(tr, data){ 28 | parse_status = sapply( 29 | tr[["LHS"]], 30 | function(arule){ 31 | trydf = try(ruleFilterable(arule, data), silent = TRUE) 32 | if (nrow(trydf) == 0) print(arule) 33 | inherits(trydf, "data.frame") 34 | } 35 | ) 36 | return(parse_status) 37 | } 38 | 39 | # test output type ---- 40 | 41 | test_that("creates rulelist", { 42 | expect_is(tidy(model_party_cl), "rulelist") 43 | expect_is(tidy(model_party_re), "rulelist") 44 | }) 45 | 46 | # test parsable ---- 47 | test_that("rules are parsable", { 48 | expect_true(all(allRulesFilterable(tidy(model_party_cl), penguins))) 49 | expect_true(all(allRulesFilterable(tidy(model_party_re), penguins))) 50 | }) 51 | 52 | -------------------------------------------------------------------------------- /man/set_keys.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{set_keys} 4 | \alias{set_keys} 5 | \title{Set keys for a \link{rulelist}} 6 | \usage{ 7 | set_keys(x, keys, reset = FALSE) 8 | } 9 | \arguments{ 10 | \item{x}{A \link{rulelist}} 11 | 12 | \item{keys}{(character vector or NULL)} 13 | 14 | \item{reset}{(flag) Whether to reset the keys to sequential numbers starting 15 | with 1 when \code{keys} is set to NULL} 16 | } 17 | \value{ 18 | A \link{rulelist} object 19 | } 20 | \description{ 21 | 'keys' are a set of column(s) which identify a group of rules in 22 | a \link{rulelist}. Methods like \link[=predict.rulelist]{predict}, 23 | \link[=augment.rulelist]{augment} produce output per key combination. 24 | } 25 | \details{ 26 | A new \link{rulelist} is returned with attr \code{keys} is modified. The input 27 | \link{rulelist} object is unaltered. 28 | } 29 | \examples{ 30 | model_c5 = C50::C5.0(Attrition ~., data = modeldata::attrition, rules = TRUE) 31 | tidy_c5 = tidy(model_c5) 32 | tidy_c5 # keys are: "trial_nbr" 33 | 34 | tidy_c5[["rule_nbr"]] = 1:nrow(tidy_c5) 35 | new_tidy_c5 = set_keys(tidy_c5, NULL) # remove all keys 36 | new_tidy_c5 37 | 38 | new_2_tidy_c5 = set_keys(new_tidy_c5, "trial_nbr") # set "trial_nbr" as key 39 | new_2_tidy_c5 40 | 41 | # Note that `tidy_c5` and `new_tidy_c5` are not altered. 42 | tidy_c5 43 | new_tidy_c5 44 | 45 | } 46 | \seealso{ 47 | \link{rulelist}, \link{tidy}, \link[=augment.rulelist]{augment}, 48 | \link[=predict.rulelist]{predict}, \link[=calculate.rulelist]{calculate}, 49 | \link[=prune.rulelist]{prune}, \link[=reorder.rulelist]{reorder} 50 | 51 | Other Core Rulelist Utility: 52 | \code{\link{set_validation_data}()} 53 | } 54 | \concept{Core Rulelist Utility} 55 | -------------------------------------------------------------------------------- /man/tidy.constparty.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tidy.R 3 | \name{tidy.constparty} 4 | \alias{tidy.constparty} 5 | \title{Get the \link{rulelist} from a \link[partykit:party]{party} model} 6 | \usage{ 7 | \method{tidy}{constparty}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{\link[partykit:party]{partykit::party} model typically built using \link[partykit:ctree]{partykit::ctree}} 11 | 12 | \item{...}{Other arguments (currently unused)} 13 | } 14 | \value{ 15 | A \link{rulelist} object 16 | } 17 | \description{ 18 | Each row corresponds to a rule 19 | } 20 | \details{ 21 | These types of \link[partykit:party]{party} models are supported: 22 | \code{regression} (y is numeric), \code{classification} (y is factor) 23 | 24 | For \link[partykit:party]{party} classification model: 25 | \itemize{ 26 | \item Output columns are: \code{rule_nbr}, \code{LHS}, \code{RHS}, \code{support}, \code{confidence}, \code{lift}, \code{terminal_node_id}. 27 | \item Rules are sorted in this order: \code{desc(confidence)}, \code{desc(lift)}, 28 | \code{desc(support)}. 29 | } 30 | 31 | For \link[partykit:party]{party} regression model: 32 | \itemize{ 33 | \item Output columns are: \code{rule_nbr}, \code{LHS}, \code{RHS}, \code{support}, \code{IQR}, \code{RMSE}, \code{terminal_node_id}. 34 | \item Rules are sorted in this order: \code{RMSE}, \code{desc(support)}. 35 | } 36 | } 37 | \examples{ 38 | pen = palmerpenguins::penguins 39 | model_class_party = partykit::ctree(species ~ ., data = pen) 40 | tidy(model_class_party) 41 | model_regr_party = partykit::ctree(bill_length_mm ~ ., data = pen) 42 | tidy(model_regr_party) 43 | 44 | } 45 | \seealso{ 46 | \link{rulelist}, \link{tidy}, \link[=augment.rulelist]{augment}, 47 | \link[=predict.rulelist]{predict}, \link[=calculate.rulelist]{calculate}, 48 | \link[=prune.rulelist]{prune}, \link[=reorder.rulelist]{reorder} 49 | } 50 | -------------------------------------------------------------------------------- /man/reorder.rulelist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{reorder.rulelist} 4 | \alias{reorder.rulelist} 5 | \title{Reorder the rules/rows of a \link{rulelist}} 6 | \usage{ 7 | \method{reorder}{rulelist}(x, metric = "cumulative_coverage", minimize = FALSE, init = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{x}{A \link{rulelist}} 11 | 12 | \item{metric}{(character vector or named list) Name of metrics or a custom 13 | function(s). See \link[=calculate.rulelist]{calculate}. The 'n+1'th metric is 14 | used when there is a match at 'nth' level, similar to \link[base:order]{base::order}. If 15 | there is a match at final level, row order of the rulelist comes into play.} 16 | 17 | \item{minimize}{(logical vector) Whether to minimize. Either TRUE/FALSE or a 18 | logical vector of same length as metric} 19 | 20 | \item{init}{(positive integer) Initial number of rows after which reordering 21 | should begin} 22 | 23 | \item{...}{passed to \link[=calculate.rulelist]{calculate}} 24 | } 25 | \description{ 26 | Implements a greedy strategy to add one rule at a time which 27 | maximizes/minimizes a metric. 28 | } 29 | \examples{ 30 | library("magrittr") 31 | att = modeldata::attrition 32 | tidy_c5 = 33 | C50::C5.0(Attrition ~., data = att, rules = TRUE) \%>\% 34 | tidy() \%>\% 35 | set_validation_data(att, "Attrition") \%>\% 36 | set_keys(NULL) \%>\% 37 | head(5) 38 | 39 | # with defaults 40 | reorder(tidy_c5) 41 | 42 | # use 'cumulative_overlap' to break ties (if any) 43 | reorder(tidy_c5, metric = c("cumulative_coverage", "cumulative_overlap")) 44 | 45 | # reorder after 2 rules 46 | reorder(tidy_c5, init = 2) 47 | 48 | } 49 | \seealso{ 50 | \link{rulelist}, \link{tidy}, \link[=augment.rulelist]{augment}, 51 | \link[=predict.rulelist]{predict}, \link[=calculate.rulelist]{calculate}, 52 | \link[=prune.rulelist]{prune}, \link[=reorder.rulelist]{reorder} 53 | } 54 | -------------------------------------------------------------------------------- /man/tidy.rpart.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tidy.R 3 | \name{tidy.rpart} 4 | \alias{tidy.rpart} 5 | \title{Get the \link{rulelist} from a \link[rpart:rpart]{rpart} model} 6 | \usage{ 7 | \method{tidy}{rpart}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{\link[rpart:rpart]{rpart::rpart} model} 11 | 12 | \item{...}{Other arguments (currently unused)} 13 | } 14 | \value{ 15 | A \link{rulelist} object 16 | } 17 | \description{ 18 | Each row corresponds to a rule 19 | } 20 | \details{ 21 | For rpart rules, one should build the model without \link[base:factor]{ordered factor} variable. We recommend you to convert \link[base:factor]{ordered factor} to \link[base:factor]{factor} or \emph{integer} class. 22 | 23 | For \link[rpart:rpart]{rpart::rpart} classification model: 24 | \itemize{ 25 | \item Output columns are: \code{rule_nbr}, \code{LHS}, \code{RHS}, \code{support}, \code{confidence}, \code{lift}. 26 | \item The rules are sorted in this order: \code{desc(confidence)}, \code{desc(lift)}, 27 | \code{desc(support)}. 28 | } 29 | 30 | For \link[rpart:rpart]{rpart::rpart} regression(anova) model: 31 | \itemize{ 32 | \item Output columns are: \code{rule_nbr}, \code{LHS}, \code{RHS}, \code{support}. 33 | \item The rules are sorted in this order: \code{desc(support)}. 34 | } 35 | } 36 | \examples{ 37 | model_class_rpart = rpart::rpart(Species ~ ., data = iris) 38 | tidy(model_class_rpart) 39 | 40 | model_regr_rpart = rpart::rpart(Sepal.Length ~ ., data = iris) 41 | tidy(model_regr_rpart) 42 | 43 | } 44 | \seealso{ 45 | \link{rulelist}, \link{tidy}, \link[=augment.rulelist]{augment}, 46 | \link[=predict.rulelist]{predict}, \link[=calculate.rulelist]{calculate}, 47 | \link[=prune.rulelist]{prune}, \link[=reorder.rulelist]{reorder} 48 | 49 | Other Core Tidy Utility: 50 | \code{\link{tidy}()}, 51 | \code{\link{tidy.C5.0}()}, 52 | \code{\link{tidy.cubist}()} 53 | } 54 | \concept{Core Tidy Utility} 55 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | 6 | 7 | ```{r, include = FALSE} 8 | knitr::opts_chunk$set( 9 | collapse = TRUE, 10 | comment = "#>", 11 | fig.path = "man/figures/README-", 12 | out.width = "100%" 13 | ) 14 | devtools::load_all() #todo 15 | ``` 16 | # tidyrules 17 | 18 | 19 | [![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/tidyrules)](https://cran.r-project.org/package=tidyrules) 20 | 21 | 22 | > [tidyrules](https://cran.r-project.org/package=tidyrules) [R](https://www.r-project.org/) [package](https://cran.r-project.org/) 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. 23 | 24 | **website**: https://talegari.github.io/tidyrules/ 25 | 26 | ![](man/figures/tidyrules_schematic.png) 27 | 28 | ## Example 29 |
30 | expand/collapse 31 | 32 | ```{r example} 33 | library(tidyrules) 34 | ``` 35 | 36 | ```{r basic C5 example} 37 | model_c5 = C50::C5.0(Species ~ ., data = iris, rules = TRUE) 38 | tidy(model_c5) 39 | ``` 40 |
41 | 42 | ## Installation 43 |
44 | expand/collapse 45 | 46 | You can install the released version of tidyrules from [CRAN](https://CRAN.R-project.org) with: 47 | 48 | ```{r, eval = FALSE} 49 | install.packages("tidyrules") 50 | ``` 51 | 52 | And the development version from [GitHub](https://github.com/) with: 53 | 54 | ```{r, eval = FALSE} 55 | # install.packages("devtools") 56 | devtools::install_github("talegari/tidyrules") 57 | ``` 58 |
59 | 60 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: tidyrules 2 | Type: Package 3 | Title: Utilities to Retrieve Rulelists from Model Fits, Filter, Prune, Reorder and Predict on Unseen Data 4 | Version: 0.2.7 5 | Authors@R: c( 6 | person("Srikanth", "Komala Sheshachala", email = "sri.teach@gmail.com", role = c("aut", "cre")), 7 | person("Amith Kumar", "Ullur Raghavendra", email = "amith54@gmail.com", role = c("aut")) 8 | ) 9 | Maintainer: Srikanth Komala Sheshachala 10 | Depends: R (>= 3.6.0), 11 | Imports: 12 | stringr (>= 1.3.1), 13 | magrittr (>= 1.5), 14 | purrr (>= 0.3.2), 15 | partykit (>= 1.2.2), 16 | rlang (>= 1.1.3), 17 | generics (>= 0.1.3), 18 | checkmate (>= 2.3.1), 19 | tidytable (>= 0.11.0), 20 | data.table (>= 1.14.6), 21 | DescTools (>= 0.99.54), 22 | MetricsWeighted (>= 1.0.3), 23 | cli (>= 3.6.2), 24 | glue (>= 1.7.0), 25 | pheatmap (>= 1.0.12), 26 | proxy (>= 0.4.27), 27 | tibble (>= 3.2.1), 28 | Suggests: 29 | AmesHousing (>= 0.0.3), 30 | dplyr (>= 0.8), 31 | C50 (>= 0.1.2), 32 | Cubist (>= 0.2.2), 33 | rpart (>= 1.2.2), 34 | rpart.plot (>= 3.0.7), 35 | modeldata (>= 0.0.1), 36 | testthat (>= 2.0.1), 37 | MASS (>= 7.3.50), 38 | mlbench (>= 2.1.1), 39 | rmarkdown (>= 1.13), 40 | palmerpenguins (>= 0.1.1), 41 | Description: 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. 42 | URL: https://github.com/talegari/tidyrules, https://talegari.github.io/tidyrules/ 43 | BugReports: https://github.com/talegari/tidyrules/issues 44 | License: GPL-3 45 | Encoding: UTF-8 46 | LazyData: true 47 | RoxygenNote: 7.3.1 48 | Roxygen: list(markdown = TRUE) 49 | 50 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | 6 | /* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ 7 | 8 | /* All levels of nav */ 9 | nav[data-toggle='toc'] .nav > li > a { 10 | display: block; 11 | padding: 4px 20px; 12 | font-size: 13px; 13 | font-weight: 500; 14 | color: #767676; 15 | } 16 | nav[data-toggle='toc'] .nav > li > a:hover, 17 | nav[data-toggle='toc'] .nav > li > a:focus { 18 | padding-left: 19px; 19 | color: #563d7c; 20 | text-decoration: none; 21 | background-color: transparent; 22 | border-left: 1px solid #563d7c; 23 | } 24 | nav[data-toggle='toc'] .nav > .active > a, 25 | nav[data-toggle='toc'] .nav > .active:hover > a, 26 | nav[data-toggle='toc'] .nav > .active:focus > a { 27 | padding-left: 18px; 28 | font-weight: bold; 29 | color: #563d7c; 30 | background-color: transparent; 31 | border-left: 2px solid #563d7c; 32 | } 33 | 34 | /* Nav: second level (shown on .active) */ 35 | nav[data-toggle='toc'] .nav .nav { 36 | display: none; /* Hide by default, but at >768px, show it */ 37 | padding-bottom: 10px; 38 | } 39 | nav[data-toggle='toc'] .nav .nav > li > a { 40 | padding-top: 1px; 41 | padding-bottom: 1px; 42 | padding-left: 30px; 43 | font-size: 12px; 44 | font-weight: normal; 45 | } 46 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 47 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 48 | padding-left: 29px; 49 | } 50 | nav[data-toggle='toc'] .nav .nav > .active > a, 51 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 52 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 53 | padding-left: 28px; 54 | font-weight: 500; 55 | } 56 | 57 | /* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ 58 | nav[data-toggle='toc'] .nav > .active > ul { 59 | display: block; 60 | } 61 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(as_rulelist,data.frame) 4 | S3method(augment,rulelist) 5 | S3method(calculate,rulelist) 6 | S3method(plot,prune_rulelist) 7 | S3method(plot,rulelist) 8 | S3method(predict,rulelist) 9 | S3method(predict,ruleset) 10 | S3method(print,prune_rulelist) 11 | S3method(print,rulelist) 12 | S3method(print,ruleset) 13 | S3method(prune,rulelist) 14 | S3method(reorder,rulelist) 15 | S3method(tidy,C5.0) 16 | S3method(tidy,constparty) 17 | S3method(tidy,cubist) 18 | S3method(tidy,rpart) 19 | export(as_rulelist) 20 | export(as_ruleset) 21 | export(augment) 22 | export(calculate) 23 | export(convert_rule_flavor) 24 | export(prune) 25 | export(reorder) 26 | export(set_keys) 27 | export(set_validation_data) 28 | export(tidy) 29 | export(to_sql_case) 30 | importFrom(data.table,":=") 31 | importFrom(generics,augment) 32 | importFrom(generics,calculate) 33 | importFrom(generics,prune) 34 | importFrom(generics,tidy) 35 | importFrom(graphics,abline) 36 | importFrom(graphics,axis) 37 | importFrom(graphics,legend) 38 | importFrom(graphics,lines) 39 | importFrom(magrittr,"%>%") 40 | importFrom(rlang,"%||%") 41 | importFrom(stats,IQR) 42 | importFrom(stats,predict) 43 | importFrom(stats,reorder) 44 | importFrom(stats,runif) 45 | importFrom(stats,weighted.mean) 46 | importFrom(tidytable,across) 47 | importFrom(tidytable,all_of) 48 | importFrom(tidytable,arrange) 49 | importFrom(tidytable,bind_cols) 50 | importFrom(tidytable,bind_rows) 51 | importFrom(tidytable,distinct) 52 | importFrom(tidytable,drop_na) 53 | importFrom(tidytable,inner_join) 54 | importFrom(tidytable,left_join) 55 | importFrom(tidytable,mutate) 56 | importFrom(tidytable,n) 57 | importFrom(tidytable,nest) 58 | importFrom(tidytable,pivot_longer) 59 | importFrom(tidytable,pivot_wider) 60 | importFrom(tidytable,pull) 61 | importFrom(tidytable,relocate) 62 | importFrom(tidytable,right_join) 63 | importFrom(tidytable,row_number) 64 | importFrom(tidytable,select) 65 | importFrom(tidytable,slice) 66 | importFrom(tidytable,summarise) 67 | importFrom(tidytable,unnest) 68 | importFrom(utils,capture.output) 69 | importFrom(utils,data) 70 | importFrom(utils,head) 71 | importFrom(utils,tail) 72 | -------------------------------------------------------------------------------- /man/set_validation_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{set_validation_data} 4 | \alias{set_validation_data} 5 | \title{Add \code{validation_data} to a \link{rulelist}} 6 | \usage{ 7 | set_validation_data(x, validation_data, y_name, weight = 1) 8 | } 9 | \arguments{ 10 | \item{x}{A \link{rulelist}} 11 | 12 | \item{validation_data}{(dataframe) Data to used for computing some metrics. 13 | It is expected to contain \code{y_name} column.} 14 | 15 | \item{y_name}{(string) Name of the dependent variable column.} 16 | 17 | \item{weight}{(non-negative numeric vector, default: 1) Weight per 18 | observation/row of \code{validation_data}. This is expected to have same length 19 | as the number of rows in \code{validation_data}. Only exception is when it is a 20 | single positive number, which means that all rows have equal weight.} 21 | } 22 | \value{ 23 | A \link{rulelist} with some extra attributes set. 24 | } 25 | \description{ 26 | Returns a \link{rulelist} with three new attributes set: 27 | \code{validation_data}, \code{y_name} and \code{weight}. Methods such as 28 | \link[=augment.rulelist]{augment}, \link[=calculate.rulelist]{calculate}, 29 | \link[=prune.rulelist]{prune}, \link{reorder} require this to be set. 30 | } 31 | \examples{ 32 | att = modeldata::attrition 33 | set.seed(100) 34 | index = sample(c(TRUE, FALSE), nrow(att), replace = TRUE) 35 | model_c5 = C50::C5.0(Attrition ~., data = att[index, ], rules = TRUE) 36 | 37 | tidy_c5 = tidy(model_c5) 38 | tidy_c5 39 | 40 | tidy_c5_2 = set_validation_data(tidy_c5, 41 | validation_data = att[!index, ], 42 | y_name = "Attrition", 43 | weight = 1 # default 44 | ) 45 | tidy_c5_2 46 | tidy_c5 # not altered 47 | 48 | } 49 | \seealso{ 50 | \link{rulelist}, \link{tidy}, \link[=augment.rulelist]{augment}, 51 | \link[=predict.rulelist]{predict}, \link[=calculate.rulelist]{calculate}, 52 | \link[=prune.rulelist]{prune}, \link[=reorder.rulelist]{reorder} 53 | 54 | Other Core Rulelist Utility: 55 | \code{\link{set_keys}()} 56 | } 57 | \concept{Core Rulelist Utility} 58 | -------------------------------------------------------------------------------- /man/predict.rulelist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{predict.rulelist} 4 | \alias{predict.rulelist} 5 | \title{\code{predict} method for a \link{rulelist}} 6 | \usage{ 7 | \method{predict}{rulelist}(object, new_data, multiple = FALSE, ...) 8 | } 9 | \arguments{ 10 | \item{object}{A \link{rulelist}} 11 | 12 | \item{new_data}{(dataframe)} 13 | 14 | \item{multiple}{(flag, default: FALSE) Whether to output all rule numbers 15 | applicable for a row. If FALSE, the first satisfying rule is provided.} 16 | 17 | \item{...}{unused} 18 | } 19 | \value{ 20 | A dataframe. See \strong{Details}. 21 | } 22 | \description{ 23 | Predicts \code{rule_nbr} applicable (as per the order in rulelist) 24 | for a \code{row_nbr} (per key) in new_data 25 | } 26 | \details{ 27 | If a \code{row_nbr} is covered more than one \code{rule_nbr} per 'keys', then 28 | \code{rule_nbr} appearing earlier (as in row order of the \link{rulelist}) takes 29 | precedence. 30 | \subsection{Output Format}{ 31 | \itemize{ 32 | \item When multiple is \code{FALSE}(default), output is a dataframe with three 33 | or more columns: \code{row_number} (int), columns corresponding to 'keys', 34 | \code{rule_nbr} (int). 35 | \item When multiple is \code{TRUE}, output is a dataframe with three 36 | or more columns: \code{row_number} (int), columns corresponding to 'keys', 37 | \code{rule_nbr} (list column of integers). 38 | \item If a row number and 'keys' combination is not covered by any rule, then 39 | \code{rule_nbr} column has missing value. 40 | } 41 | } 42 | } 43 | \examples{ 44 | model_c5 = C50::C5.0(species ~., 45 | data = palmerpenguins::penguins, 46 | trials = 5, 47 | rules = TRUE 48 | ) 49 | tidy_c5 = tidy(model_c5) 50 | tidy_c5 51 | 52 | output_1 = predict(tidy_c5, palmerpenguins::penguins) 53 | output_1 # different rules per 'keys' (`trial_nbr` here) 54 | 55 | output_2 = predict(tidy_c5, palmerpenguins::penguins, multiple = TRUE) 56 | output_2 # `rule_nbr` is a list-column of integer vectors 57 | 58 | } 59 | \seealso{ 60 | \link{rulelist}, \link{tidy}, \link[=augment.rulelist]{augment}, 61 | \link[=predict.rulelist]{predict}, \link[=calculate.rulelist]{calculate}, 62 | \link[=prune.rulelist]{prune}, \link[=reorder.rulelist]{reorder} 63 | } 64 | -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # tidyrules 5 | 6 | 7 | 8 | [![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/tidyrules)](https://cran.r-project.org/package=tidyrules) 9 | 10 | 11 | > [tidyrules](https://cran.r-project.org/package=tidyrules) 12 | > [R](https://www.r-project.org/) [package](https://cran.r-project.org/) 13 | > provides a framework to work with decision rules. Rules can be 14 | > extracted from supported models, augmented with (custom) metrics using 15 | > validation data, manipulated using standard dataframe operations, 16 | > reordered and pruned based on a metric, predict on unseen (test) data. 17 | > Utilities include; Creating a rulelist manually, Exporting a rulelist 18 | > as a SQL case statement and so on. The package offers two classes; 19 | > rulelist and ruleset based on dataframe. 20 | 21 | **website**: 22 | 23 | ![](man/figures/tidyrules_schematic.png) 24 | 25 | ## Example 26 | 27 |
28 | 29 | expand/collapse 30 | 31 | 32 | ``` r 33 | library(tidyrules) 34 | ``` 35 | 36 | ``` r 37 | model_c5 = C50::C5.0(Species ~ ., data = iris, rules = TRUE) 38 | tidy(model_c5) 39 | #> ---- Rulelist -------------------------------- 40 | #> ▶ Keys: trial_nbr 41 | #> ▶ Number of distinct keys: 1 42 | #> ▶ Number of rules: 4 43 | #> ▶ Model type: C5 44 | #> ▶ Estimation type: classification 45 | #> ▶ Is validation data set: FALSE 46 | #> 47 | #> 48 | #> rule_nbr trial_nbr LHS RHS support confidence lift 49 | #> 50 | #> 1 1 1 ( Petal.Length <= 1.9 ) seto… 50 0.981 2.9 51 | #> 2 2 1 ( Petal.Length > 1.9 ) & ( … vers… 48 0.96 2.9 52 | #> 3 3 1 ( Petal.Width > 1.7 ) virg… 46 0.958 2.9 53 | #> 4 4 1 ( Petal.Length > 4.9 ) virg… 46 0.938 2.8 54 | #> ---------------------------------------------- 55 | ``` 56 | 57 |
58 | 59 | ## Installation 60 | 61 |
62 | 63 | expand/collapse 64 | 65 | 66 | You can install the released version of tidyrules from 67 | [CRAN](https://CRAN.R-project.org) with: 68 | 69 | ``` r 70 | install.packages("tidyrules") 71 | ``` 72 | 73 | And the development version from [GitHub](https://github.com/) with: 74 | 75 | ``` r 76 | # install.packages("devtools") 77 | devtools::install_github("talegari/tidyrules") 78 | ``` 79 | 80 |
81 | -------------------------------------------------------------------------------- /tests/testthat/test-c5.R: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # This is the part of the 'tidyrules' R package hosted at 3 | # https://github.com/talegari/tidyrules with GPL-3 license. 4 | ################################################################################ 5 | 6 | context("test-c5") 7 | 8 | # setup some models ---- 9 | # attrition 10 | data("attrition", package = "modeldata") 11 | 12 | c5_att = C50::C5.0(Attrition ~ ., data = attrition, rules = TRUE) 13 | tr_att = tidy(c5_att) 14 | 15 | # attrition with trials 16 | c5_att_2 = C50::C5.0(Attrition ~ ., data = attrition 17 | , trials = 7, rules = TRUE) 18 | tr_att_2 = tidy(c5_att_2) 19 | 20 | # ames housing 21 | # ames has some space in Sale_Type levels 22 | ames = AmesHousing::make_ames() 23 | ames 24 | cb_ames = C50::C5.0(MS_SubClass ~ ., data = ames 25 | , trials = 3, rules = TRUE) 26 | tr_ames = tidy(cb_ames) 27 | 28 | # column name has a space in it 29 | ames = AmesHousing::make_ames() 30 | ames_2 = ames 31 | colnames(ames_2)[which(colnames(ames_2) == "Bldg_Type")] = "Bldg Type" 32 | colnames(ames_2)[which(colnames(ames_2) == "House_Style")] = "House Style" 33 | c5_ames_2 = C50::C5.0(MS_SubClass ~ ., data = ames_2, rules = TRUE) 34 | tr_ames_2 = tidy(c5_ames_2) 35 | 36 | # function to check whether a rule is filterable 37 | ruleFilterable = function(rule, data){ 38 | dplyr::filter(data, eval(parse(text = rule))) 39 | } 40 | 41 | # function to check whether all rules are filterable 42 | allRulesFilterable = function(tr, data){ 43 | parse_status = sapply( 44 | tr[["LHS"]] 45 | , function(arule){ 46 | trydf = try(ruleFilterable(arule, data) 47 | , silent = TRUE 48 | ) 49 | if(nrow(trydf) == 0){ 50 | # print(arule) 51 | } 52 | inherits(trydf, "data.frame") 53 | } 54 | ) 55 | return(parse_status) 56 | } 57 | 58 | # test output type ---- 59 | 60 | test_that("creates tibble", { 61 | expect_is(tr_att, "rulelist") 62 | expect_is(tr_att_2, "rulelist") 63 | expect_is(tr_ames, "rulelist") 64 | expect_is(tr_ames_2, "rulelist") 65 | }) 66 | 67 | # test NA ---- 68 | test_that("Are NA present", { 69 | expect_false(anyNA(tr_att)) 70 | expect_false(anyNA(tr_att_2)) 71 | expect_false(anyNA(tr_ames)) 72 | expect_false(anyNA(tr_ames_2)) 73 | }) 74 | 75 | # test parsable ---- 76 | test_that("rules are parsable", { 77 | expect_true(all(allRulesFilterable(tr_att, attrition))) 78 | expect_true(all(allRulesFilterable(tr_att_2, attrition))) 79 | expect_true(all(allRulesFilterable(tr_ames, ames))) 80 | expect_true(all(allRulesFilterable(tr_ames_2, ames_2))) 81 | }) 82 | -------------------------------------------------------------------------------- /man/prune.rulelist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{prune.rulelist} 4 | \alias{prune.rulelist} 5 | \title{\code{prune} rules of a \link{rulelist}} 6 | \usage{ 7 | \method{prune}{rulelist}( 8 | tree, 9 | metrics_to_exclude = NULL, 10 | stop_expr_string = "relative__cumulative_coverage >= 0.9", 11 | min_n_rules = 1, 12 | ... 13 | ) 14 | } 15 | \arguments{ 16 | \item{tree}{A \link{rulelist}} 17 | 18 | \item{metrics_to_exclude}{(character vector or NULL) Names of metrics not to 19 | be calculated. See \link[=calculate.rulelist]{calculate} for the list of default 20 | metrics.} 21 | 22 | \item{stop_expr_string}{(string default: "relative__cumulative_coverage >= 23 | 0.9") Parsable condition} 24 | 25 | \item{min_n_rules}{(positive integer) Minimum number of rules to keep} 26 | 27 | \item{...}{Named list of custom metrics passed to 28 | \link[=calculate.rulelist]{calculate}} 29 | } 30 | \value{ 31 | Object of class 'prune_ruleslist' with these components: 1. pruned: 32 | ruleset keeping only first 'pos' rows. 2. n_pruned_rules: pos. If stop 33 | criteria is never met, then pos = nrow(ruleset) 3. n_total_rules: 34 | nrow(ruleset), 4. metrics_df: Dataframe with metrics and relative metrics 35 | 5. stop_expr_string 36 | } 37 | \description{ 38 | Prune the \link{rulelist} by suggesting to keep first 'k' rules based 39 | on metrics computed by \link[=calculate.rulelist]{calculate} 40 | } 41 | \details{ 42 | \enumerate{ 43 | \item Metrics are computed using \link[=calculate.rulelist]{calculate}. 2. 44 | Relative metrics (prepended by 'relative__') are calculated by dividing 45 | each metric by its max value. 3. The first rule in rulelist order which 46 | meets the 'stop_expr_string' criteria is stored (say 'pos'). Print method 47 | suggests to keep rules until pos. 48 | } 49 | } 50 | \examples{ 51 | library("magrittr") 52 | model_c5 = C50::C5.0(Attrition ~., data = modeldata::attrition, rules = TRUE) 53 | tidy_c5 = tidy(model_c5) \%>\% 54 | set_validation_data(modeldata::attrition, "Attrition") \%>\% 55 | set_keys(NULL) 56 | 57 | #' prune with defaults 58 | prune_obj = prune(tidy_c5) 59 | #' note that all other metrics are visible in the print output 60 | prune_obj 61 | plot(prune_obj) 62 | prune_obj$pruned 63 | 64 | #' prune with a different stop_expr_string threshold 65 | prune_obj = prune(tidy_c5, 66 | stop_expr_string = "relative__cumulative_coverage >= 0.2" 67 | ) 68 | prune_obj #' as expected, has smaller then 10 rules as compared to default args 69 | plot(prune_obj) 70 | prune_obj$pruned 71 | 72 | #' prune with a different stop_expr_string metric 73 | st = "relative__cumulative_overlap <= 0.7 & relative__cumulative_overlap > 0" 74 | prune_obj = prune(tidy_c5, stop_expr_string = st) 75 | prune_obj #' as expected, has smaller then 10 rules as compared to default args 76 | plot(prune_obj) 77 | prune_obj$pruned 78 | 79 | } 80 | \seealso{ 81 | \link{rulelist}, \link{tidy}, \link[=augment.rulelist]{augment}, 82 | \link[=predict.rulelist]{predict}, \link[=calculate.rulelist]{calculate}, 83 | \link[=prune.rulelist]{prune}, \link[=reorder.rulelist]{reorder} 84 | } 85 | -------------------------------------------------------------------------------- /tests/testthat/test-rpart.R: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # This is the part of the 'tidyrules' R package hosted at 3 | # https://github.com/talegari/tidyrules with GPL-3 license. 4 | ################################################################################ 5 | 6 | context("test-rpart") 7 | 8 | # setup some models ---- 9 | data("attrition", package = "modeldata") 10 | 11 | # classification test 12 | attrition_class = 13 | attrition %>% 14 | tidytable::mutate( 15 | tidytable::across(tidytable::where(is.ordered), ~ factor(.x, ordered = F)) 16 | ) %>% 17 | tidytable::mutate(Attrition = factor(Attrition, levels = c("No", "Yes"))) 18 | 19 | rpart_att = rpart::rpart(Attrition ~ ., data = attrition_class) 20 | tr_att_class = tidy(rpart_att) 21 | 22 | # regression test 23 | attrition_reg = 24 | attrition %>% 25 | tidytable::mutate( 26 | tidytable::across(tidytable::where(is.ordered), ~ factor(.x, ordered = F)) 27 | ) %>% 28 | tidytable::select(-Attrition) 29 | 30 | rpart_att_reg = rpart::rpart(MonthlyIncome ~ ., data = attrition_reg) 31 | tr_att_reg = tidy(rpart_att_reg) 32 | 33 | # BreastCancer 34 | data(BreastCancer, package = "mlbench") 35 | bc = BreastCancer %>% 36 | dplyr::select(-Id) %>% 37 | dplyr::mutate_if(is.ordered, function(x) x = factor(x,ordered = F)) 38 | 39 | bc_1m = rpart::rpart(Class ~ ., data = bc) 40 | 41 | tr_bc_1 = tidy(bc_1m) 42 | 43 | # variables with spaces 44 | bc2 = bc 45 | 46 | colnames(bc2)[which(colnames(bc2) == "Cell.size")] = "Cell size" 47 | colnames(bc2)[which(colnames(bc2) == "Cell.shape")] = "Cell shape" 48 | 49 | bc_2m = rpart::rpart(Class ~ ., data = bc2) 50 | 51 | tr_bc_2 = tidy(bc_2m) 52 | 53 | # function to check whether a rule is filterable 54 | ruleFilterable = function(rule, data){ 55 | dplyr::filter(data, eval(parse(text = rule))) 56 | } 57 | 58 | # function to check whether all rules are filterable 59 | allRulesFilterable = function(tr, data){ 60 | parse_status = sapply( 61 | tr[["LHS"]], 62 | function(arule){ 63 | trydf = try(ruleFilterable(arule, data), silent = TRUE) 64 | if (nrow(trydf) == 0) print(arule) 65 | inherits(trydf, "data.frame") 66 | } 67 | ) 68 | return(parse_status) 69 | } 70 | 71 | # test for error while ordered features are present ---- 72 | test_that("check error",{ 73 | expect_error(tidy(rpart_att_1))}) 74 | 75 | # test output type ---- 76 | 77 | test_that("creates rulelist", { 78 | expect_is(tr_att_class, "rulelist") 79 | expect_is(tr_bc_1, "rulelist") 80 | expect_is(tr_bc_2, "rulelist") 81 | expect_is(tr_att_reg, "rulelist") 82 | }) 83 | 84 | # test NA ---- 85 | test_that("Are NA present", { 86 | expect_false(anyNA(tr_att_class)) 87 | expect_false(anyNA(tr_bc_1)) 88 | expect_false(anyNA(tr_bc_2)) 89 | expect_false(anyNA(tr_att_reg)) 90 | }) 91 | 92 | # test parsable ---- 93 | test_that("rules are parsable", { 94 | expect_true(all(allRulesFilterable(tr_att_class, attrition))) 95 | expect_true(all(allRulesFilterable(tr_bc_1, bc))) 96 | expect_true(all(allRulesFilterable(tr_bc_2, bc2))) 97 | expect_true(all(allRulesFilterable(tr_att_reg,attrition))) 98 | }) 99 | 100 | -------------------------------------------------------------------------------- /docs/sitemap.xml: -------------------------------------------------------------------------------- 1 | 2 | /404.html 3 | /articles/index.html 4 | /articles/tidyrules_vignette.html 5 | /articles/using_tidyrules.html 6 | /authors.html 7 | /index.html 8 | /news/index.html 9 | /reference/addBackquotes.html 10 | /reference/as_rulelist.data.frame.html 11 | /reference/as_rulelist.html 12 | /reference/as_ruleset.html 13 | /reference/augment.html 14 | /reference/augment.rulelist.html 15 | /reference/augment_class_keys.html 16 | /reference/augment_class_no_keys.html 17 | /reference/augment_regr_keys.html 18 | /reference/augment_regr_no_keys.html 19 | /reference/calculate.html 20 | /reference/calculate.rulelist.html 21 | /reference/convert_rule_flavor.html 22 | /reference/index.html 23 | /reference/package_tidyrules.html 24 | /reference/plot.prune_rulelist.html 25 | /reference/plot.rulelist.html 26 | /reference/positionSpaceOutsideSinglequotes.html 27 | /reference/predict.rulelist.html 28 | /reference/predict.ruleset.html 29 | /reference/predict_all_nokeys_rulelist.html 30 | /reference/predict_all_rulelist.html 31 | /reference/predict_nokeys_rulelist.html 32 | /reference/predict_rulelist.html 33 | /reference/print.prune_rulelist.html 34 | /reference/print.rulelist.html 35 | /reference/print.ruleset.html 36 | /reference/prune.html 37 | /reference/prune.rulelist.html 38 | /reference/removeEmptyLines.html 39 | /reference/reorder.html 40 | /reference/reorder.rulelist.html 41 | /reference/ruleRToPython.html 42 | /reference/ruleRToSQL.html 43 | /reference/rulelist.html 44 | /reference/ruleset.html 45 | /reference/set_keys.html 46 | /reference/set_validation_data.html 47 | /reference/strHead.html 48 | /reference/strReplaceReduce.html 49 | /reference/strSplitSingle.html 50 | /reference/strTail.html 51 | /reference/tidy.C5.0.html 52 | /reference/tidy.constparty.html 53 | /reference/tidy.cubist.html 54 | /reference/tidy.html 55 | /reference/tidy.rpart.html 56 | /reference/tidyRules.C5.0.html 57 | /reference/tidyRules.cubist.html 58 | /reference/tidyRules.html 59 | /reference/tidyRules.rpart.html 60 | /reference/to_sql_case.html 61 | /reference/varSpec.html 62 | 63 | 64 | -------------------------------------------------------------------------------- /tests/testthat/test-cubist.R: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # This is the part of the 'tidy' R package hosted at 3 | # https://github.com/talegari/tidy with GPL-3 license. 4 | ################################################################################ 5 | 6 | context("test-cubist") 7 | 8 | # setup some models ---- 9 | # attrition 10 | data("attrition", package = "modeldata") 11 | cols_att = setdiff(colnames(attrition), c("MonthlyIncome", "Attrition")) 12 | 13 | cb_att = 14 | Cubist::cubist(x = attrition[, cols_att], 15 | y = attrition[["MonthlyIncome"]] 16 | ) 17 | tr_att = tidy(cb_att) 18 | 19 | # attrition with commitees 20 | cb_att_2 = 21 | Cubist::cubist(x = attrition[, cols_att], 22 | y = attrition[["MonthlyIncome"]], 23 | committees = 7 24 | ) 25 | tr_att_2 = tidy(cb_att_2) 26 | 27 | # ames housing 28 | ames = AmesHousing::make_ames() 29 | cb_ames = Cubist::cubist(x = ames[, setdiff(colnames(ames), c("Sale_Price"))], 30 | y = log10(ames[["Sale_Price"]]), 31 | committees = 3 32 | ) 33 | tr_ames = tidy(cb_ames) 34 | 35 | 36 | # column name has a space in it 37 | data("Boston", package = "MASS") 38 | boston_2 = Boston 39 | names(boston_2)[6] = "r m" 40 | names(boston_2)[13] = "l stat" 41 | cb_boston = Cubist::cubist(x = boston_2[, -14], y = boston_2[[14]]) 42 | tr_boston = tidy(cb_boston) 43 | 44 | # function to check whether a rule is filterable 45 | ruleFilterable = function(rule, data){ 46 | dplyr::filter(data, eval(parse(text = rule))) 47 | } 48 | 49 | # function to check whether all rules are filterable 50 | allRulesFilterable = function(tr, data){ 51 | parse_status = sapply( 52 | tr[["LHS"]] 53 | , function(arule){ 54 | trydf = try(ruleFilterable(arule, data) 55 | , silent = TRUE 56 | ) 57 | if(nrow(trydf) == 0){ 58 | #print(arule) 59 | } 60 | inherits(trydf, "data.frame") && (nrow(trydf) > 0) 61 | } 62 | ) 63 | return(parse_status) 64 | } 65 | 66 | # evaluate RHS 67 | evalRHS = function(tr, data){ 68 | 69 | message(deparse(substitute(data))) 70 | 71 | with_RHS = sapply(tr[["RHS"]], 72 | function(x){ 73 | try(data %>% 74 | dplyr::mutate(RHS_ = eval(parse(text = x))) %>% 75 | dplyr::pull(RHS_) %>% 76 | is.numeric() 77 | , silent = TRUE 78 | )} 79 | , USE.NAMES = FALSE 80 | ) 81 | 82 | # print(which(!with_RHS)) 83 | return(all(with_RHS)) 84 | } 85 | 86 | # test output type ---- 87 | 88 | test_that("creates tibble", { 89 | expect_is(tr_att, "rulelist") 90 | expect_is(tr_att_2, "rulelist") 91 | expect_is(tr_ames, "rulelist") 92 | expect_is(tr_boston, "rulelist") 93 | }) 94 | 95 | # test NA ---- 96 | test_that("Are NA present", { 97 | expect_false(anyNA(tr_att)) 98 | expect_false(anyNA(tr_att_2)) 99 | expect_false(anyNA(tr_ames)) 100 | expect_false(anyNA(tr_boston)) 101 | }) 102 | 103 | # test parsable ---- 104 | test_that("rules are parsable", { 105 | expect_true(all(allRulesFilterable(tr_att, attrition))) 106 | expect_true(all(allRulesFilterable(tr_att_2, attrition))) 107 | expect_true(all(allRulesFilterable(tr_ames, ames))) 108 | expect_true(all(allRulesFilterable(tr_boston, boston_2))) 109 | }) 110 | 111 | # rhs is computable ---- 112 | test_that("rhs is computable", { 113 | expect_true(evalRHS(tr_att, attrition)) 114 | expect_true(evalRHS(tr_att_2, attrition)) 115 | expect_true(evalRHS(tr_ames, ames)) 116 | expect_true(evalRHS(tr_boston, boston_2)) 117 | }) 118 | 119 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('.navbar-fixed-top').headroom(); 6 | 7 | $('body').css('padding-top', $('.navbar').height() + 10); 8 | $(window).resize(function(){ 9 | $('body').css('padding-top', $('.navbar').height() + 10); 10 | }); 11 | 12 | $('[data-toggle="tooltip"]').tooltip(); 13 | 14 | var cur_path = paths(location.pathname); 15 | var links = $("#navbar ul li a"); 16 | var max_length = -1; 17 | var pos = -1; 18 | for (var i = 0; i < links.length; i++) { 19 | if (links[i].getAttribute("href") === "#") 20 | continue; 21 | // Ignore external links 22 | if (links[i].host !== location.host) 23 | continue; 24 | 25 | var nav_path = paths(links[i].pathname); 26 | 27 | var length = prefix_length(nav_path, cur_path); 28 | if (length > max_length) { 29 | max_length = length; 30 | pos = i; 31 | } 32 | } 33 | 34 | // Add class to parent
  • , and enclosing
  • if in dropdown 35 | if (pos >= 0) { 36 | var menu_anchor = $(links[pos]); 37 | menu_anchor.parent().addClass("active"); 38 | menu_anchor.closest("li.dropdown").addClass("active"); 39 | } 40 | }); 41 | 42 | function paths(pathname) { 43 | var pieces = pathname.split("/"); 44 | pieces.shift(); // always starts with / 45 | 46 | var end = pieces[pieces.length - 1]; 47 | if (end === "index.html" || end === "") 48 | pieces.pop(); 49 | return(pieces); 50 | } 51 | 52 | // Returns -1 if not found 53 | function prefix_length(needle, haystack) { 54 | if (needle.length > haystack.length) 55 | return(-1); 56 | 57 | // Special case for length-0 haystack, since for loop won't run 58 | if (haystack.length === 0) { 59 | return(needle.length === 0 ? 0 : -1); 60 | } 61 | 62 | for (var i = 0; i < haystack.length; i++) { 63 | if (needle[i] != haystack[i]) 64 | return(i); 65 | } 66 | 67 | return(haystack.length); 68 | } 69 | 70 | /* Clipboard --------------------------*/ 71 | 72 | function changeTooltipMessage(element, msg) { 73 | var tooltipOriginalTitle=element.getAttribute('data-original-title'); 74 | element.setAttribute('data-original-title', msg); 75 | $(element).tooltip('show'); 76 | element.setAttribute('data-original-title', tooltipOriginalTitle); 77 | } 78 | 79 | if(ClipboardJS.isSupported()) { 80 | $(document).ready(function() { 81 | var copyButton = ""; 82 | 83 | $("div.sourceCode").addClass("hasCopyButton"); 84 | 85 | // Insert copy buttons: 86 | $(copyButton).prependTo(".hasCopyButton"); 87 | 88 | // Initialize tooltips: 89 | $('.btn-copy-ex').tooltip({container: 'body'}); 90 | 91 | // Initialize clipboard: 92 | var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { 93 | text: function(trigger) { 94 | return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); 95 | } 96 | }); 97 | 98 | clipboardBtnCopies.on('success', function(e) { 99 | changeTooltipMessage(e.trigger, 'Copied!'); 100 | e.clearSelection(); 101 | }); 102 | 103 | clipboardBtnCopies.on('error', function() { 104 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 105 | }); 106 | }); 107 | } 108 | })(window.jQuery || window.$) 109 | -------------------------------------------------------------------------------- /R/ruleset.R: -------------------------------------------------------------------------------- 1 | #******************************************************************************* 2 | # This is the part of the 'tidyrules' R package hosted at 3 | # https://github.com/talegari/tidyrules with GPL-3 license. 4 | #******************************************************************************* 5 | 6 | #' @name ruleset 7 | #' @title Ruleset 8 | #' @description ruleset class is a piggyback class that inherits [rulelist] 9 | #' class for convenience of [print] and [predict] methods. 10 | identity # just a placeholder for 'ruleset' documentation, not exported 11 | 12 | #' @name as_ruleset 13 | #' @title Get a ruleset from a rulelist 14 | #' @description Returns a ruleset object 15 | #' @param rulelist A [rulelist] 16 | #' @returns A [ruleset] 17 | #' 18 | #' @examples 19 | #' model_class_party = partykit::ctree(species ~ ., 20 | #' data = palmerpenguins::penguins 21 | #' ) 22 | #' as_ruleset(tidy(model_class_party)) 23 | #' 24 | #' @seealso [rulelist] 25 | #' @export 26 | as_ruleset = function(rulelist){ 27 | 28 | validate_rulelist(rulelist) 29 | 30 | x = rlang::duplicate(rulelist) 31 | class(x) = c("ruleset", class(x)) 32 | 33 | return(x) 34 | } 35 | 36 | #' @name print.ruleset 37 | #' @title Print method for ruleset class 38 | #' @description Prints the ruleset object 39 | #' @param x A [rulelist] 40 | #' @param banner (flag, default: `TRUE`) Should the banner be displayed 41 | #' @param ... Passed to `print.rulelist` 42 | #' @returns (invisibly) Returns the ruleset object 43 | #' 44 | #' @examples 45 | #' model_class_party = partykit::ctree(species ~ ., 46 | #' data = palmerpenguins::penguins 47 | #' ) 48 | #' as_ruleset(tidy(model_class_party)) 49 | #' 50 | #' @seealso [print.rulelist] 51 | #' @export 52 | print.ruleset = function(x, banner = TRUE, ...){ 53 | 54 | ruleset = rlang::duplicate(x) 55 | 56 | text = character(0) 57 | if (banner) { 58 | text = c(text, "---- Ruleset -------------------------------") 59 | } 60 | 61 | class(ruleset) = setdiff(class(ruleset), "ruleset") 62 | text = c(text, 63 | capture.output(print(ruleset, banner = FALSE, ...), 64 | file = NULL 65 | ) 66 | ) 67 | 68 | if (banner) { 69 | text = c(text, "--------------------------------------------") 70 | } 71 | cat(paste(text, collapse = "\n")) 72 | 73 | return(invisible(x)) 74 | } 75 | 76 | #' @name predict.ruleset 77 | #' @title `predict` method for a [ruleset] 78 | #' @description Predicts multiple `rule_nbr`(s) applicable for a `row_nbr` (per 79 | #' key) in new_data 80 | #' 81 | #' @param object A [ruleset] 82 | #' @param new_data (dataframe) 83 | #' @param ... unused 84 | #' 85 | #' @returns A dataframe with three or more columns: `row_number` (int), columns 86 | #' corresponding to 'keys', `rule_nbr` (list column of integers). If a row 87 | #' number and 'keys' combination is not covered by any rule, then `rule_nbr` 88 | #' column has missing value. 89 | #' 90 | #' @examples 91 | #' model_c5 = C50::C5.0(species ~., 92 | #' data = palmerpenguins::penguins, 93 | #' trials = 5, 94 | #' rules = TRUE 95 | #' ) 96 | #' tidy_c5_ruleset = as_ruleset(tidy(model_c5)) 97 | #' tidy_c5_ruleset 98 | #' 99 | #' predict(tidy_c5_ruleset, palmerpenguins::penguins) 100 | #' 101 | #' @seealso [predict.rulelist] 102 | #' @importFrom stats predict 103 | #' @export 104 | predict.ruleset = function(object, new_data, ...){ 105 | 106 | x = rlang::duplicate(object) 107 | class(x) = setdiff(class(x), "ruleset") 108 | 109 | # now 'ruleset' is a rulelist 110 | res = predict(x, new_data, multiple = TRUE, ...) 111 | 112 | return(res) 113 | } 114 | -------------------------------------------------------------------------------- /R/package.R: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # This is the part of the 'tidyrules' R package hosted at 3 | # https://github.com/talegari/tidyrules with GPL-3 license. 4 | ################################################################################ 5 | 6 | #' @name package_tidyrules 7 | #' @title `tidyrules` 8 | #' @description `tidyrules` package provides a framework to work with decision 9 | #' rules. Rules can be extracted from supported models using [tidy], augmented 10 | #' using validation data by [augment][augment.rulelist], manipulated using 11 | #' standard dataframe operations, (modified) rulelists can be used to 12 | #' [predict][predict.rulelist] on unseen (test) data. Utilities include: 13 | #' Create a rulelist manually ([as_rulelist][as_rulelist.data.frame]), Export 14 | #' a rulelist to SQL ([to_sql_case]) and so on. The package offers two 15 | #' classes; [rulelist] and [ruleset] based on dataframe. 16 | #' @seealso [rulelist], [tidy], [augment][augment.rulelist], 17 | #' [predict][predict.rulelist] 18 | #' @importFrom magrittr %>% 19 | #' @importFrom rlang %||% 20 | #' @importFrom data.table := 21 | #' @importFrom utils data 22 | #' @importFrom stats IQR 23 | #' @importFrom stats weighted.mean 24 | #' @importFrom tidytable select 25 | #' @importFrom tidytable arrange 26 | #' @importFrom tidytable mutate 27 | #' @importFrom tidytable summarise 28 | #' @importFrom tidytable distinct 29 | #' @importFrom tidytable all_of 30 | #' @importFrom tidytable n 31 | #' @importFrom tidytable left_join 32 | #' @importFrom tidytable right_join 33 | #' @importFrom tidytable inner_join 34 | #' @importFrom tidytable inner_join 35 | #' @importFrom tidytable nest 36 | #' @importFrom tidytable unnest 37 | #' @importFrom tidytable row_number 38 | #' @importFrom tidytable drop_na 39 | #' @importFrom tidytable relocate 40 | #' @importFrom tidytable bind_rows 41 | #' @importFrom tidytable pull 42 | #' @importFrom tidytable slice 43 | #' @importFrom tidytable pivot_wider 44 | #' @importFrom tidytable pivot_longer 45 | #' @importFrom tidytable bind_cols 46 | #' @importFrom tidytable across 47 | #' @importFrom graphics abline 48 | #' @importFrom graphics axis 49 | #' @importFrom graphics legend 50 | #' @importFrom graphics lines 51 | #' @importFrom stats runif 52 | #' @importFrom utils head 53 | #' @importFrom utils tail 54 | #' @importFrom utils capture.output 55 | #' 56 | "_PACKAGE" 57 | 58 | list.rules.party = getFromNamespace(".list.rules.party", "partykit") 59 | 60 | utils::globalVariables(c(".", 61 | "LHS", 62 | "RHS", 63 | "committee", 64 | "desc", 65 | "dev", 66 | "lift", 67 | "n", 68 | "predict_class", 69 | "rule_nbr", 70 | "rule_number", 71 | "support", 72 | "trial_number", 73 | "yval", 74 | "confidence", 75 | "rn__", 76 | "row_nbr", 77 | "pref__", 78 | "data", 79 | "weight", 80 | "response", 81 | "terminal_node_id", 82 | "sum_weight", 83 | "prevalence", 84 | "winning_response", 85 | "average", 86 | "RMSE", 87 | "weight__", 88 | "prevalence_0", 89 | ".data", 90 | "rn_df", 91 | "trial_nbr", 92 | "error", 93 | "data__", 94 | "rn_df__", 95 | "hit", 96 | "priority", 97 | "value" 98 | ) 99 | ) 100 | 101 | -------------------------------------------------------------------------------- /man/augment.rulelist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{augment.rulelist} 4 | \alias{augment.rulelist} 5 | \title{Augment a \link{rulelist}} 6 | \usage{ 7 | \method{augment}{rulelist}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{A \link{rulelist}} 11 | 12 | \item{...}{(expressions) To be send to \link[tidytable:summarize]{tidytable::summarise} for custom 13 | aggregations. See examples.} 14 | } 15 | \value{ 16 | A \link{rulelist} with a new dataframe-column named \code{augmented_stats}. 17 | } 18 | \description{ 19 | \code{augment} outputs a \link{rulelist} with an additional column named 20 | \code{augmented_stats} based on summary statistics calculated using attribute 21 | \code{validation_data}. 22 | } 23 | \details{ 24 | The dataframe-column \code{augmented_stats} will have these columns 25 | corresponding to the \code{estimation_type}: 26 | \itemize{ 27 | \item For \code{regression}: \code{support}, \code{IQR}, \code{RMSE} 28 | \item For \code{classification}: \code{support}, \code{confidence}, \code{lift} 29 | } 30 | 31 | along with custom aggregations. 32 | } 33 | \examples{ 34 | # Examples for augment ------------------------------------------------------ 35 | library("magrittr") 36 | 37 | # C5 ---- 38 | att = modeldata::attrition 39 | set.seed(100) 40 | train_index = sample(c(TRUE, FALSE), nrow(att), replace = TRUE) 41 | 42 | model_c5 = C50::C5.0(Attrition ~., data = att[train_index, ], rules = TRUE) 43 | tidy_c5 = 44 | model_c5 \%>\% 45 | tidy() \%>\% 46 | set_validation_data(att[!train_index, ], "Attrition") 47 | 48 | tidy_c5 49 | 50 | augment(tidy_c5) \%>\% 51 | tidytable::unnest(augmented_stats, names_sep = "__") \%>\% 52 | tidytable::glimpse() 53 | 54 | # augment with custom aggregator 55 | augment(tidy_c5,output_counts = list(table(Attrition))) \%>\% 56 | tidytable::unnest(augmented_stats, names_sep = "__") \%>\% 57 | tidytable::glimpse() 58 | 59 | # rpart ---- 60 | set.seed(100) 61 | train_index = sample(c(TRUE, FALSE), nrow(iris), replace = TRUE) 62 | 63 | model_class_rpart = rpart::rpart(Species ~ ., data = iris[train_index, ]) 64 | tidy_class_rpart = tidy(model_class_rpart) \%>\% 65 | set_validation_data(iris[!train_index, ], "Species") 66 | tidy_class_rpart 67 | 68 | model_regr_rpart = rpart::rpart(Sepal.Length ~ ., data = iris[train_index, ]) 69 | tidy_regr_rpart = tidy(model_regr_rpart) \%>\% 70 | set_validation_data(iris[!train_index, ], "Sepal.Length") 71 | tidy_regr_rpart 72 | 73 | # augment (classification case) 74 | augment(tidy_class_rpart) \%>\% 75 | tidytable::unnest(augmented_stats, names_sep = "__") \%>\% 76 | tidytable::glimpse() 77 | 78 | # augment (regression case) 79 | augment(tidy_regr_rpart) \%>\% 80 | tidytable::unnest(augmented_stats, names_sep = "__") \%>\% 81 | tidytable::glimpse() 82 | 83 | # party ---- 84 | pen = palmerpenguins::penguins \%>\% 85 | tidytable::drop_na(bill_length_mm) 86 | set.seed(100) 87 | train_index = sample(c(TRUE, FALSE), nrow(pen), replace = TRUE) 88 | 89 | model_class_party = partykit::ctree(species ~ ., data = pen[train_index, ]) 90 | tidy_class_party = tidy(model_class_party) \%>\% 91 | set_validation_data(pen[!train_index, ], "species") 92 | tidy_class_party 93 | 94 | model_regr_party = 95 | partykit::ctree(bill_length_mm ~ ., data = pen[train_index, ]) 96 | tidy_regr_party = tidy(model_regr_party) \%>\% 97 | set_validation_data(pen[!train_index, ], "bill_length_mm") 98 | tidy_regr_party 99 | 100 | # augment (classification case) 101 | augment(tidy_class_party) \%>\% 102 | tidytable::unnest(augmented_stats, names_sep = "__") \%>\% 103 | tidytable::glimpse() 104 | 105 | # augment (regression case) 106 | augment(tidy_regr_party) \%>\% 107 | tidytable::unnest(augmented_stats, names_sep = "__") \%>\% 108 | tidytable::glimpse() 109 | 110 | # cubist ---- 111 | att = modeldata::attrition 112 | set.seed(100) 113 | train_index = sample(c(TRUE, FALSE), nrow(att), replace = TRUE) 114 | cols_att = setdiff(colnames(att), c("MonthlyIncome", "Attrition")) 115 | 116 | model_cubist = Cubist::cubist(x = att[train_index, cols_att], 117 | y = att[train_index, "MonthlyIncome"] 118 | ) 119 | 120 | tidy_cubist = tidy(model_cubist) \%>\% 121 | set_validation_data(att[!train_index, ], "MonthlyIncome") 122 | tidy_cubist 123 | 124 | augment(tidy_cubist) \%>\% 125 | tidytable::unnest(augmented_stats, names_sep = "__") \%>\% 126 | tidytable::glimpse() 127 | 128 | } 129 | \seealso{ 130 | \link{rulelist}, \link{tidy}, \link[=augment.rulelist]{augment}, 131 | \link[=predict.rulelist]{predict}, \link[=calculate.rulelist]{calculate}, 132 | \link[=prune.rulelist]{prune}, \link[=reorder.rulelist]{reorder} 133 | } 134 | -------------------------------------------------------------------------------- /man/rulelist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{rulelist} 4 | \alias{rulelist} 5 | \title{Rulelist} 6 | \description{ 7 | \subsection{Structure}{ 8 | 9 | A \code{rulelist} is ordered list of rules stored as a dataframe. Each row, 10 | specifies a rule (LHS), expected outcome (RHS) and some other details. 11 | 12 | It has these mandatory columns: 13 | \itemize{ 14 | \item \code{rule_nbr}: (integer vector) Rule number 15 | \item \code{LHS}: (character vector) A rule is a string that can be parsed using \code{\link[base:parse]{base::parse()}} 16 | \item \code{RHS}: (character vector or a literal) 17 | } 18 | } 19 | 20 | \subsection{Example}{ 21 | 22 | \if{html}{\out{
    }}\preformatted{| rule_nbr|LHS |RHS | support| confidence| lift| 23 | |--------:|:--------------------------------------------------------------------|:---------|-------:|----------:|--------:| 24 | | 1|( island \%in\% c('Biscoe') ) & ( flipper_length_mm > 203 ) |Gentoo | 122| 1.0000000| 2.774193| 25 | | 2|( island \%in\% c('Biscoe') ) & ( flipper_length_mm <= 203 ) |Adelie | 46| 0.9565217| 2.164760| 26 | | 3|( island \%in\% c('Dream', 'Torgersen') ) & ( bill_length_mm > 44.1 ) |Chinstrap | 65| 0.9538462| 4.825339| 27 | | 4|( island \%in\% c('Dream', 'Torgersen') ) & ( bill_length_mm <= 44.1 ) |Adelie | 111| 0.9459459| 2.140825| 28 | }\if{html}{\out{
    }} 29 | } 30 | 31 | \subsection{Create a rulelist}{ 32 | 33 | A \code{rulelist} can be created using \code{\link[=tidy]{tidy()}} on some supported model fits 34 | (run: \code{utils::methods(tidy)}). It can also be created manually from a 35 | existing dataframe using \link[=as_rulelist.data.frame]{as_rulelist}. 36 | } 37 | 38 | \subsection{Keys and attributes}{ 39 | 40 | Columns identified as 'keys' along with \code{rule_nbr} form a unique 41 | combination 42 | -- a group of rules. For example, rule-based C5 model with multiple trials 43 | creates rules per each \code{trial_nbr}. \code{predict} method understands 'keys', 44 | thereby provides/predicts a rule number (for each row in new data / test 45 | data) within the same \code{trial_nbr}. 46 | 47 | A rulelist has these mandatory attributes: 48 | \itemize{ 49 | \item \code{estimation_type}: One among \code{regression}, \code{classification} 50 | 51 | A rulelist has these optional attributes: 52 | \item \code{keys}: (character vector)Names of the column that forms a key. 53 | \item \code{model_type}: (string) Name of the model 54 | } 55 | 56 | \subsection{Set Validation data}{ 57 | 58 | This helps a few methods like \link{augment}, \link{calculate}, \link{prune}, \link{reorder} 59 | require few additional attributes which can be set using 60 | \link{set_validation_data}. 61 | } 62 | 63 | \subsection{Methods for rulelist}{ 64 | \enumerate{ 65 | \item \link[=predict.rulelist]{Predict}: Given a dataframe (possibly without a 66 | dependent variable column aka 'test data'), predicts the first rule (as 67 | ordered in the rulelist) per 'keys' that is applicable for each row. When 68 | \code{multiple = TRUE}, returns all rules applicable for a row (per key). 69 | \item \link[=augment.rulelist]{Augment}: Outputs summary statistics per rule over 70 | validation data and returns a rulelist with a new dataframe-column. 71 | \item \link[=calculate.rulelist]{Calculate}: Computes metrics for a rulelist in a 72 | cumulative manner such as \code{cumulative_coverage}, \code{cumulative_overlap}, 73 | \code{cumulative_accuracy}. 74 | \item \link[=prune.rulelist]{Prune}: Suggests pruning a rulelist such that some 75 | expectation are met (based on metrics). Example: cumulative_coverage of 80\% 76 | can be met with a first few rules. 77 | \item \link[=reorder.rulelist]{Reorder}: Reorders a rulelist in order to maximize a 78 | metric. 79 | } 80 | } 81 | 82 | \subsection{Manipulating a rulelist}{ 83 | 84 | Rulelists are essentially dataframes. Hence, any dataframe operations which 85 | preferably preserve attributes will output a rulelist. \link{as_rulelist} and 86 | \link{as.data.frame} will help in moving back and forth between rulelist and 87 | dataframe worlds. 88 | } 89 | 90 | \subsection{Utilities for a rulelist}{ 91 | \enumerate{ 92 | \item \link[=as_rulelist.data.frame]{as_rulelist}: Create a \code{rulelist} from a 93 | dataframe with some mandatory columns. 94 | \item \link{set_keys}: Set or Unset 'keys' of a \code{rulelist}. 95 | \item \link{to_sql_case}: Outputs a SQL case statement for a \code{rulelist}. 96 | \item \link{convert_rule_flavor}: Converts \code{R}-parsable rule strings to python/SQL 97 | parsable rule strings. 98 | } 99 | } 100 | } 101 | } 102 | \seealso{ 103 | \link{rulelist}, \link{tidy}, \link[=augment.rulelist]{augment}, 104 | \link[=predict.rulelist]{predict}, \link[=calculate.rulelist]{calculate}, 105 | \link[=prune.rulelist]{prune}, \link[=reorder.rulelist]{reorder} 106 | } 107 | -------------------------------------------------------------------------------- /docs/articles/index.html: -------------------------------------------------------------------------------- 1 | 2 | Articles • tidyrules 6 | 7 | 8 |
    9 |
    50 | 51 | 52 | 53 |
    54 |
    55 | 58 | 59 |
    60 |

    All vignettes

    61 |

    62 | 63 |
    Using tidyrules
    64 |
    65 |
    66 |
    67 |
    68 | 69 | 70 |
    73 | 74 |
    75 |

    Site built with pkgdown 2.1.1.

    76 |
    77 | 78 |
    79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | (function() { 6 | 'use strict'; 7 | 8 | window.Toc = { 9 | helpers: { 10 | // return all matching elements in the set, or their descendants 11 | findOrFilter: function($el, selector) { 12 | // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ 13 | // http://stackoverflow.com/a/12731439/358804 14 | var $descendants = $el.find(selector); 15 | return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); 16 | }, 17 | 18 | generateUniqueIdBase: function(el) { 19 | var text = $(el).text(); 20 | var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); 21 | return anchor || el.tagName.toLowerCase(); 22 | }, 23 | 24 | generateUniqueId: function(el) { 25 | var anchorBase = this.generateUniqueIdBase(el); 26 | for (var i = 0; ; i++) { 27 | var anchor = anchorBase; 28 | if (i > 0) { 29 | // add suffix 30 | anchor += '-' + i; 31 | } 32 | // check if ID already exists 33 | if (!document.getElementById(anchor)) { 34 | return anchor; 35 | } 36 | } 37 | }, 38 | 39 | generateAnchor: function(el) { 40 | if (el.id) { 41 | return el.id; 42 | } else { 43 | var anchor = this.generateUniqueId(el); 44 | el.id = anchor; 45 | return anchor; 46 | } 47 | }, 48 | 49 | createNavList: function() { 50 | return $(''); 51 | }, 52 | 53 | createChildNavList: function($parent) { 54 | var $childList = this.createNavList(); 55 | $parent.append($childList); 56 | return $childList; 57 | }, 58 | 59 | generateNavEl: function(anchor, text) { 60 | var $a = $(''); 61 | $a.attr('href', '#' + anchor); 62 | $a.text(text); 63 | var $li = $('
  • '); 64 | $li.append($a); 65 | return $li; 66 | }, 67 | 68 | generateNavItem: function(headingEl) { 69 | var anchor = this.generateAnchor(headingEl); 70 | var $heading = $(headingEl); 71 | var text = $heading.data('toc-text') || $heading.text(); 72 | return this.generateNavEl(anchor, text); 73 | }, 74 | 75 | // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). 76 | getTopLevel: function($scope) { 77 | for (var i = 1; i <= 6; i++) { 78 | var $headings = this.findOrFilter($scope, 'h' + i); 79 | if ($headings.length > 1) { 80 | return i; 81 | } 82 | } 83 | 84 | return 1; 85 | }, 86 | 87 | // returns the elements for the top level, and the next below it 88 | getHeadings: function($scope, topLevel) { 89 | var topSelector = 'h' + topLevel; 90 | 91 | var secondaryLevel = topLevel + 1; 92 | var secondarySelector = 'h' + secondaryLevel; 93 | 94 | return this.findOrFilter($scope, topSelector + ',' + secondarySelector); 95 | }, 96 | 97 | getNavLevel: function(el) { 98 | return parseInt(el.tagName.charAt(1), 10); 99 | }, 100 | 101 | populateNav: function($topContext, topLevel, $headings) { 102 | var $context = $topContext; 103 | var $prevNav; 104 | 105 | var helpers = this; 106 | $headings.each(function(i, el) { 107 | var $newNav = helpers.generateNavItem(el); 108 | var navLevel = helpers.getNavLevel(el); 109 | 110 | // determine the proper $context 111 | if (navLevel === topLevel) { 112 | // use top level 113 | $context = $topContext; 114 | } else if ($prevNav && $context === $topContext) { 115 | // create a new level of the tree and switch to it 116 | $context = helpers.createChildNavList($prevNav); 117 | } // else use the current $context 118 | 119 | $context.append($newNav); 120 | 121 | $prevNav = $newNav; 122 | }); 123 | }, 124 | 125 | parseOps: function(arg) { 126 | var opts; 127 | if (arg.jquery) { 128 | opts = { 129 | $nav: arg 130 | }; 131 | } else { 132 | opts = arg; 133 | } 134 | opts.$scope = opts.$scope || $(document.body); 135 | return opts; 136 | } 137 | }, 138 | 139 | // accepts a jQuery object, or an options object 140 | init: function(opts) { 141 | opts = this.helpers.parseOps(opts); 142 | 143 | // ensure that the data attribute is in place for styling 144 | opts.$nav.attr('data-toggle', 'toc'); 145 | 146 | var $topContext = this.helpers.createChildNavList(opts.$nav); 147 | var topLevel = this.helpers.getTopLevel(opts.$scope); 148 | var $headings = this.helpers.getHeadings(opts.$scope, topLevel); 149 | this.helpers.populateNav($topContext, topLevel, $headings); 150 | } 151 | }; 152 | 153 | $(function() { 154 | $('nav[data-toggle="toc"]').each(function(i, el) { 155 | var $nav = $(el); 156 | Toc.init($nav); 157 | }); 158 | }); 159 | })(); 160 | -------------------------------------------------------------------------------- /man/calculate.rulelist.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rulelist.R 3 | \name{calculate.rulelist} 4 | \alias{calculate.rulelist} 5 | \title{\code{calculate} metrics for a \link{rulelist}} 6 | \usage{ 7 | \method{calculate}{rulelist}(x, metrics_to_exclude = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{x}{A \link{rulelist}} 11 | 12 | \item{metrics_to_exclude}{(character vector) Names of metrics to exclude} 13 | 14 | \item{...}{Named list of custom metrics. See 'details'.} 15 | } 16 | \value{ 17 | A dataframe of metrics with a \code{rule_nbr} column. 18 | } 19 | \description{ 20 | Computes some metrics (based on \code{estimation_type}) in cumulative 21 | window function style over the rulelist (in the same order) ignoring the 22 | keys. 23 | } 24 | \details{ 25 | \subsection{Default Metrics}{ 26 | 27 | These metrics are calculated by default: 28 | \itemize{ 29 | \item \code{cumulative_coverage}: For nth rule in the rulelist, number of distinct \code{row_nbr}s (of \code{new_data}) covered by nth and all preceding rules (in order). In weighted case, we sum the weights corresponding to the distinct \code{row_nbr}s. 30 | \item \code{cumulative_overlap}: Up til nth rule in the rulelist, number of distinct \code{row_nbr}s (of \code{new_data}) already covered by some preceding rule (in order). In weighted case, we sum the weights corresponding to the distinct \code{row_nbr}s. 31 | } 32 | 33 | For classification: 34 | \itemize{ 35 | \item \code{cumulative_accuracy}: For nth rule in the rulelist, fraction of \code{row_nbr}s such that \code{RHS} matches the \code{y_name} column (of \code{new_data}) by nth and all preceding rules (in order). In weighted case, weighted accuracy is computed. 36 | } 37 | 38 | For regression: 39 | \itemize{ 40 | \item \code{cumulative_RMSE}: For nth rule in the rulelist, weighted RMSE of all predictions (\code{RHS}) predicted by nth rule and all preceding rules. 41 | } 42 | } 43 | 44 | \subsection{Custom metrics}{ 45 | 46 | Custom metrics to be computed should be passed a named list of function(s) in 47 | \code{...}. The custom metric function should take these arguments in same order: 48 | \code{rulelist}, \code{new_data}, \code{y_name}, \code{weight}. The custom metric function should 49 | return a numeric vector of same length as the number of rows of rulelist. 50 | } 51 | } 52 | \examples{ 53 | library("magrittr") 54 | model_c5 = C50::C5.0(Attrition ~., data = modeldata::attrition, rules = TRUE) 55 | tidy_c5 = tidy(model_c5) \%>\% 56 | set_validation_data(modeldata::attrition, "Attrition") \%>\% 57 | set_keys(NULL) 58 | 59 | # calculate default metrics (classification) 60 | calculate(tidy_c5) 61 | 62 | model_rpart = rpart::rpart(MonthlyIncome ~., data = modeldata::attrition) 63 | tidy_rpart = 64 | tidy(model_rpart) \%>\% 65 | set_validation_data(modeldata::attrition, "MonthlyIncome") \%>\% 66 | set_keys(NULL) 67 | 68 | # calculate default metrics (regression) 69 | calculate(tidy_rpart) 70 | 71 | # calculate default metrics with a custom metric 72 | #' custom function to get cumulative MAE 73 | library("tidytable") 74 | get_cumulative_MAE = function(rulelist, new_data, y_name, weight){ 75 | 76 | priority_df = 77 | rulelist \%>\% 78 | select(rule_nbr) \%>\% 79 | mutate(priority = 1:nrow(rulelist)) \%>\% 80 | select(rule_nbr, priority) 81 | 82 | pred_df = 83 | predict(rulelist, new_data) \%>\% 84 | left_join(priority_df, by = "rule_nbr") \%>\% 85 | mutate(weight = local(weight)) \%>\% 86 | select(rule_nbr, row_nbr, weight, priority) 87 | 88 | new_data2 = 89 | new_data \%>\% 90 | mutate(row_nbr = 1:n()) \%>\% 91 | select(all_of(c("row_nbr", y_name))) 92 | 93 | rmse_till_rule = function(rn){ 94 | 95 | if (is.character(rulelist$RHS)) { 96 | inter_df = 97 | pred_df \%>\% 98 | tidytable::filter(priority <= rn) \%>\% 99 | left_join(mutate(new_data, row_nbr = 1:n()), by = "row_nbr") \%>\% 100 | left_join(select(rulelist, rule_nbr, RHS), by = "rule_nbr") \%>\% 101 | nest(.by = c("RHS", "rule_nbr", "row_nbr", "priority", "weight")) \%>\% 102 | mutate(RHS = purrr::map2_dbl(RHS, 103 | data, 104 | ~ eval(parse(text = .x), envir = .y) 105 | ) 106 | ) \%>\% 107 | unnest(data) 108 | } else { 109 | 110 | inter_df = 111 | pred_df \%>\% 112 | tidytable::filter(priority <= rn) \%>\% 113 | left_join(new_data2, by = "row_nbr") \%>\% 114 | left_join(select(rulelist, rule_nbr, RHS), by = "rule_nbr") 115 | } 116 | 117 | inter_df \%>\% 118 | summarise(rmse = MetricsWeighted::mae(RHS, 119 | .data[[y_name]], 120 | weight, 121 | na.rm = TRUE 122 | ) 123 | ) \%>\% 124 | `[[`("rmse") 125 | } 126 | 127 | res = purrr::map_dbl(1:nrow(rulelist), rmse_till_rule) 128 | return(res) 129 | } 130 | 131 | calculate(tidy_rpart, 132 | metrics_to_exclude = NULL, 133 | list("cumulative_mae" = get_cumulative_MAE) 134 | ) 135 | 136 | } 137 | \seealso{ 138 | \link{rulelist}, \link{tidy}, \link[=augment.rulelist]{augment}, 139 | \link[=predict.rulelist]{predict}, \link[=calculate.rulelist]{calculate}, 140 | \link[=prune.rulelist]{prune}, \link[=reorder.rulelist]{reorder} 141 | } 142 | -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Page not found (404) • tidyrules 9 | 10 | 11 | 12 | 13 | 14 | 15 | 19 | 20 | 21 | 22 | 23 |
    24 |
    73 | 74 | 75 | 76 | 77 |
    78 |
    79 | 82 | 83 | Content not found. Please use links in the navbar. 84 | 85 |
    86 | 87 | 91 | 92 |
    93 | 94 | 95 | 96 |
    100 | 101 |
    102 |

    103 |

    Site built with pkgdown 2.1.1.

    104 |
    105 | 106 |
    107 |
    108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /docs/reference/ruleset.html: -------------------------------------------------------------------------------- 1 | 2 | Ruleset — ruleset • tidyrules 7 | 8 | 9 |
    10 |
    51 | 52 | 53 | 54 |
    55 |
    56 | 61 | 62 |
    63 |

    ruleset class is a piggyback class that inherits rulelist 64 | class for convenience of print and predict methods.

    65 |
    66 | 67 | 68 | 69 |
    70 | 73 |
    74 | 75 | 76 |
    79 | 80 |
    81 |

    Site built with pkgdown 2.1.1.

    82 |
    83 | 84 |
    85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /docs/reference/augment_regr_keys.html: -------------------------------------------------------------------------------- 1 | 2 | as the name says — augment_regr_keys • tidyrules 7 | 8 | 9 |
    10 |
    51 | 52 | 53 | 54 |
    55 |
    56 | 61 | 62 |
    63 |

    as the name says 64 | not to be exported

    65 |
    66 | 67 |
    68 |
    augment_regr_keys(x, new_data, y_name, weight, ...)
    69 |
    70 | 71 | 72 |
    73 | 76 |
    77 | 78 | 79 |
    82 | 83 |
    84 |

    Site built with pkgdown 2.1.1.

    85 |
    86 | 87 |
    88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /docs/reference/augment_class_keys.html: -------------------------------------------------------------------------------- 1 | 2 | as the name says — augment_class_keys • tidyrules 7 | 8 | 9 |
    10 |
    51 | 52 | 53 | 54 |
    55 |
    56 | 61 | 62 |
    63 |

    as the name says 64 | not to be exported

    65 |
    66 | 67 |
    68 |
    augment_class_keys(x, new_data, y_name, weight, ...)
    69 |
    70 | 71 | 72 |
    73 | 76 |
    77 | 78 | 79 |
    82 | 83 |
    84 |

    Site built with pkgdown 2.1.1.

    85 |
    86 | 87 |
    88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /docs/reference/augment_regr_no_keys.html: -------------------------------------------------------------------------------- 1 | 2 | as the name says — augment_regr_no_keys • tidyrules 7 | 8 | 9 |
    10 |
    51 | 52 | 53 | 54 |
    55 |
    56 | 61 | 62 |
    63 |

    as the name says 64 | not to be exported

    65 |
    66 | 67 |
    68 |
    augment_regr_no_keys(x, new_data, y_name, weight, ...)
    69 |
    70 | 71 | 72 |
    73 | 76 |
    77 | 78 | 79 |
    82 | 83 |
    84 |

    Site built with pkgdown 2.1.1.

    85 |
    86 | 87 |
    88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /docs/reference/augment_class_no_keys.html: -------------------------------------------------------------------------------- 1 | 2 | as the name says — augment_class_no_keys • tidyrules 7 | 8 | 9 |
    10 |
    51 | 52 | 53 | 54 |
    55 |
    56 | 61 | 62 |
    63 |

    as the name says 64 | not to be exported

    65 |
    66 | 67 |
    68 |
    augment_class_no_keys(x, new_data, y_name, weight, ...)
    69 |
    70 | 71 | 72 |
    73 | 76 |
    77 | 78 | 79 |
    82 | 83 |
    84 |

    Site built with pkgdown 2.1.1.

    85 |
    86 | 87 |
    88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /docs/reference/predict_nokeys_rulelist.html: -------------------------------------------------------------------------------- 1 | 2 | as the name says — predict_nokeys_rulelist • tidyrules 6 | 7 | 8 |
    9 |
    50 | 51 | 52 | 53 |
    54 |
    55 | 60 | 61 |
    62 |

    as the name says

    63 |
    64 | 65 |
    66 |
    predict_nokeys_rulelist(rulelist, new_data)
    67 |
    68 | 69 |
    70 |

    Arguments

    71 | 72 | 73 |
    rulelist
    74 |

    rulelist

    75 | 76 | 77 |
    new_data
    78 |

    new_data

    79 | 80 |
    81 |
    82 |

    Value

    83 |

    dataframe

    84 |
    85 | 86 |
    87 | 90 |
    91 | 92 | 93 |
    96 | 97 |
    98 |

    Site built with pkgdown 2.1.1.

    99 |
    100 | 101 |
    102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /docs/reference/predict_rulelist.html: -------------------------------------------------------------------------------- 1 | 2 | with or without keys — predict_rulelist • tidyrules 6 | 7 | 8 |
    9 |
    50 | 51 | 52 | 53 |
    54 |
    55 | 60 | 61 |
    62 |

    uses predict_nokeys_rulelist

    63 |
    64 | 65 |
    66 |
    predict_rulelist(rulelist, new_data)
    67 |
    68 | 69 |
    70 |

    Arguments

    71 | 72 | 73 |
    rulelist
    74 |

    rulelist

    75 | 76 | 77 |
    new_data
    78 |

    new_data

    79 | 80 |
    81 |
    82 |

    Value

    83 |

    dataframe

    84 |
    85 | 86 |
    87 | 90 |
    91 | 92 | 93 |
    96 | 97 |
    98 |

    Site built with pkgdown 2.1.1.

    99 |
    100 | 101 |
    102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /docs/reference/predict_all_nokeys_rulelist.html: -------------------------------------------------------------------------------- 1 | 2 | as the name says — predict_all_nokeys_rulelist • tidyrules 6 | 7 | 8 |
    9 |
    50 | 51 | 52 | 53 |
    54 |
    55 | 60 | 61 |
    62 |

    as the name says

    63 |
    64 | 65 |
    66 |
    predict_all_nokeys_rulelist(rulelist, new_data)
    67 |
    68 | 69 |
    70 |

    Arguments

    71 | 72 | 73 |
    rulelist
    74 |

    rulelist

    75 | 76 | 77 |
    new_data
    78 |

    new_data

    79 | 80 |
    81 |
    82 |

    Value

    83 |

    dataframe

    84 |
    85 | 86 |
    87 | 90 |
    91 | 92 | 93 |
    96 | 97 |
    98 |

    Site built with pkgdown 2.1.1.

    99 |
    100 | 101 |
    102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /docs/reference/predict_all_rulelist.html: -------------------------------------------------------------------------------- 1 | 2 | with or without keys — predict_all_rulelist • tidyrules 6 | 7 | 8 |
    9 |
    50 | 51 | 52 | 53 |
    54 |
    55 | 60 | 61 |
    62 |

    uses predict_all_nokeys_rulelist

    63 |
    64 | 65 |
    66 |
    predict_all_rulelist(rulelist, new_data)
    67 |
    68 | 69 |
    70 |

    Arguments

    71 | 72 | 73 |
    rulelist
    74 |

    rulelist

    75 | 76 | 77 |
    new_data
    78 |

    new_data

    79 | 80 |
    81 |
    82 |

    Value

    83 |

    dataframe

    84 |
    85 | 86 |
    87 | 90 |
    91 | 92 | 93 |
    96 | 97 |
    98 |

    Site built with pkgdown 2.1.1.

    99 |
    100 | 101 |
    102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | Authors and Citation • tidyrules 6 | 7 | 8 |
    9 |
    50 | 51 | 52 | 53 |
    54 |
    55 |
    56 | 59 | 60 | 61 |
    • 62 |

      Srikanth Komala Sheshachala. Author, maintainer. 63 |

      64 |
    • 65 |
    • 66 |

      Amith Kumar Ullur Raghavendra. Author. 67 |

      68 |
    • 69 |
    70 |
    71 |
    72 |

    Citation

    73 | Source: DESCRIPTION 74 |
    75 |
    76 | 77 | 78 |

    Komala Sheshachala S, Ullur Raghavendra A (2025). 79 | tidyrules: Utilities to Retrieve Rulelists from Model Fits, Filter, Prune, Reorder and Predict on Unseen Data. 80 | R package version 0.2.7, https://talegari.github.io/tidyrules/, https://github.com/talegari/tidyrules. 81 |

    82 |
    @Manual{,
     83 |   title = {tidyrules: Utilities to Retrieve Rulelists from Model Fits, Filter, Prune, Reorder and Predict on Unseen Data},
     84 |   author = {Srikanth {Komala Sheshachala} and Amith Kumar {Ullur Raghavendra}},
     85 |   year = {2025},
     86 |   note = {R package version 0.2.7, https://talegari.github.io/tidyrules/},
     87 |   url = {https://github.com/talegari/tidyrules},
     88 | }
    89 | 90 |
    91 | 92 |
    93 | 94 | 95 | 96 |
    99 | 100 |
    101 |

    Site built with pkgdown 2.1.1.

    102 |
    103 | 104 |
    105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /docs/reference/print.prune_rulelist.html: -------------------------------------------------------------------------------- 1 | 2 | Print method for prune_rulelist class — print.prune_rulelist • tidyrules 6 | 7 | 8 |
    9 |
    50 | 51 | 52 | 53 |
    54 |
    55 | 60 | 61 |
    62 |

    Print method for prune_rulelist class

    63 |
    64 | 65 |
    66 |
    # S3 method for class 'prune_rulelist'
     67 | print(x, ...)
    68 |
    69 | 70 |
    71 |

    Arguments

    72 | 73 | 74 |
    x
    75 |

    A 'prune_rulelist' object

    76 | 77 | 78 |
    ...
    79 |

    unused

    80 | 81 |
    82 | 83 |
    84 | 87 |
    88 | 89 | 90 |
    93 | 94 |
    95 |

    Site built with pkgdown 2.1.1.

    96 |
    97 | 98 |
    99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /docs/reference/plot.prune_rulelist.html: -------------------------------------------------------------------------------- 1 | 2 | Plot method for prune_rulelist class — plot.prune_rulelist • tidyrules 6 | 7 | 8 |
    9 |
    50 | 51 | 52 | 53 |
    54 |
    55 | 60 | 61 |
    62 |

    Plot method for prune_rulelist class

    63 |
    64 | 65 |
    66 |
    # S3 method for class 'prune_rulelist'
     67 | plot(x, ...)
    68 |
    69 | 70 |
    71 |

    Arguments

    72 | 73 | 74 |
    x
    75 |

    A 'prune_rulelist' object

    76 | 77 | 78 |
    ...
    79 |

    unused

    80 | 81 |
    82 |
    83 |

    Value

    84 |

    ggplot2 object (invisibly)

    85 |
    86 | 87 |
    88 | 91 |
    92 | 93 | 94 |
    97 | 98 |
    99 |

    Site built with pkgdown 2.1.1.

    100 |
    101 | 102 |
    103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /docs/reference/reorder.html: -------------------------------------------------------------------------------- 1 | 2 | reorder generic — reorder • tidyrules 6 | 7 | 8 |
    9 |
    50 | 51 | 52 | 53 |
    54 |
    55 | 60 | 61 |
    62 |

    reorder generic for rulelist

    63 |
    64 | 65 |
    66 |
    reorder(x, ...)
    67 |
    68 | 69 |
    70 |

    Arguments

    71 | 72 | 73 |
    x
    74 |

    A rulelist

    75 | 76 | 77 |
    ...
    78 |

    See reorder.rulelist

    79 | 80 |
    81 |
    82 |

    See also

    83 | 86 |
    87 | 88 |
    89 | 92 |
    93 | 94 | 95 |
    98 | 99 |
    100 |

    Site built with pkgdown 2.1.1.

    101 |
    102 | 103 |
    104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /docs/reference/ruleRToSQL.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Convert a R parsable rule to SQL parsable rule — ruleRToSQL • tidyrules 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 56 | 57 | 58 | 59 | 60 | 61 | 62 |
    63 |
    64 | 118 | 119 | 120 | 121 |
    122 | 123 |
    124 |
    125 | 130 | 131 |
    132 |

    Expected to be passed after SQL 'WHERE' clause

    133 |
    134 | 135 |
    ruleRToSQL(rule)
    136 | 137 |

    Arguments

    138 | 139 | 140 | 141 | 142 | 143 | 144 |
    rule

    (chr vector) R parsable rule(s)

    145 | 146 |

    Value

    147 | 148 |

    (chr vector) SQL parsable rule(s) as a 'WHERE' clause

    149 | 150 |
    151 | 156 |
    157 | 158 | 159 | 169 |
    170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | --------------------------------------------------------------------------------