{"id":50689536,"url":"https://github.com/tidymodels/lorax","last_synced_at":"2026-06-09T01:34:25.573Z","repository":{"id":344415859,"uuid":"1181738999","full_name":"tidymodels/lorax","owner":"tidymodels","description":"R functions and methods to extract elements of tree- and     rule-based models.","archived":false,"fork":false,"pushed_at":"2026-06-07T15:55:20.000Z","size":1496,"stargazers_count":3,"open_issues_count":7,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-06-09T01:34:20.839Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tidymodels.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-14T15:01:44.000Z","updated_at":"2026-05-29T22:39:37.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/tidymodels/lorax","commit_stats":null,"previous_names":["topepo/lorax","tidymodels/lorax"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tidymodels/lorax","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidymodels%2Florax","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidymodels%2Florax/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidymodels%2Florax/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidymodels%2Florax/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tidymodels","download_url":"https://codeload.github.com/tidymodels/lorax/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidymodels%2Florax/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34088013,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-08T02:00:07.615Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-09T01:34:21.401Z","updated_at":"2026-06-09T01:34:25.566Z","avatar_url":"https://github.com/tidymodels.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# lorax\n\n\u003c!-- badges: start --\u003e\n[![R-CMD-check](https://github.com/topepo/lorax/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/topepo/lorax/actions/workflows/R-CMD-check.yaml)\n[![Codecov test coverage](https://codecov.io/gh/topepo/lorax/graph/badge.svg)](https://app.codecov.io/gh/topepo/lorax)\n\u003c!-- badges: end --\u003e\n\nThe goal of lorax is to help look at different aspects of tree- and rule-based models. \n\nlorax supports a few APIs:\n\n - `as.party()` converts trees to the format used by `partykit::ctree()`, mostly because it has an amazing `plot()` method. \n - `extract_rules()` helps write out the logical paths to the terminal nodes. \n - `active_predictors()` enumerates which predictors were actually used in a split. \n - `var_imp()` is a wrapper for any importance method contained in the package. This is a wrapper that enables a common interface to the scores. \n \nHere is a list of which classes have which methods:\n\n```{r}\n#| echo: false\nlibrary(lorax)\n\nactive_predictors_mthd \u003c-\n tibble::tibble(\n  method = \"active_predictors\",\n  class = ls(pattern = \"^active_predictors\", envir = asNamespace(\"lorax\")) |\u003e\n   gsub(\"active_predictors\\\\.\", \"\", x = _)\n )\n\nextract_rules_mthd \u003c-\n tibble::tibble(\n  method = \"extract_rules\",\n  class = ls(pattern = \"^extract_rules\", envir = asNamespace(\"lorax\")) |\u003e\n   gsub(\"extract_rules\", \"\", x = _) |\u003e\n   gsub(\"^\\\\.\", \"\", x = _)\n )\n\nparty_mthd \u003c-\n tibble::tibble(\n  method = \"as.party\",\n  class = ls(pattern = \"^as.party\", envir = asNamespace(\"lorax\")) |\u003e\n   gsub(\"as.party\\\\.\", \"\", x = _)\n )\n\nimp_mthd \u003c-\n tibble::tibble(\n  method = \"var_imp\",\n  class = ls(pattern = \"^var_imp\", envir = asNamespace(\"lorax\")) |\u003e\n   gsub(\"var_imp\", \"\", x = _) |\u003e\n   gsub(\"^\\\\.\", \"\", x = _)\n )\n\ndplyr::bind_rows(\n imp_mthd,\n active_predictors_mthd,\n party_mthd,\n extract_rules_mthd\n) |\u003e\n dplyr::filter(method != class \u0026 !grepl(\"^new_\", class) \u0026 class != \"\") |\u003e\n dplyr::mutate(here = cli::symbol$tick) |\u003e\n tidyr::pivot_wider(\n  id_cols = class,\n  names_from = method,\n  values_from = here,\n  values_fill = cli::symbol$cross\n ) |\u003e\n dplyr::arrange(tolower(class)) |\u003e\n dplyr::mutate(\n  as.party = ifelse(class %in% c(\"rpart\", \"cforest\", \"party\"), \"n/a\", as.party),\n  var_imp = ifelse(class %in% c(\"bart\", \"C5.0\"), \"n/a\", var_imp)\n ) |\u003e \n knitr::kable()\n```\n\nNote that `as.party.rpart()` is in the partykit package and that cforest is made out of party objects.  \n\n## Installation\n\nYou can install the development version of lorax like so:\n\n``` r\nrequire(pak)\npak::pak(\"topepo/lorax\")\n```\n\n## Example\n\n\n```{r}\n#| label: startup\n#| include: false\nlibrary(lorax)\nlibrary(tibble)\nlibrary(ranger)\nlibrary(palmerpenguins)\n```\n\n```{r}\n#| label: ranger-ex\n#| results: hide\nset.seed(822)\nrngr_fit \u003c- ranger(species ~ ., data = penguins, max.depth = 3, num.trees = 10)\n```\n\n\n```{r}\n#| label: ranger-party\nrngr_party \u003c- as.party(rngr_fit, data = penguins, tree = 1)\nrngr_party\n\nplot(rngr_party)\n```\n\n```{r}\n#| label: ranger-rules\nall_rules \u003c- extract_rules(rngr_party, trees = 10)\n\n# An expression\nall_rules$rules[[1]]\n\n# Text\nall_rules$rules[[1]] |\u003e rule_text()\n\n# Substitutions\nnew_names \u003c- \n tribble(\n  ~ original, ~ label,\n  \"flipper_length_mm\", \"Flipper Length\",\n  \"body_mass_g\", \"Body Mass\"\n )\n \nall_rules$rules[[1]] |\u003e rule_text(key = new_names)\n\n# Bullets:\nall_rules$rules[[1]] |\u003e \n rule_text(key = new_names, bullets = TRUE) |\u003e \n cat()\n```\n\n## Code of Conduct\n  \nPlease note that the lorax project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftidymodels%2Florax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftidymodels%2Florax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftidymodels%2Florax/lists"}