├── .Rbuildignore ├── .github ├── .gitignore └── workflows │ ├── R-CMD-check.yaml │ ├── pkgdown.yaml │ ├── pr-commands.yaml │ └── test-coverage.yaml ├── .gitignore ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── NEWS.md ├── R ├── aspect_importance.R ├── aspect_importance_single.R ├── group_variables.R ├── hierarchical_importance.R └── triplot.R ├── README.md ├── README.rmd ├── README_files ├── figure-gfm │ ├── unnamed-chunk-3-1.png │ ├── unnamed-chunk-4-1.png │ ├── unnamed-chunk-5-1.png │ ├── unnamed-chunk-6-1.png │ └── unnamed-chunk-7-1.png └── triplot_explained.gif ├── _pkgdown.yml ├── codecov.yml ├── docs ├── 404.html ├── LICENSE-text.html ├── MI2logo.jpg ├── apple-touch-icon-120x120.png ├── apple-touch-icon-152x152.png ├── apple-touch-icon-180x180.png ├── apple-touch-icon-60x60.png ├── apple-touch-icon-76x76.png ├── apple-touch-icon.png ├── articles │ ├── index.html │ ├── vignette_aspect_importance.html │ ├── vignette_aspect_importance_description.html │ ├── vignette_aspect_importance_description_files │ │ └── figure-html │ │ │ ├── aspect importance with automated aspects-1.png │ │ │ ├── aspect importance with manual aspects-1.png │ │ │ ├── triplot-1.png │ │ │ └── triplot-2.png │ ├── vignette_aspect_importance_fifa.html │ ├── vignette_aspect_importance_fifa_files │ │ └── figure-html │ │ │ ├── check model parts-1.png │ │ │ ├── predict_aspects #1-1.png │ │ │ ├── predict_aspects #2-1.png │ │ │ ├── predict_aspects #3-1.png │ │ │ ├── triplot for the whole model-1.png │ │ │ ├── unnamed-chunk-1-1.png │ │ │ ├── unnamed-chunk-10-1.png │ │ │ ├── unnamed-chunk-11-1.png │ │ │ ├── unnamed-chunk-4-1.png │ │ │ ├── unnamed-chunk-4-2.png │ │ │ ├── unnamed-chunk-4-3.png │ │ │ ├── unnamed-chunk-4-4.png │ │ │ ├── unnamed-chunk-5-1.png │ │ │ ├── unnamed-chunk-6-1.png │ │ │ ├── unnamed-chunk-6-2.png │ │ │ ├── unnamed-chunk-6-3.png │ │ │ ├── unnamed-chunk-7-1.png │ │ │ ├── unnamed-chunk-7-2.png │ │ │ ├── unnamed-chunk-8-1.png │ │ │ └── unnamed-chunk-9-1.png │ ├── vignette_aspect_importance_files │ │ └── figure-html │ │ │ ├── Calculating aspect importance (logistic regression)-1.png │ │ │ ├── Calculating aspect importance (random forest)-1.png │ │ │ └── unnamed-chunk-2-1.png │ ├── vignette_aspect_importance_indepth.html │ └── vignette_aspect_importance_indepth_files │ │ └── figure-html │ │ ├── aspect importance with automated aspects-1.png │ │ ├── aspect importance with manual aspects-1.png │ │ ├── triplot-1.png │ │ └── triplot-2.png ├── authors.html ├── bootstrap-toc.css ├── bootstrap-toc.js ├── dalexverse-2.css ├── dalexverse.css ├── docsearch.css ├── docsearch.js ├── drwhy_znak_violet.jpg ├── drwhy_znak_violet_small.jpg ├── drwhylogo.jpg ├── favicon-16x16.png ├── favicon-32x32.png ├── favicon.ico ├── index.html ├── jquery.sticky-kit.min.js ├── link.svg ├── logo.png ├── news │ └── index.html ├── pkgdown.css ├── pkgdown.js ├── pkgdown.yml ├── reference │ ├── aspect_importance.html │ ├── aspect_importance_single.html │ ├── calculate_triplot-1.png │ ├── calculate_triplot.html │ ├── cluster_variables.html │ ├── figures │ │ ├── aspect-importance-1.png │ │ ├── logo.png │ │ ├── model-triplot-1.png │ │ ├── predict-triplot-1.png │ │ ├── unnamed-chunk-4-1.png │ │ ├── unnamed-chunk-5-1.png │ │ ├── unnamed-chunk-6-1.png │ │ ├── unnamed-chunk-7-1.png │ │ ├── unnamed-chunk-8-1.png │ │ └── unnamed-chunk-9-1.png │ ├── get_sample.html │ ├── group_variables.html │ ├── hierarchical_importance-1.png │ ├── hierarchical_importance.html │ ├── index.html │ ├── list_variables.html │ ├── plot.aspect_importance-1.png │ ├── plot.aspect_importance.html │ ├── plot.cluster_variables-1.png │ ├── plot.cluster_variables.html │ ├── plot.triplot-1.png │ ├── plot.triplot.html │ ├── plot_aspects_importance_grouping-1.png │ ├── plot_aspects_importance_grouping.html │ ├── plot_group_variables-1.png │ ├── plot_group_variables.html │ ├── print.aspect_importance.html │ ├── triplot-1.png │ ├── triplot-2.png │ ├── triplot-3.png │ ├── triplot-4.png │ └── triplot.html └── tocBullet.svg ├── man ├── aspect_importance.Rd ├── aspect_importance_single.Rd ├── calculate_triplot.Rd ├── cluster_variables.Rd ├── figures │ ├── aspect-importance-1.png │ ├── logo.png │ ├── model-triplot-1.png │ └── predict-triplot-1.png ├── get_sample.Rd ├── group_variables.Rd ├── hierarchical_importance.Rd ├── list_variables.Rd ├── plot.aspect_importance.Rd ├── plot.cluster_variables.Rd ├── plot.triplot.Rd └── print.aspect_importance.Rd ├── misc ├── cheatsheet_code.R ├── medium_example.R ├── medium_example_part2.R └── triplot_cheatsheet.pdf ├── pkgdown └── favicon │ ├── apple-touch-icon-120x120.png │ ├── apple-touch-icon-152x152.png │ ├── apple-touch-icon-180x180.png │ ├── apple-touch-icon-60x60.png │ ├── apple-touch-icon-76x76.png │ ├── apple-touch-icon.png │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ └── favicon.ico ├── tests ├── testthat.R └── testthat │ ├── helper-objects.R │ ├── test_aspect_importance.R │ ├── test_aspect_importance_single.R │ ├── test_group_variables.R │ ├── test_hierarchical_importance.R │ └── test_triplot.R └── vignettes ├── vignette_aspect_importance.Rmd ├── vignette_aspect_importance_fifa.Rmd └── vignette_aspect_importance_indepth.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^README.md$ 4 | ^\.travis\.yml$ 5 | ^codecov\.yml$ 6 | ^_pkgdown\.yml$ 7 | ^docs$ 8 | ^pkgdown$ 9 | ^doc$ 10 | ^Meta$ 11 | ^\.github$ 12 | README_files 13 | README.rmd 14 | vignettes/ 15 | ^cran-comments\.md$ 16 | LICENSE 17 | ^CRAN-RELEASE$ 18 | ^misc$ -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - master 5 | paths: 6 | - '**.R' 7 | - '*DESCRIPTION' 8 | - '**.Rmd' 9 | pull_request: 10 | branches: 11 | - master 12 | 13 | name: R-CMD-check 14 | 15 | jobs: 16 | R-CMD-check: 17 | runs-on: ${{ matrix.config.os }} 18 | 19 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 20 | 21 | strategy: 22 | fail-fast: false 23 | matrix: 24 | config: 25 | # - {os: macOS-latest, r: 'devel'} 26 | - {os: macOS-latest, r: '4.0'} 27 | - {os: windows-latest, r: 'devel'} 28 | - {os: windows-latest, r: '4.0'} 29 | - {os: windows-latest, r: '3.6'} 30 | - {os: ubuntu-16.04, r: '4.0', rspm: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"} 31 | - {os: ubuntu-16.04, r: '3.6', rspm: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"} 32 | 33 | env: 34 | R_REMOTES_NO_ERRORS_FROM_WARNINGS: true 35 | RSPM: ${{ matrix.config.rspm }} 36 | 37 | steps: 38 | - uses: actions/checkout@v2 39 | 40 | - uses: r-lib/actions/setup-r@master 41 | with: 42 | r-version: ${{ matrix.config.r }} 43 | 44 | - uses: r-lib/actions/setup-pandoc@master 45 | 46 | - name: Query dependencies 47 | run: | 48 | install.packages('remotes') 49 | saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) 50 | shell: Rscript {0} 51 | 52 | - name: Cache R packages 53 | if: runner.os != 'Windows' 54 | uses: actions/cache@v1 55 | with: 56 | path: ${{ env.R_LIBS_USER }} 57 | key: ${{ runner.os }}-r-${{ matrix.config.r }}-${{ hashFiles('.github/depends.Rds') }} 58 | restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}- 59 | 60 | - name: Install system dependencies 61 | if: runner.os == 'Linux' 62 | env: 63 | RHUB_PLATFORM: linux-x86_64-ubuntu-gcc 64 | run: | 65 | Rscript -e "remotes::install_github('r-hub/sysreqs')" 66 | sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))") 67 | sudo -s eval "$sysreqs" 68 | sudo apt-get install -y qpdf 69 | 70 | - name: Install dependencies 71 | run: | 72 | remotes::install_deps(dependencies = TRUE) 73 | remotes::install_cran("rcmdcheck") 74 | shell: Rscript {0} 75 | 76 | - name: Check 77 | run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran", "--run-donttest", "--run-dontrun"), 78 | build_args = "--compact-vignettes=no", error_on = "warning", check_dir = "check") 79 | shell: Rscript {0} 80 | 81 | - name: Upload check results 82 | if: failure() 83 | uses: actions/upload-artifact@master 84 | with: 85 | name: ${{ runner.os }}-r${{ matrix.config.r }}-results 86 | path: check 87 | -------------------------------------------------------------------------------- /.github/workflows/pkgdown.yaml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: master 4 | 5 | name: pkgdown 6 | 7 | jobs: 8 | pkgdown: 9 | runs-on: macOS-latest 10 | steps: 11 | - uses: actions/checkout@v2 12 | 13 | - uses: r-lib/actions/setup-r@master 14 | 15 | - uses: r-lib/actions/setup-pandoc@master 16 | 17 | - name: Query dependencies 18 | run: | 19 | install.packages('remotes') 20 | saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) 21 | shell: Rscript {0} 22 | 23 | - name: Cache R packages 24 | uses: actions/cache@v1 25 | with: 26 | path: ${{ env.R_LIBS_USER }} 27 | key: macOS-r-4.0-1-${{ hashFiles('.github/depends.Rds') }} 28 | restore-keys: macOS-r-4.0-1- 29 | 30 | - name: Install dependencies 31 | run: | 32 | install.packages("remotes") 33 | remotes::install_deps(dependencies = TRUE) 34 | remotes::install_dev("pkgdown") 35 | remotes::install_github("ModelOriented/DrWhyTemplate") 36 | shell: Rscript {0} 37 | 38 | - name: Install package 39 | run: R CMD INSTALL . 40 | 41 | - name: Deploy package 42 | run: pkgdown::deploy_to_branch(new_process = FALSE, examples = FALSE, clean = TRUE) 43 | shell: Rscript {0} 44 | -------------------------------------------------------------------------------- /.github/workflows/pr-commands.yaml: -------------------------------------------------------------------------------- 1 | on: 2 | issue_comment: 3 | types: [created] 4 | name: Commands 5 | jobs: 6 | document: 7 | if: startsWith(github.event.comment.body, '/document') 8 | name: document 9 | runs-on: macOS-latest 10 | steps: 11 | - uses: actions/checkout@v2 12 | - uses: r-lib/actions/pr-fetch@master 13 | with: 14 | repo-token: ${{ secrets.GITHUB_TOKEN }} 15 | - uses: r-lib/actions/setup-r@master 16 | - name: Install dependencies 17 | run: Rscript -e 'install.packages(c("remotes", "roxygen2"))' -e 'remotes::install_deps(dependencies = TRUE)' 18 | - name: Document 19 | run: Rscript -e 'roxygen2::roxygenise()' 20 | - name: commit 21 | run: | 22 | git add man/\* NAMESPACE 23 | git commit -m 'Document' 24 | - uses: r-lib/actions/pr-push@master 25 | with: 26 | repo-token: ${{ secrets.GITHUB_TOKEN }} 27 | style: 28 | if: startsWith(github.event.comment.body, '/style') 29 | name: style 30 | runs-on: macOS-latest 31 | steps: 32 | - uses: actions/checkout@v2 33 | - uses: r-lib/actions/pr-fetch@master 34 | with: 35 | repo-token: ${{ secrets.GITHUB_TOKEN }} 36 | - uses: r-lib/actions/setup-r@master 37 | - name: Install dependencies 38 | run: Rscript -e 'install.packages("styler")' 39 | - name: Style 40 | run: Rscript -e 'styler::style_pkg()' 41 | - name: commit 42 | run: | 43 | git add \*.R 44 | git commit -m 'Style' 45 | - uses: r-lib/actions/pr-push@master 46 | with: 47 | repo-token: ${{ secrets.GITHUB_TOKEN }} 48 | # A mock job just to ensure we have a successful build status 49 | finish: 50 | runs-on: ubuntu-latest 51 | steps: 52 | - run: true 53 | -------------------------------------------------------------------------------- /.github/workflows/test-coverage.yaml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - master 5 | pull_request: 6 | branches: 7 | - master 8 | 9 | name: test-coverage 10 | 11 | jobs: 12 | test-coverage: 13 | runs-on: macOS-latest 14 | steps: 15 | - uses: actions/checkout@v2 16 | 17 | - uses: r-lib/actions/setup-r@master 18 | 19 | - uses: r-lib/actions/setup-pandoc@master 20 | 21 | - name: Query dependencies 22 | run: | 23 | install.packages('remotes') 24 | saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) 25 | shell: Rscript {0} 26 | 27 | - name: Cache R packages 28 | uses: actions/cache@v1 29 | with: 30 | path: ${{ env.R_LIBS_USER }} 31 | key: macOS-r-4.0-1-${{ hashFiles('.github/depends.Rds') }} 32 | restore-keys: macOS-r-4.0-1- 33 | 34 | - name: Install dependencies 35 | run: | 36 | install.packages(c("remotes")) 37 | remotes::install_deps(dependencies = TRUE) 38 | remotes::install_cran("covr") 39 | shell: Rscript {0} 40 | 41 | - name: Test coverage 42 | run: covr::codecov() 43 | shell: Rscript {0} 44 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | triplot.Rproj 6 | doc 7 | Meta 8 | 9 | #vignettes 10 | vignettes/*.html 11 | vignettes/*.R 12 | vignettes/*.md 13 | 14 | # CRAN 15 | CRAN-RELEASE 16 | cran-comments.md 17 | 18 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: triplot 2 | Title: Explaining Correlated Features in Machine Learning Models 3 | Version: 1.3.1 4 | Authors@R: 5 | c(person("Katarzyna", "Pekala", email = "katarzyna.pekala@gmail.com", 6 | role = c("aut", "cre")), 7 | person("Przemyslaw", "Biecek", role = c("aut"), 8 | comment = c(ORCID = "0000-0001-8423-1823"))) 9 | Description: Tools for exploring effects of correlated features in predictive 10 | models. The predict_triplot() function delivers instance-level explanations 11 | that calculate the importance of the groups of explanatory variables. The 12 | model_triplot() function delivers data-level explanations. The generic plot 13 | function visualises in a concise way importance of hierarchical groups of 14 | predictors. All of the the tools are model agnostic, therefore works for any 15 | predictive machine learning models. Find more details in Biecek (2018) 16 | . 17 | Depends: R (>= 3.6) 18 | License: GPL-3 19 | Encoding: UTF-8 20 | LazyData: true 21 | RoxygenNote: 7.1.1 22 | Imports: 23 | ggplot2, 24 | DALEX (>= 1.3), 25 | glmnet, 26 | ggdendro, 27 | patchwork 28 | Suggests: 29 | testthat, 30 | knitr, 31 | randomForest, 32 | mlbench, 33 | ranger, 34 | gbm, 35 | covr 36 | URL: https://github.com/ModelOriented/triplot 37 | BugReports: https://github.com/ModelOriented/triplot/issues 38 | Language: en-US 39 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(aspect_importance,default) 4 | S3method(aspect_importance,explainer) 5 | S3method(aspect_importance_single,default) 6 | S3method(aspect_importance_single,explainer) 7 | S3method(calculate_triplot,default) 8 | S3method(calculate_triplot,explainer) 9 | S3method(cluster_variables,default) 10 | S3method(plot,aspect_importance) 11 | S3method(plot,cluster_variables) 12 | S3method(plot,hierarchical_importance) 13 | S3method(plot,triplot) 14 | S3method(print,aspect_importance) 15 | S3method(print,triplot) 16 | export(aspect_importance) 17 | export(aspect_importance_single) 18 | export(calculate_triplot) 19 | export(cluster_variables) 20 | export(get_sample) 21 | export(group_variables) 22 | export(hierarchical_importance) 23 | export(lime) 24 | export(list_variables) 25 | export(model_triplot) 26 | export(predict_aspects) 27 | export(predict_triplot) 28 | import(ggplot2) 29 | import(patchwork) 30 | import(stats) 31 | importFrom(DALEX,colors_discrete_drwhy) 32 | importFrom(DALEX,explain) 33 | importFrom(DALEX,feature_importance) 34 | importFrom(DALEX,theme_drwhy) 35 | importFrom(DALEX,theme_drwhy_vertical) 36 | importFrom(ggdendro,dendro_data) 37 | importFrom(ggdendro,label) 38 | importFrom(ggdendro,segment) 39 | importFrom(ggplot2,.pt) 40 | importFrom(glmnet,glmnet) 41 | importFrom(graphics,plot) 42 | importFrom(stats,coef) 43 | importFrom(stats,cor) 44 | importFrom(stats,cutree) 45 | importFrom(stats,hclust) 46 | importFrom(stats,lm) 47 | importFrom(stats,model.matrix) 48 | importFrom(stats,rbinom) 49 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # triplot 1.3.1 2 | 3 | * extended documentation (cheatsheet) 4 | 5 | # triplot 1.3 6 | 7 | * changed the way plot(model_triplot) is build, so it works correctly with 8 | patchwork 1.0.1 9 | * changed parameter in DALEX::feature_importance call from n_sample to N (due 10 | to change in DALEX 1.2.1) 11 | * added parameter to change correlation method in group_variables, 12 | cluster_variables, triplot 13 | * deprecated aspects_on_axis argument in plot.aspect_importance (now it’s 14 | show_features) (#14) 15 | 16 | # triplot 1.2 17 | 18 | * last vertical line in hierarchical_importance() plot of model_triplot() shows 19 | baseline value 20 | * left margin of middle panel in triplot can be set with "margin_mid" 21 | * colors in plot for predict_aspects() changed to match DALEX::colors_discrete_drwhy() 22 | * changed order or n_var and sample_method parameters in aspect_importance() functions 23 | * renamed triplot title to Global / Local triplot 24 | 25 | 26 | # triplot 1.1.2 27 | 28 | * modified triplot object and methods 29 | * removed ingredients dependency 30 | 31 | # triplot 1.1.1 32 | 33 | * switched from GridExtra to Patchwork 34 | * improved plotting of triplot object 35 | 36 | # triplot 1.1.0 37 | 38 | * renamed prediction_aspect() to predict_aspects() 39 | * added aliases predict_triplot() and model_triplot() 40 | * added bar_width param to triplot 41 | * added warning if target is in data 42 | * added parameter "type" to calculate_triplot() 43 | * added print for predict_aspects() and triplot() 44 | 45 | # triplot 1.0.4 46 | 47 | * restructured group_variables() and triplot objects 48 | * added hierarchical_importance object (instead of 49 | plot_aspects_importance_grouping) 50 | * triplot renamed to calculate_triplot() 51 | * triplot is plotted by calling plot on calculate_triplot() results 52 | 53 | # triplot 1.0.3 54 | 55 | * updated plot_aspects_importance_grouping so it can draw last clusters 56 | connection 57 | * add_importance_labels parameter set to FALSE by default 58 | 59 | 60 | # triplot 1.0.2 61 | 62 | * new feature: triplot can present both: automatic aspect and feature importance 63 | grouping (by using ingredients::feature_importance()) 64 | 65 | 66 | # triplot 1.0.1 67 | 68 | * aspectImportance is renamed to triplot 69 | * added second vignette 70 | 71 | 72 | # aspectImportance 1.0 73 | 74 | * aspect_importance is moved out of `DALEXtra` into standalone package 75 | -------------------------------------------------------------------------------- /R/aspect_importance_single.R: -------------------------------------------------------------------------------- 1 | #' Aspects importance for single aspects 2 | #' 3 | #' Calculates aspect_importance for single aspects (every aspect contains only 4 | #' one feature). 5 | #' 6 | #' @param x an explainer created with the \code{DALEX::explain()} function 7 | #' or a model to be explained. 8 | #' @param data dataset, it will be extracted from \code{x} if it's an explainer 9 | #' NOTE: Target variable shouldn't be present in the \code{data} 10 | #' @param predict_function predict function, it will be extracted from \code{x} 11 | #' if it's an explainer 12 | #' @param label name of the model. By default it's extracted from the 'class' 13 | #' attribute of the model. 14 | #' @param new_observation selected observation with columns that corresponds to 15 | #' variables used in the model, should be without target variable 16 | #' @param N number of observations to be sampled (with replacement) from data 17 | #' NOTE: Small \code{N} may cause unstable results. 18 | #' @param n_var how many non-zero coefficients for lasso fitting, if zero than 19 | #' linear regression is used 20 | #' @param sample_method sampling method in \code{\link{get_sample}} 21 | #' @param f frequency in in \code{\link{get_sample}} 22 | #' @param ... other parameters 23 | #' 24 | #' @return An object of the class 'aspect_importance'. Contains dataframe that 25 | #' describes aspects' importance. 26 | #' 27 | #' @examples 28 | #' library("DALEX") 29 | #' model_titanic_glm <- glm(survived == 1 ~ class + gender + age + 30 | #' sibsp + parch + fare + embarked, 31 | #' data = titanic_imputed, 32 | #' family = "binomial") 33 | #' 34 | #' explainer_titanic <- explain(model_titanic_glm, 35 | #' data = titanic_imputed[,-8], 36 | #' verbose = FALSE) 37 | #' aspect_importance_single(explainer_titanic, 38 | #' new_observation = titanic_imputed[1,-8]) 39 | #' 40 | #' @export 41 | 42 | aspect_importance_single <- function(x, ...) 43 | UseMethod("aspect_importance_single") 44 | 45 | #' @export 46 | #' @rdname aspect_importance_single 47 | 48 | aspect_importance_single.explainer <- function(x, new_observation, 49 | N = 1000, 50 | n_var = 0, 51 | sample_method = "default", 52 | f = 2, 53 | ...) { 54 | 55 | # extracts model, data and predict function from the explainer ------------ 56 | 57 | model <- x$model 58 | data <- x$data 59 | predict_function <- x$predict_function 60 | label <- x$label 61 | 62 | 63 | # calls aspect_importance_single function --------------------------------- 64 | 65 | aspect_importance_single.default(x = model, 66 | data = data, 67 | predict_function = predict_function, 68 | new_observation = new_observation, 69 | N = N, 70 | label = label, 71 | n_var = n_var, 72 | sample_method = sample_method, 73 | f = f) 74 | } 75 | 76 | #' @export 77 | #' @rdname aspect_importance_single 78 | 79 | aspect_importance_single.default <- function(x, data, 80 | predict_function = predict, 81 | label = class(x)[1], 82 | new_observation, 83 | N = 1000, 84 | n_var = 0, 85 | sample_method = "default", 86 | f = 2, ...) { 87 | 88 | 89 | # creates list of single aspects ------------------------------------------ 90 | 91 | single_aspect_list <- vector("list", length(colnames(data))) 92 | names(single_aspect_list) <- colnames(data) 93 | 94 | for (i in seq_along(single_aspect_list)) { 95 | single_aspect_list[i] <- colnames(data)[i] 96 | } 97 | 98 | # calls aspect importance function ---------------------------------------- 99 | 100 | res_ai <- aspect_importance(x = x, 101 | data = data, 102 | predict_function = predict_function, 103 | new_observation = new_observation, 104 | variable_groups = single_aspect_list, 105 | N = N, 106 | label = label, 107 | sample_method = sample_method, 108 | n_var = n_var, 109 | f = f) 110 | 111 | # creates data frame with results ------------------------------------------ 112 | 113 | res_ai[, 3] <- as.character(res_ai[, 1]) 114 | for (i in c(1:dim(res_ai)[1])) { 115 | tmp_val <- new_observation[as.character(res_ai[i, 1])] 116 | if (is.numeric(tmp_val[1, 1])) { 117 | tmp_val <- round(tmp_val[1, 1], digits = 2) 118 | } else { 119 | tmp_val <- as.character(tmp_val[1, 1]) 120 | } 121 | res_ai[i, 3] <- paste0(res_ai[i, 1], " = ", tmp_val) 122 | } 123 | colnames(res_ai)[3] <- "new observation" 124 | 125 | return(res_ai) 126 | } 127 | -------------------------------------------------------------------------------- /R/group_variables.R: -------------------------------------------------------------------------------- 1 | #' Creates a cluster tree from numeric features 2 | #' 3 | #' Creates a cluster tree from numeric features and their correlations. 4 | #' 5 | #' @param x dataframe with only numeric columns 6 | #' @param clust_method the agglomeration method to be used 7 | #' see \code{\link[stats]{hclust}} methods 8 | #' @param cor_method the correlation method to be used 9 | #' see \code{\link[stats]{cor}} methods 10 | #' 11 | #' @return an hclust object 12 | #' 13 | #' @importFrom stats hclust 14 | #' @importFrom stats cor 15 | #' @importFrom graphics plot 16 | #' @param ... other parameters 17 | #' 18 | #' @examples 19 | #' library("DALEX") 20 | #' dragons_data <- dragons[,c(2,3,4,7,8)] 21 | #' cluster_variables(dragons_data, clust_method = "complete") 22 | #' 23 | #' @export 24 | 25 | cluster_variables <- function(x, ...) 26 | UseMethod("cluster_variables") 27 | 28 | #' @export 29 | #' @rdname cluster_variables 30 | 31 | cluster_variables.default <- function(x, clust_method = "complete", 32 | cor_method = "spearman", ...) { 33 | 34 | stopifnot(all(sapply(x, is.numeric))) 35 | 36 | # build clustering tree --------------------------------------------------- 37 | 38 | x_hc <- hclust(as.dist(1 - abs(cor(x, method = cor_method))), 39 | method = clust_method) 40 | 41 | class(x_hc) <- c("cluster_variables", "hclust") 42 | return(x_hc) 43 | } 44 | 45 | 46 | #' Plots tree with correlation values 47 | #' 48 | #' Plots tree that illustrates the results of cluster_variables function. 49 | #' 50 | #' @param x \code{cluster_variables} or \code{hclust} object 51 | #' @param p correlation value for cutoff level, if not NULL, cutoff line will 52 | #' be drawn 53 | #' @param show_labels if TRUE, plot will have annotated axis Y 54 | #' @param axis_lab_size size of labels on axis Y, if applicable 55 | #' @param text_size size of labels annotating values of correlations 56 | #' @param ... other parameters 57 | #' 58 | #' @return plot 59 | #' 60 | #' @importFrom stats hclust 61 | #' @importFrom ggdendro dendro_data 62 | #' @importFrom ggdendro segment 63 | #' @importFrom ggdendro label 64 | #' @importFrom ggplot2 .pt 65 | #' @importFrom DALEX theme_drwhy 66 | #' 67 | #' @examples 68 | #' library("DALEX") 69 | #' dragons_data <- dragons[,c(2,3,4,7,8)] 70 | #' cv <- cluster_variables(dragons_data, clust_method = "complete") 71 | #' plot(cv, p = 0.7) 72 | #' 73 | #' @export 74 | 75 | plot.cluster_variables <- function(x, 76 | p = NULL, 77 | show_labels = TRUE, 78 | axis_lab_size = 10, 79 | text_size = 3, ...) { 80 | stopifnot(p >= 0, p <= 1) 81 | stopifnot("hclust" %in% class(x)) 82 | 83 | y <- xend <- yend <- h <- NULL 84 | 85 | # convert tree to dendogram ----------------------------------------------- 86 | 87 | dhc <- as.dendrogram(x) 88 | ddata <- dendro_data(dhc, type = "rectangle") 89 | 90 | # get correlation values -------------------------------------------------- 91 | 92 | xy_horizon <- ddata$segments[ddata$segments$x == ddata$segments$xend, ] 93 | additional_x <- mean(xy_horizon[xy_horizon$y == max(xy_horizon$y), ]$x) 94 | additional_y <- max(xy_horizon$y) 95 | last_cor_value <- data.frame("x" = additional_x, "yend" = additional_y) 96 | xy <- xy_horizon[xy_horizon$yend != 0, ][, c(1, 4)] 97 | xy <- rbind(xy, last_cor_value) 98 | xy <- cbind(xy, 1 - xy[, 2]) 99 | colnames(xy) <- c("x", "y", "h") 100 | 101 | 102 | # build plot -------------------------------------------------------------- 103 | 104 | cor_plot <- ggplot(segment(ddata)) + 105 | geom_segment(aes(x = x, y = y, xend = xend, yend = yend)) + 106 | geom_text(data = xy, aes(x = x, y = y, label = round(h, digits = 2)), 107 | hjust = 1.3, size = text_size) + 108 | coord_flip() + 109 | scale_y_continuous(expand = c(0.3, 0.3)) + 110 | theme(axis.line.y = element_blank(), 111 | axis.ticks.y = element_blank(), 112 | axis.text.y = element_blank(), 113 | axis.title.y = element_blank(), 114 | axis.text.x = element_text(colour = "white"), 115 | axis.ticks.x = element_blank(), 116 | axis.title.x = theme_drwhy()$axis.title, 117 | panel.background = element_rect(fill = "white"), 118 | panel.grid = element_blank()) + 119 | labs(y = "Hierarchical clustering") 120 | 121 | if (show_labels) { 122 | cor_plot <- cor_plot + 123 | geom_text(aes(x = x, y = y, label = label, hjust = 1), 124 | data = label(ddata), nudge_y = -0.01, 125 | size = axis_lab_size / .pt, 126 | colour = theme_drwhy()$axis.title$colour) 127 | } 128 | 129 | # add line that shows correlation cut off level --------------------------- 130 | 131 | if (!is.null(p)) { 132 | cor_plot <- cor_plot + geom_hline(yintercept = 1 - p, linetype = "dashed") 133 | } 134 | 135 | attr(cor_plot, "order") <- x$order 136 | attr(cor_plot, "labels") <- x$labels 137 | 138 | return(cor_plot) 139 | } 140 | 141 | 142 | #' Cuts tree at custom height and returns a list 143 | #' 144 | #' This function creates aspect list after cutting a cluster tree of features 145 | #' at a given height. 146 | #' 147 | #' @param x hclust object 148 | #' @param h correlation value for tree cutting 149 | #' 150 | #' @return list of aspects 151 | #' 152 | #' @examples 153 | #' library("DALEX") 154 | #' dragons_data <- dragons[,c(2,3,4,7,8)] 155 | #' cv <- cluster_variables(dragons_data, clust_method = "complete") 156 | #' list_variables(cv, h = 0.5) 157 | #' 158 | #' @export 159 | #' @importFrom stats cutree 160 | 161 | 162 | list_variables <- function(x, h) { 163 | 164 | val <- NULL 165 | clust_list <- cutree(x, h = 1 - h) 166 | stopifnot(h >= 0, h <= 1) 167 | 168 | # prepare a list with aspects grouping ------------------------------------ 169 | 170 | df <- data.frame(names(clust_list), unname(clust_list)) 171 | colnames(df) <- c("name", "val") 172 | res <- vector("list", max(clust_list)) 173 | names(res) <- paste0("aspect.group", seq_along(res)) 174 | 175 | for (i in seq_along(res)) { 176 | res[i] <- list(as.character(subset(df, val == i)$name)) 177 | } 178 | 179 | return(res) 180 | } 181 | 182 | #' Helper function that combines clustering variables and creating aspect list 183 | #' 184 | #' Divides correlated features into groups, called aspects. Division is based on 185 | #' correlation cutoff level. 186 | #' 187 | #' 188 | #' @param x hclust object 189 | #' @param h correlation value for tree cutting 190 | #' @param clust_method the agglomeration method to be used 191 | #' see \code{\link[stats]{hclust}} methods 192 | #' @param cor_method the correlation method to be used 193 | #' see \code{\link[stats]{cor}} methods 194 | #' 195 | #' @examples 196 | #' library("DALEX") 197 | #' dragons_data <- dragons[,c(2,3,4,7,8)] 198 | #' group_variables(dragons_data, h = 0.5, clust_method = "complete") 199 | #' 200 | #' @return list with aspect 201 | #' @export 202 | 203 | 204 | group_variables <- function(x, h, clust_method = "complete", 205 | cor_method = "spearman") { 206 | 207 | # make a tree and prepare a list with aspects grouping -------------------- 208 | 209 | cv <- cluster_variables(x, clust_method = clust_method, 210 | cor_method = cor_method) 211 | res <- list_variables(cv, h) 212 | 213 | return(res) 214 | } 215 | -------------------------------------------------------------------------------- /README.rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | ```{r setup, include=FALSE, message=FALSE, warning=TRUE} 6 | knitr::opts_chunk$set( 7 | message = FALSE, 8 | warning = FALSE, 9 | fig.align = 'center', 10 | fig.path = "man/figures/") 11 | 12 | ``` 13 | 14 | # triplot 15 | 16 | 17 | [![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/triplot)](https://cran.r-project.org/package=triplot) 18 | [![R build status](https://github.com/ModelOriented/triplot/workflows/R-CMD-check/badge.svg)](https://github.com/ModelOriented/triplot/actions?query=workflow%3AR-CMD-check) 19 | [![Codecov test coverage](https://codecov.io/gh/ModelOriented/triplot/branch/master/graph/badge.svg)](https://codecov.io/gh/ModelOriented/triplot?branch=master) 20 | [![DrWhy-eXtrAI](https://img.shields.io/badge/DrWhy-eXtrAI-4378bf)](http://drwhy.ai/#eXtraAI) 21 | 22 | 23 | 24 | ## Introduction 25 | 26 | The `triplot` package provides tools for exploration of machine learning predictive models. It contains an instance-level explainer called `predict_aspects` (AKA `aspects_importance`), that is able to explain the contribution of the whole groups of explanatory variables. Furthermore, package delivers functionality called `triplot` - it illustrates how the importance of aspects (group of predictors) change depending on the size of aspects. 27 | 28 | Key functions: 29 | 30 | * `predict_triplot()` and `model_triplot()` for instance- and data-level summary of automatic aspect importance grouping, 31 | * `predict_aspects()` for calculating the feature groups importance (called aspects importance) for a selected observation, 32 | * `group_variables()` for grouping of correlated numeric features into aspects. 33 | 34 | The `triplot` package is a part of [DrWhy.AI](http://DrWhy.AI) universe. More information about analysis of machine learning models can be found in 35 | the [Explanatory Model Analysis. Explore, Explain and Examine Predictive Models](https://pbiecek.github.io/ema/) e-book. 36 | 37 | 38 |
39 | 40 | ![](https://raw.githubusercontent.com/ModelOriented/triplot/master/README_files/triplot_explained.gif) 41 | 42 |
43 | 44 | 45 | 46 | ## Installation 47 | 48 | ```{r eval = FALSE} 49 | # from CRAN: 50 | install.packages("triplot") 51 | 52 | # from GitHub (development version): 53 | # install.packages("devtools") 54 | devtools::install_github("ModelOriented/triplot") 55 | ``` 56 | 57 | 58 | ## Overview 59 | 60 | `triplot` shows, in one place: 61 | 62 | * the importance of every single feature, 63 | * hierarchical aspects importance, 64 | * order of grouping features into aspects. 65 | 66 | We can use it to investigate the **instance level** importance of features (using `predict_aspects()` function) or to illustrate the **model level** importance of features (using `model_parts()` function from DALEX package). `triplot` can be only used on numerical features. More information about this functionality can be found in [triplot overview](https://modeloriented.github.io/triplot/articles/vignette_aspect_importance.html#hierarchical-aspects-importance-1). 67 | 68 | ### Basic triplot for a model 69 | 70 | To showcase `triplot`, we will choose `apartments` dataset from DALEX, use it's numeric features to build a model, create DALEX [explainer](https://modeloriented.github.io/DALEX/reference/explain.html), use `model_triplot()` to calculate the `triplot` object and then plot it with the generic `plot()` function. 71 | 72 | #### Import `apartments` and train a linear model 73 | 74 | ```{r} 75 | library("DALEX") 76 | apartments_num <- apartments[,unlist(lapply(apartments, is.numeric))] 77 | 78 | model_apartments <- lm(m2.price ~ ., data = apartments_num) 79 | ``` 80 | 81 | #### Create an explainer 82 | 83 | ```{r} 84 | explain_apartments <- DALEX::explain(model = model_apartments, 85 | data = apartments_num[, -1], 86 | y = apartments_num$m2.price, 87 | verbose = FALSE) 88 | ``` 89 | 90 | #### Create a triplot object 91 | 92 | ```{r model-triplot, fig.width = 8, fig.height = 2.5, fig.cap="The left panel shows the global importance of individual variables. Right panel shows global correlation structure visualized by hierarchical clustering. The middle panel shows the importance of groups of variables determined by the hierarchical clustering."} 93 | set.seed(123) 94 | library("triplot") 95 | 96 | tri_apartments <- model_triplot(explain_apartments) 97 | 98 | plot(tri_apartments) + 99 | patchwork::plot_annotation(title = "Global triplot for four variables in the linear model") 100 | ``` 101 | 102 | At the model level, `surface` and `floor` have the biggest contributions. But we also know that `Number of rooms` and `surface` are strongly correlated and together have strong influence on the model prediction.`Construction year` has small influence on the prediction, is not correlated with `number of rooms` nor `surface` variables. Adding `construction year` to them, only slightly increases the importance of this group. 103 | 104 | ### Basic triplot for an observation 105 | 106 | Afterwards, we are building triplot for single instance and it's prediction. 107 | 108 | ```{r predict-triplot, fig.width = 8, fig.height = 2.5, fig.cap="The left panel shows the local importance of individual variables (similar to LIME). Right panel shows global correlation structure visualized by hierarchical clustering. The middle panel shows the local importance of groups of variables (similar to LIME) determined by the hierarchical clustering."} 109 | (new_apartment <- apartments_num[6, -1]) 110 | 111 | tri_apartments <- predict_triplot(explain_apartments, 112 | new_observation = new_apartment) 113 | 114 | plot(tri_apartments) + 115 | patchwork::plot_annotation(title = "Local triplot for four variables in the linear model") 116 | ``` 117 | 118 | We can observe that for the given apartment `surface` has also significant, positive influence on the prediction. Adding `number of rooms`, increases its contribution. However, adding `construction year` to those two features, decreases the group importance. 119 | 120 | We can notice that `floor` has the small influence on the prediction of this observation, unlike in the model-level analysis. 121 | 122 | 123 | ## Aspect importance for single instance 124 | 125 | For this example we use `titanic` dataset with a logistic regression model that predicts passenger survival. Features are combined into thematic aspects. 126 | 127 | ### Importing dataset and building a logistic regression model 128 | 129 | ```{r} 130 | set.seed(123) 131 | 132 | model_titanic_glm <- glm(survived ~ ., titanic_imputed, family = "binomial") 133 | ``` 134 | 135 | ### Manual selection of aspects 136 | 137 | ```{r} 138 | aspects_titanic <- 139 | list( 140 | wealth = c("class", "fare"), 141 | family = c("sibsp", "parch"), 142 | personal = c("age", "gender"), 143 | embarked = "embarked" 144 | ) 145 | ``` 146 | 147 | ### Select an instance 148 | 149 | We are interested in explaining the model prediction for the `johny_d` example. 150 | 151 | ```{r} 152 | (johny_d <- titanic_imputed[2,]) 153 | 154 | predict(model_titanic_glm, johny_d, type = "response") 155 | ``` 156 | 157 | It turns out that the model prediction for this passenger's survival is very low. Let's see which aspects have the biggest influence on it. 158 | 159 | We start with DALEX [explainer](https://modeloriented.github.io/DALEX/reference/explain.html). 160 | 161 | ```{r} 162 | explain_titanic <- DALEX::explain(model_titanic_glm, 163 | data = titanic_imputed, 164 | y = titanic_imputed$survived, 165 | label = "Logistic Regression", 166 | verbose = FALSE) 167 | ``` 168 | 169 | And use it to call `triplot::predict_aspects()` function. 170 | Afterwards, we print and plot function results 171 | 172 | ```{r aspect-importance, fig.width = 8, fig.height = 2.5} 173 | library("triplot") 174 | 175 | ai_titanic <- predict_aspects(x = explain_titanic, 176 | new_observation = johny_d[,-8], 177 | variable_groups = aspects_titanic) 178 | 179 | print(ai_titanic, show_features = TRUE) 180 | 181 | plot(ai_titanic) 182 | ``` 183 | 184 | We can observe that `wealth` (class, fare) variables have the biggest contribution to the prediction. This contribution is of a negative type. `Personal` (age, gender) and `Family` (sibsp, parch) variables have positive influence on the prediction, but it is much smaller. `Embarked` feature has very small, negative contribution to the prediction. 185 | 186 | ## Learn more 187 | 188 | - [triplot package overview](https://modeloriented.github.io/triplot/articles/vignette_aspect_importance.html) 189 | - [usecase with FIFA 20 data set](https://modeloriented.github.io/triplot/articles/vignette_aspect_importance_fifa.html) 190 | - [description of predict aspects method](https://modeloriented.github.io/triplot/articles/vignette_aspect_importance_indepth.html) 191 | 192 | ## Acknowledgments 193 | 194 | Work on this package was financially supported by the NCBR Grant POIR.01.01.01-00-0328/17. 195 | 196 | -------------------------------------------------------------------------------- /README_files/figure-gfm/unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/README_files/figure-gfm/unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /README_files/figure-gfm/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/README_files/figure-gfm/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /README_files/figure-gfm/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/README_files/figure-gfm/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /README_files/figure-gfm/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/README_files/figure-gfm/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /README_files/figure-gfm/unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/README_files/figure-gfm/unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /README_files/triplot_explained.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/README_files/triplot_explained.gif -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | template: 2 | package: DrWhyTemplate 3 | default_assets: false 4 | reference: 5 | - title: "Predict aspects" 6 | desc: "Functions for local model explanations. Also known as aspect importance." 7 | - contents: 8 | - matches("aspect_importance") 9 | - get_sample 10 | 11 | - title: "Triplot" 12 | desc: "Plots for hierarchical feature grouping." 13 | - contents: 14 | - matches("triplot") 15 | - matches("hierarchical") 16 | 17 | - title: "Variables grouping" 18 | desc: "Function for variables grouping." 19 | - contents: 20 | - cluster_variables 21 | - plot.cluster_variables 22 | - list_variables 23 | - group_variables 24 | 25 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | 3 | coverage: 4 | status: 5 | project: 6 | default: 7 | target: auto 8 | threshold: 1% 9 | informational: true 10 | patch: 11 | default: 12 | target: auto 13 | threshold: 1% 14 | informational: true 15 | -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Page not found (404) • triplot 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 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 69 | 70 | 71 | 72 | 79 | 80 | 81 | 82 | 83 |
84 |
85 | 147 | 148 | 149 | 150 |
151 | 152 |
153 |
154 | 157 | 158 | Content not found. Please use links in the navbar. 159 | 160 |
161 | 162 | 167 | 168 |
169 | 170 | 171 | 172 |
173 | 176 | 177 |
178 |

Site built with pkgdown.

179 |
180 | 181 |
182 |
183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | -------------------------------------------------------------------------------- /docs/MI2logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/MI2logo.jpg -------------------------------------------------------------------------------- /docs/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /docs/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/apple-touch-icon.png -------------------------------------------------------------------------------- /docs/articles/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Articles • triplot 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 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 69 | 70 | 71 | 72 | 79 | 80 | 81 | 82 | 83 |
84 |
85 | 147 | 148 | 149 | 150 |
151 | 152 |
153 |
154 | 157 | 158 |
159 |

All vignettes

160 |

161 | 162 |
163 |
Triplot overview
164 |
165 |
Usecase with FIFA 20 dataset
166 |
167 |
Description of predict_aspects method
168 |
169 |
170 |
171 |
172 |
173 | 174 | 175 |
176 | 179 | 180 |
181 |

Site built with pkgdown.

182 |
183 | 184 |
185 |
186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_description_files/figure-html/aspect importance with automated aspects-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_description_files/figure-html/aspect importance with automated aspects-1.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_description_files/figure-html/aspect importance with manual aspects-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_description_files/figure-html/aspect importance with manual aspects-1.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_description_files/figure-html/triplot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_description_files/figure-html/triplot-1.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_description_files/figure-html/triplot-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_description_files/figure-html/triplot-2.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_fifa_files/figure-html/check model parts-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_fifa_files/figure-html/check model parts-1.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_fifa_files/figure-html/predict_aspects #1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_fifa_files/figure-html/predict_aspects #1-1.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_fifa_files/figure-html/predict_aspects #2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_fifa_files/figure-html/predict_aspects #2-1.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_fifa_files/figure-html/predict_aspects #3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_fifa_files/figure-html/predict_aspects #3-1.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_fifa_files/figure-html/triplot for the whole model-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_fifa_files/figure-html/triplot for the whole model-1.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-1-1.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-10-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-10-1.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-11-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-11-1.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-4-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-4-2.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-4-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-4-3.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-4-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-4-4.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-6-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-6-2.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-6-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-6-3.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-7-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-7-2.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-9-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_fifa_files/figure-html/unnamed-chunk-9-1.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_files/figure-html/Calculating aspect importance (logistic regression)-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_files/figure-html/Calculating aspect importance (logistic regression)-1.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_files/figure-html/Calculating aspect importance (random forest)-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_files/figure-html/Calculating aspect importance (random forest)-1.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_files/figure-html/unnamed-chunk-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_files/figure-html/unnamed-chunk-2-1.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_indepth_files/figure-html/aspect importance with automated aspects-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_indepth_files/figure-html/aspect importance with automated aspects-1.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_indepth_files/figure-html/aspect importance with manual aspects-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_indepth_files/figure-html/aspect importance with manual aspects-1.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_indepth_files/figure-html/triplot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_indepth_files/figure-html/triplot-1.png -------------------------------------------------------------------------------- /docs/articles/vignette_aspect_importance_indepth_files/figure-html/triplot-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/articles/vignette_aspect_importance_indepth_files/figure-html/triplot-2.png -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Authors • triplot 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 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 69 | 70 | 71 | 72 | 79 | 80 | 81 | 82 | 83 |
84 |
85 | 147 | 148 | 149 | 150 |
151 | 152 |
153 |
154 | 157 | 158 |
    159 |
  • 160 |

    Katarzyna Pekala. Author, maintainer. 161 |

    162 |
  • 163 |
  • 164 |

    Przemyslaw Biecek. Author. 165 |

    166 |
  • 167 |
168 | 169 |
170 | 171 |
172 | 173 | 174 | 175 |
176 | 179 | 180 |
181 |

Site built with pkgdown.

182 |
183 | 184 |
185 |
186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /docs/dalexverse-2.css: -------------------------------------------------------------------------------- 1 | body {font-size: 16px; 2 | padding-top: 60px; 3 | } 4 | h1 {font-size: 40px; 5 | font-weight: 500; 6 | } 7 | h2 {font-size: 30px; 8 | font-weight: 500; 9 | } 10 | h3 {font-size: 23px; 11 | font-weight: 500; 12 | } 13 | 14 | 15 | .ref-arguments th {vertical-align: top;} 16 | 17 | /* navbar ----------------------------------------------- */ 18 | 19 | 20 | .navbar .info { 21 | color: #fff; 22 | float: left; 23 | height: 50px; 24 | width: 330px; 25 | font-size: 80%; 26 | position: relative; 27 | margin-left: 5px; 28 | } 29 | 30 | .navbar .info .partof .a { 31 | color: #7abaf5 !important; 32 | } 33 | 34 | .navbar .info .partof { 35 | position: absolute; 36 | top: 0; 37 | } 38 | 39 | .navbar .info .developedby { 40 | position: absolute; 41 | bottom: 0; 42 | right: 0; 43 | } 44 | 45 | .navbar .info .version { 46 | position: absolute; 47 | bottom: 0; 48 | } 49 | .navbar .info .version-danger { 50 | font-weight: bold; 51 | color: orange; 52 | } 53 | 54 | .navbar-form { 55 | margin-top: 3px; 56 | margin-bottom: 0; 57 | } 58 | 59 | .navbar-toggle { 60 | margin-top: 8px; 61 | margin-bottom: 5px; 62 | } 63 | 64 | /* new */ 65 | 66 | nav[data-toggle='toc'] .nav > li > a { 67 | background-color: #4a3c89; 68 | color: #fff; 69 | padding: 7px 12px; 70 | border-radius: 4px; 71 | border: 1px white solid; 72 | font-size: 16px; 73 | font-weight: 400; 74 | } 75 | 76 | nav[data-toggle='toc'] .nav > li > a:hover, 77 | nav[data-toggle='toc'] .nav > li > a:focus { 78 | background-color: #370f54; 79 | color: #fff; 80 | padding: 7px 12px; 81 | border-radius: 4px; 82 | border: 1px white solid; 83 | font-size: 16px; 84 | font-weight: 400; 85 | padding-left: 15px; 86 | border-left: 2px solid #fff; 87 | } 88 | 89 | nav[data-toggle='toc'] .nav > .active > a, 90 | nav[data-toggle='toc'] .nav > .active:hover > a, 91 | nav[data-toggle='toc'] .nav > .active:focus > a { 92 | background-color: #370f54; 93 | color: #fff; 94 | padding: 7px 12px; 95 | border-radius: 4px; 96 | border: 1px white solid; 97 | font-size: 16px; 98 | font-weight: 500; 99 | padding-left: 15px; 100 | border-left: 3px solid #fff; 101 | } 102 | 103 | 104 | nav[data-toggle='toc'] .nav .nav > li > a { 105 | background-color: #4a3c89; 106 | color: #fff; 107 | padding: 7px 12px; 108 | border-radius: 4px; 109 | border: 1px white solid; 110 | font-size: 14px; 111 | font-weight: 400; 112 | } 113 | 114 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 115 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 116 | background-color: #370f54; 117 | color: #fff; 118 | padding: 7px 12px; 119 | border-radius: 4px; 120 | border: 1px white solid; 121 | font-size: 14px; 122 | font-weight: 400; 123 | padding-left: 15px; 124 | border-left: 2px solid #fff; 125 | } 126 | 127 | nav[data-toggle='toc'] .nav .nav > .active > a, 128 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 129 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 130 | background-color: #370f54; 131 | color: #fff; 132 | padding: 7px 12px; 133 | border-radius: 4px; 134 | border: 1px white solid; 135 | font-size: 14px; 136 | font-weight: 500; 137 | padding-left: 15px; 138 | border-left: 3px solid #fff; 139 | } 140 | 141 | /* old */ 142 | .navbar-nav li a { 143 | padding-bottom: 10px; 144 | } 145 | .navbar-default .navbar-nav > .active > a, 146 | .navbar-default .navbar-nav > .active > a:hover, 147 | .navbar-default .navbar-nav > .active > a:focus { 148 | background-color: #370f54 !important; 149 | border-radius: 3px; 150 | } 151 | 152 | .nav-pils>li>a { 153 | position: relative; 154 | display: block; 155 | padding: 10px 15px; 156 | border-radius: 4px; 157 | } 158 | 159 | 160 | 161 | /* footer ------------------------------------------------ */ 162 | 163 | footer { 164 | margin-top: 45px; 165 | padding: 35px 0 36px; 166 | border-top: 1px solid #e5e5e5; 167 | 168 | display: flex; 169 | color: #666; 170 | } 171 | footer p { 172 | margin-bottom: 0; 173 | } 174 | footer .tidyverse { 175 | flex: 1; 176 | margin-right: 1em; 177 | } 178 | footer .author { 179 | flex: 1; 180 | text-align: left; 181 | } 182 | 183 | /* sidebar old ------------------------------------------------ */ 184 | 185 | #sidebar h2 { 186 | font-size: 1.6em; 187 | margin-top: 1em; 188 | margin-bottom: 0.25em; 189 | } 190 | 191 | #sidebar .list-unstyled li { 192 | margin-bottom: 0.5em; 193 | line-height: 1.4; 194 | } 195 | 196 | #sidebar small { 197 | color: #777; 198 | } 199 | 200 | #sidebar .nav { 201 | padding-left: 0px; 202 | list-style-type: none; 203 | color: #5a9ddb; 204 | } 205 | 206 | #sidebar .nav > li.active { 207 | background-position: left -240px; 208 | } 209 | 210 | /*#sidebar a { 211 | padding: 0px; 212 | color: #5a9ddb; 213 | background-color: transparent; 214 | } 215 | */ 216 | /*#sidebar a:hover { 217 | background-color: transparent; 218 | text-decoration: underline; 219 | }*/ 220 | 221 | /* sidebar new ------------------------------------------------ */ 222 | 223 | #pkgdown-sidebar h2 { 224 | font-size: 30px; 225 | margin-top: 1em; 226 | margin-bottom: 0.25em; 227 | } 228 | 229 | #pkgdown-sidebar .list-unstyled li { 230 | margin-bottom: 0.5em; 231 | line-height: 1.4; 232 | } 233 | 234 | #pkgdown-sidebar small { 235 | color: #777; 236 | } 237 | 238 | #pkgdown-sidebar .nav { 239 | padding-left: 0px; 240 | list-style-type: none; 241 | color: #5a9ddb; 242 | } 243 | 244 | #pkgdown-sidebar .nav > li.active { 245 | background-position: left -240px; 246 | } 247 | 248 | /* ---- *\/*----------------------------------*\ 249 | 250 | /* Sticker footer */ 251 | body > .container { 252 | display: flex; 253 | padding-top: 30px; 254 | min-height: calc(100vh); 255 | flex-direction: column; 256 | } 257 | 258 | /* Section anchors ---------------------------------*/ 259 | 260 | 261 | .hasAnchor:hover a.anchor { 262 | visibility: visible; 263 | } 264 | 265 | @media (max-width: 767px) { 266 | .hasAnchor:hover a.anchor { 267 | visibility: hidden; 268 | } 269 | } 270 | 271 | 272 | /* Static header placement on mobile devices */ 273 | @media (max-width: 767px) { 274 | .navbar-fixed-top { 275 | position: absolute; 276 | } 277 | .navbar { 278 | padding: 0; 279 | } 280 | } 281 | 282 | 283 | /* Syntax highlighting ---------------------------------------------------- */ 284 | 285 | 286 | table { 287 | display: block; 288 | overflow: auto; 289 | width: 100% !important; 290 | } 291 | 292 | .navbar-mi2logo { 293 | float: left; 294 | margin-right: 2px; 295 | margin-left: 2px; 296 | margin-bottom: 2px; 297 | margin-top: 2px; 298 | } 299 | 300 | .sidebar-logo { 301 | display:block; 302 | margin-left:auto; 303 | margin-right:auto; 304 | text-align: justify; 305 | } 306 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /docs/drwhy_znak_violet.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/drwhy_znak_violet.jpg -------------------------------------------------------------------------------- /docs/drwhy_znak_violet_small.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/drwhy_znak_violet_small.jpg -------------------------------------------------------------------------------- /docs/drwhylogo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/drwhylogo.jpg -------------------------------------------------------------------------------- /docs/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/favicon-16x16.png -------------------------------------------------------------------------------- /docs/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/favicon-32x32.png -------------------------------------------------------------------------------- /docs/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/favicon.ico -------------------------------------------------------------------------------- /docs/jquery.sticky-kit.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | Sticky-kit v1.1.2 | WTFPL | Leaf Corcoran 2015 | http://leafo.net 3 | */ 4 | (function(){var b,f;b=this.jQuery||window.jQuery;f=b(window);b.fn.stick_in_parent=function(d){var A,w,J,n,B,K,p,q,k,E,t;null==d&&(d={});t=d.sticky_class;B=d.inner_scrolling;E=d.recalc_every;k=d.parent;q=d.offset_top;p=d.spacer;w=d.bottoming;null==q&&(q=0);null==k&&(k=void 0);null==B&&(B=!0);null==t&&(t="is_stuck");A=b(document);null==w&&(w=!0);J=function(a,d,n,C,F,u,r,G){var v,H,m,D,I,c,g,x,y,z,h,l;if(!a.data("sticky_kit")){a.data("sticky_kit",!0);I=A.height();g=a.parent();null!=k&&(g=g.closest(k)); 5 | if(!g.length)throw"failed to find stick parent";v=m=!1;(h=null!=p?p&&a.closest(p):b("
    "))&&h.css("position",a.css("position"));x=function(){var c,f,e;if(!G&&(I=A.height(),c=parseInt(g.css("border-top-width"),10),f=parseInt(g.css("padding-top"),10),d=parseInt(g.css("padding-bottom"),10),n=g.offset().top+c+f,C=g.height(),m&&(v=m=!1,null==p&&(a.insertAfter(h),h.detach()),a.css({position:"",top:"",width:"",bottom:""}).removeClass(t),e=!0),F=a.offset().top-(parseInt(a.css("margin-top"),10)||0)-q, 6 | u=a.outerHeight(!0),r=a.css("float"),h&&h.css({width:a.outerWidth(!0),height:u,display:a.css("display"),"vertical-align":a.css("vertical-align"),"float":r}),e))return l()};x();if(u!==C)return D=void 0,c=q,z=E,l=function(){var b,l,e,k;if(!G&&(e=!1,null!=z&&(--z,0>=z&&(z=E,x(),e=!0)),e||A.height()===I||x(),e=f.scrollTop(),null!=D&&(l=e-D),D=e,m?(w&&(k=e+u+c>C+n,v&&!k&&(v=!1,a.css({position:"fixed",bottom:"",top:c}).trigger("sticky_kit:unbottom"))),eb&&!v&&(c-=l,c=Math.max(b-u,c),c=Math.min(q,c),m&&a.css({top:c+"px"})))):e>F&&(m=!0,b={position:"fixed",top:c},b.width="border-box"===a.css("box-sizing")?a.outerWidth()+"px":a.width()+"px",a.css(b).addClass(t),null==p&&(a.after(h),"left"!==r&&"right"!==r||h.append(a)),a.trigger("sticky_kit:stick")),m&&w&&(null==k&&(k=e+u+c>C+n),!v&&k)))return v=!0,"static"===g.css("position")&&g.css({position:"relative"}), 8 | a.css({position:"absolute",bottom:d,top:"auto"}).trigger("sticky_kit:bottom")},y=function(){x();return l()},H=function(){G=!0;f.off("touchmove",l);f.off("scroll",l);f.off("resize",y);b(document.body).off("sticky_kit:recalc",y);a.off("sticky_kit:detach",H);a.removeData("sticky_kit");a.css({position:"",bottom:"",top:"",width:""});g.position("position","");if(m)return null==p&&("left"!==r&&"right"!==r||a.insertAfter(h),h.remove()),a.removeClass(t)},f.on("touchmove",l),f.on("scroll",l),f.on("resize", 9 | y),b(document.body).on("sticky_kit:recalc",y),a.on("sticky_kit:detach",H),setTimeout(l,0)}};n=0;for(K=this.length;n 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /docs/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/logo.png -------------------------------------------------------------------------------- /docs/news/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Changelog • triplot 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 | 53 | 54 | 55 | 56 | 57 | 61 | 62 | 63 | 64 | 71 | 72 | 73 | 74 | 75 |
    76 |
    77 | 139 | 140 | 141 | 142 |
    143 | 144 |
    145 |
    146 | 150 | 151 |
    152 |

    153 | triplot 1.2

    154 |
      155 |
    • last vertical line in hierarchical_importance() plot of model_triplot() shows baseline value
    • 156 |
    • left margin of middle panel in triplot can be set with “margin_mid”
    • 157 |
    158 |
    159 |
    160 |

    161 | triplot 1.1.2

    162 |
      163 |
    • modified triplot object and methods
    • 164 |
    • removed ingredients dependency
    • 165 |
    166 |
    167 |
    168 |

    169 | triplot 1.1.1

    170 |
      171 |
    • switched from GridExtra to Patchwork
    • 172 |
    • improved plotting of triplot object
    • 173 |
    174 |
    175 |
    176 |

    177 | triplot 1.1.0

    178 |
      179 |
    • renamed prediction_aspect() to predict_aspects()
    • 180 |
    • added aliases predict_triplot() and model_triplot()
    • 181 |
    • added bar_width param to triplot
    • 182 |
    • added warning if target is in data
    • 183 |
    • added parameter “type” to calculate_triplot()
    • 184 |
    • added print for predict_aspects() and triplot()
    • 185 |
    186 |
    187 |
    188 |

    189 | triplot 1.0.4

    190 |
      191 |
    • restructured group_variables() and triplot objects
    • 192 |
    • added hierarchical_importance object (instead of plot_aspects_importance_grouping)
    • 193 |
    • triplot renamed to calculate_triplot()
    • 194 |
    • triplot is plotted by calling plot on calculate_triplot() results
    • 195 |
    196 |
    197 |
    198 |

    199 | triplot 1.0.3

    200 |
      201 |
    • updated plot_aspects_importance_grouping so it can draw last clusters connection
    • 202 |
    • add_importance_labels parameter set to FALSE by default
    • 203 |
    204 |
    205 |
    206 |

    207 | triplot 1.0.2

    208 |
      209 |
    • new feature: triplot can present both: automatic aspect and feature importance grouping (by using ingredients::feature_importance())
    • 210 |
    211 |
    212 |
    213 |

    214 | triplot 1.0.1

    215 |
      216 |
    • aspectImportance is renamed to triplot
    • 217 |
    • added second vignette
    • 218 |
    219 |
    220 |
    221 |

    222 | aspectImportance 1.0

    223 |
      224 |
    • aspect_importance is moved out of DALEXtra into standalone package
    • 225 |
    226 |
    227 |
    228 | 229 | 234 | 235 |
    236 | 237 | 238 |
    239 | 242 | 243 |
    244 |

    Site built with pkgdown.

    245 |
    246 | 247 |
    248 |
    249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | -------------------------------------------------------------------------------- /docs/pkgdown.css: -------------------------------------------------------------------------------- 1 | /* Sticky footer */ 2 | 3 | /** 4 | * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ 5 | * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css 6 | * 7 | * .Site -> body > .container 8 | * .Site-content -> body > .container .row 9 | * .footer -> footer 10 | * 11 | * Key idea seems to be to ensure that .container and __all its parents__ 12 | * have height set to 100% 13 | * 14 | */ 15 | 16 | html, body { 17 | height: 100%; 18 | } 19 | 20 | body { 21 | position: relative; 22 | } 23 | 24 | body > .container { 25 | display: flex; 26 | height: 100%; 27 | flex-direction: column; 28 | } 29 | 30 | body > .container .row { 31 | flex: 1 0 auto; 32 | } 33 | 34 | footer { 35 | margin-top: 45px; 36 | padding: 35px 0 36px; 37 | border-top: 1px solid #e5e5e5; 38 | color: #666; 39 | display: flex; 40 | flex-shrink: 0; 41 | } 42 | footer p { 43 | margin-bottom: 0; 44 | } 45 | footer div { 46 | flex: 1; 47 | } 48 | footer .pkgdown { 49 | text-align: right; 50 | } 51 | footer p { 52 | margin-bottom: 0; 53 | } 54 | 55 | img.icon { 56 | float: right; 57 | } 58 | 59 | img { 60 | max-width: 100%; 61 | } 62 | 63 | /* Fix bug in bootstrap (only seen in firefox) */ 64 | summary { 65 | display: list-item; 66 | } 67 | 68 | /* Typographic tweaking ---------------------------------*/ 69 | 70 | .contents .page-header { 71 | margin-top: calc(-60px + 1em); 72 | } 73 | 74 | dd { 75 | margin-left: 3em; 76 | } 77 | 78 | /* Section anchors ---------------------------------*/ 79 | 80 | a.anchor { 81 | margin-left: -30px; 82 | display:inline-block; 83 | width: 30px; 84 | height: 30px; 85 | visibility: hidden; 86 | 87 | background-image: url(./link.svg); 88 | background-repeat: no-repeat; 89 | background-size: 20px 20px; 90 | background-position: center center; 91 | } 92 | 93 | .hasAnchor:hover a.anchor { 94 | visibility: visible; 95 | } 96 | 97 | @media (max-width: 767px) { 98 | .hasAnchor:hover a.anchor { 99 | visibility: hidden; 100 | } 101 | } 102 | 103 | 104 | /* Fixes for fixed navbar --------------------------*/ 105 | 106 | .contents h1, .contents h2, .contents h3, .contents h4 { 107 | padding-top: 60px; 108 | margin-top: -40px; 109 | } 110 | 111 | /* Navbar submenu --------------------------*/ 112 | 113 | .dropdown-submenu { 114 | position: relative; 115 | } 116 | 117 | .dropdown-submenu>.dropdown-menu { 118 | top: 0; 119 | left: 100%; 120 | margin-top: -6px; 121 | margin-left: -1px; 122 | border-radius: 0 6px 6px 6px; 123 | } 124 | 125 | .dropdown-submenu:hover>.dropdown-menu { 126 | display: block; 127 | } 128 | 129 | .dropdown-submenu>a:after { 130 | display: block; 131 | content: " "; 132 | float: right; 133 | width: 0; 134 | height: 0; 135 | border-color: transparent; 136 | border-style: solid; 137 | border-width: 5px 0 5px 5px; 138 | border-left-color: #cccccc; 139 | margin-top: 5px; 140 | margin-right: -10px; 141 | } 142 | 143 | .dropdown-submenu:hover>a:after { 144 | border-left-color: #ffffff; 145 | } 146 | 147 | .dropdown-submenu.pull-left { 148 | float: none; 149 | } 150 | 151 | .dropdown-submenu.pull-left>.dropdown-menu { 152 | left: -100%; 153 | margin-left: 10px; 154 | border-radius: 6px 0 6px 6px; 155 | } 156 | 157 | /* Sidebar --------------------------*/ 158 | 159 | #pkgdown-sidebar { 160 | margin-top: 30px; 161 | position: -webkit-sticky; 162 | position: sticky; 163 | top: 70px; 164 | } 165 | 166 | #pkgdown-sidebar h2 { 167 | font-size: 1.5em; 168 | margin-top: 1em; 169 | } 170 | 171 | #pkgdown-sidebar h2:first-child { 172 | margin-top: 0; 173 | } 174 | 175 | #pkgdown-sidebar .list-unstyled li { 176 | margin-bottom: 0.5em; 177 | } 178 | 179 | /* bootstrap-toc tweaks ------------------------------------------------------*/ 180 | 181 | /* All levels of nav */ 182 | 183 | /*nav[data-toggle='toc'] .nav > li > a { 184 | padding: 4px 20px 4px 6px; 185 | font-size: 1.5rem; 186 | font-weight: 400; 187 | color: inherit; 188 | } 189 | 190 | nav[data-toggle='toc'] .nav > li > a:hover, 191 | nav[data-toggle='toc'] .nav > li > a:focus { 192 | padding-left: 5px; 193 | color: inherit; 194 | border-left: 1px solid #878787; 195 | } 196 | 197 | nav[data-toggle='toc'] .nav > .active > a, 198 | nav[data-toggle='toc'] .nav > .active:hover > a, 199 | nav[data-toggle='toc'] .nav > .active:focus > a { 200 | padding-left: 5px; 201 | font-size: 1.5rem; 202 | font-weight: 400; 203 | color: inherit; 204 | border-left: 2px solid #878787; 205 | }*/ 206 | 207 | /* Nav: second level (shown on .active) */ 208 | 209 | nav[data-toggle='toc'] .nav .nav { 210 | display: none; /* Hide by default, but at >768px, show it */ 211 | padding-bottom: 10px; 212 | } 213 | /* 214 | nav[data-toggle='toc'] .nav .nav > li > a { 215 | padding-left: 16px; 216 | font-size: 1.35rem; 217 | } 218 | 219 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 220 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 221 | padding-left: 15px; 222 | } 223 | 224 | nav[data-toggle='toc'] .nav .nav > .active > a, 225 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 226 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 227 | padding-left: 15px; 228 | font-weight: 500; 229 | font-size: 1.35rem; 230 | }*/ 231 | 232 | /* orcid ------------------------------------------------------------------- */ 233 | 234 | .orcid { 235 | font-size: 16px; 236 | color: #A6CE39; 237 | /* margins are required by official ORCID trademark and display guidelines */ 238 | margin-left:4px; 239 | margin-right:4px; 240 | vertical-align: middle; 241 | } 242 | 243 | /* Reference index & topics ----------------------------------------------- */ 244 | 245 | .ref-index th {font-weight: normal;} 246 | 247 | .ref-index td {vertical-align: top;} 248 | .ref-index .icon {width: 40px;} 249 | .ref-index .alias {width: 40%;} 250 | .ref-index-icons .alias {width: calc(40% - 40px);} 251 | .ref-index .title {width: 60%;} 252 | 253 | .ref-arguments th {text-align: right; padding-right: 10px;} 254 | .ref-arguments th, .ref-arguments td {vertical-align: top;} 255 | .ref-arguments .name {width: 20%;} 256 | .ref-arguments .desc {width: 80%;} 257 | 258 | /* Nice scrolling for wide elements --------------------------------------- */ 259 | 260 | table { 261 | display: block; 262 | overflow: auto; 263 | } 264 | 265 | /* Syntax highlighting ---------------------------------------------------- */ 266 | 267 | pre { 268 | word-wrap: normal; 269 | word-break: normal; 270 | border: 1px solid #eee; 271 | } 272 | 273 | pre, code { 274 | background-color: #f8f8f8; 275 | color: #333; 276 | } 277 | 278 | pre code { 279 | overflow: auto; 280 | word-wrap: normal; 281 | white-space: pre; 282 | } 283 | 284 | pre .img { 285 | margin: 5px 0; 286 | } 287 | 288 | pre .img img { 289 | background-color: #fff; 290 | display: block; 291 | height: auto; 292 | } 293 | 294 | code a, pre a { 295 | color: #375f84; 296 | } 297 | 298 | a.sourceLine:hover { 299 | text-decoration: none; 300 | } 301 | 302 | .fl {color: #1514b5;} 303 | .fu {color: #000000;} /* function */ 304 | .ch,.st {color: #036a07;} /* string */ 305 | .kw {color: #264D66;} /* keyword */ 306 | .co {color: #888888;} /* comment */ 307 | 308 | .message { color: black; font-weight: bolder;} 309 | .error { color: orange; font-weight: bolder;} 310 | .warning { color: #6A0366; font-weight: bolder;} 311 | 312 | /* Clipboard --------------------------*/ 313 | 314 | .hasCopyButton { 315 | position: relative; 316 | } 317 | 318 | .btn-copy-ex { 319 | position: absolute; 320 | right: 0; 321 | top: 0; 322 | visibility: hidden; 323 | } 324 | 325 | .hasCopyButton:hover button.btn-copy-ex { 326 | visibility: visible; 327 | } 328 | 329 | /* headroom.js ------------------------ */ 330 | 331 | .headroom { 332 | will-change: transform; 333 | transition: transform 200ms linear; 334 | } 335 | .headroom--pinned { 336 | transform: translateY(0%); 337 | } 338 | .headroom--unpinned { 339 | transform: translateY(-100%); 340 | } 341 | 342 | /* mark.js ----------------------------*/ 343 | 344 | mark { 345 | background-color: rgba(255, 255, 51, 0.5); 346 | border-bottom: 2px solid rgba(255, 153, 51, 0.3); 347 | padding: 1px; 348 | } 349 | 350 | /* vertical spacing after htmlwidgets */ 351 | .html-widget { 352 | margin-bottom: 10px; 353 | } 354 | 355 | /* fontawesome ------------------------ */ 356 | 357 | .fab { 358 | font-family: "Font Awesome 5 Brands" !important; 359 | } 360 | 361 | /* don't display links in code chunks when printing */ 362 | /* source: https://stackoverflow.com/a/10781533 */ 363 | @media print { 364 | code a:link:after, code a:visited:after { 365 | content: ""; 366 | } 367 | } 368 | -------------------------------------------------------------------------------- /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 | $(".examples, 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; 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 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: 2.7.3 2 | pkgdown: 1.5.1 3 | pkgdown_sha: ~ 4 | articles: [] 5 | last_built: 2020-06-04T13:06Z 6 | 7 | -------------------------------------------------------------------------------- /docs/reference/calculate_triplot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/reference/calculate_triplot-1.png -------------------------------------------------------------------------------- /docs/reference/cluster_variables.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Creates a cluster tree from numeric features — cluster_variables • triplot 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 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 70 | 71 | 72 | 73 | 80 | 81 | 82 | 83 | 84 |
    85 |
    86 | 148 | 149 | 150 | 151 |
    152 | 153 |
    154 |
    155 | 160 | 161 |
    162 |

    Creates a cluster tree from numeric features and their correlations.

    163 |
    164 | 165 |
    cluster_variables(x, ...)
    166 | 
    167 | # S3 method for default
    168 | cluster_variables(x, clust_method = "complete", ...)
    169 | 170 |

    Arguments

    171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 185 | 186 |
    x

    dataframe with only numeric columns

    ...

    other parameters

    clust_method

    the agglomeration method to be used 184 | see hclust methods

    187 | 188 |

    Value

    189 | 190 |

    an hclust object

    191 | 192 |

    Examples

    193 |
    library("DALEX") 194 | dragons_data <- dragons[,c(2,3,4,7,8)] 195 | cluster_variables(dragons_data, clust_method = "complete")
    #> 196 | #> Call: 197 | #> hclust(d = as.dist(1 - abs(cor(x, method = "spearman"))), method = clust_method) 198 | #> 199 | #> Cluster method : complete 200 | #> Number of objects: 5 201 | #>
    202 |
    203 |
    204 | 209 |
    210 | 211 | 212 |
    213 | 216 | 217 |
    218 |

    Site built with pkgdown.

    219 |
    220 | 221 |
    222 |
    223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | -------------------------------------------------------------------------------- /docs/reference/figures/aspect-importance-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/reference/figures/aspect-importance-1.png -------------------------------------------------------------------------------- /docs/reference/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/reference/figures/logo.png -------------------------------------------------------------------------------- /docs/reference/figures/model-triplot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/reference/figures/model-triplot-1.png -------------------------------------------------------------------------------- /docs/reference/figures/predict-triplot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/reference/figures/predict-triplot-1.png -------------------------------------------------------------------------------- /docs/reference/figures/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/reference/figures/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/reference/figures/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/reference/figures/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /docs/reference/figures/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/reference/figures/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /docs/reference/figures/unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/reference/figures/unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /docs/reference/figures/unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/reference/figures/unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /docs/reference/figures/unnamed-chunk-9-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/reference/figures/unnamed-chunk-9-1.png -------------------------------------------------------------------------------- /docs/reference/group_variables.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Helper function that combines clustering variables and creating aspect list — group_variables • triplot 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 | 53 | 54 | 55 | 56 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 71 | 72 | 73 | 74 | 81 | 82 | 83 | 84 | 85 |
    86 |
    87 | 149 | 150 | 151 | 152 |
    153 | 154 |
    155 |
    156 | 161 | 162 |
    163 |

    Divides correlated features into groups, called aspects. Division is based on 164 | correlation cutoff level.

    165 |
    166 | 167 |
    group_variables(x, h, clust_method = "complete")
    168 | 169 |

    Arguments

    170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 184 | 185 |
    x

    hclust object

    h

    correlation value for tree cutting

    clust_method

    the agglomeration method to be used 183 | see hclust methods

    186 | 187 |

    Value

    188 | 189 |

    list with aspect

    190 | 191 |

    Examples

    192 |
    library("DALEX") 193 | dragons_data <- dragons[,c(2,3,4,7,8)] 194 | group_variables(dragons_data, h = 0.5, clust_method = "complete")
    #> $aspect.group1 195 | #> [1] "height" "weight" 196 | #> 197 | #> $aspect.group2 198 | #> [1] "scars" "life_length" 199 | #> 200 | #> $aspect.group3 201 | #> [1] "number_of_lost_teeth" 202 | #>
    203 |
    204 |
    205 | 210 |
    211 | 212 | 213 |
    214 | 217 | 218 |
    219 |

    Site built with pkgdown.

    220 |
    221 | 222 |
    223 |
    224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | -------------------------------------------------------------------------------- /docs/reference/hierarchical_importance-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/reference/hierarchical_importance-1.png -------------------------------------------------------------------------------- /docs/reference/list_variables.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Cuts tree at custom height and returns a list — list_variables • triplot 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 | 53 | 54 | 55 | 56 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 71 | 72 | 73 | 74 | 81 | 82 | 83 | 84 | 85 |
    86 |
    87 | 149 | 150 | 151 | 152 |
    153 | 154 |
    155 |
    156 | 161 | 162 |
    163 |

    This function creates aspect list after cutting a cluster tree of features 164 | at a given height.

    165 |
    166 | 167 |
    list_variables(x, h)
    168 | 169 |

    Arguments

    170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 |
    x

    hclust object

    h

    correlation value for tree cutting

    181 | 182 |

    Value

    183 | 184 |

    list of aspects

    185 | 186 |

    Examples

    187 |
    library("DALEX") 188 | dragons_data <- dragons[,c(2,3,4,7,8)] 189 | cv <- cluster_variables(dragons_data, clust_method = "complete") 190 | list_variables(cv, h = 0.5)
    #> $aspect.group1 191 | #> [1] "height" "weight" 192 | #> 193 | #> $aspect.group2 194 | #> [1] "scars" "life_length" 195 | #> 196 | #> $aspect.group3 197 | #> [1] "number_of_lost_teeth" 198 | #>
    199 |
    200 |
    201 | 206 |
    207 | 208 | 209 |
    210 | 213 | 214 |
    215 |

    Site built with pkgdown.

    216 |
    217 | 218 |
    219 |
    220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | -------------------------------------------------------------------------------- /docs/reference/plot.aspect_importance-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/reference/plot.aspect_importance-1.png -------------------------------------------------------------------------------- /docs/reference/plot.cluster_variables-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/reference/plot.cluster_variables-1.png -------------------------------------------------------------------------------- /docs/reference/plot.triplot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/reference/plot.triplot-1.png -------------------------------------------------------------------------------- /docs/reference/plot_aspects_importance_grouping-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/reference/plot_aspects_importance_grouping-1.png -------------------------------------------------------------------------------- /docs/reference/plot_group_variables-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/reference/plot_group_variables-1.png -------------------------------------------------------------------------------- /docs/reference/plot_group_variables.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Plots tree with correlation values — plot_group_variables • triplot 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 | 53 | 54 | 55 | 56 | 57 | 58 | 62 | 63 | 64 | 65 | 66 | 67 | 68 |
    69 |
    70 | 129 | 130 | 131 | 132 |
    133 | 134 |
    135 |
    136 | 141 | 142 |
    143 |

    Plots tree that illustrates the results of group_variables function.

    144 |
    145 | 146 |
    plot_group_variables(
    147 |   x,
    148 |   p,
    149 |   show_labels = TRUE,
    150 |   draw_abline = TRUE,
    151 |   axis_lab_size = 10,
    152 |   text_size = 3
    153 | )
    154 | 155 |

    Arguments

    156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 |
    x

    hclust object

    p

    correlation value for cutoff level

    show_labels

    if TRUE, plot will have annotated axis Y

    draw_abline

    if TRUE, cutoff line will be drawn

    axis_lab_size

    size of labels on axis Y, if applicable

    text_size

    size of labels annotating values of correlations

    183 | 184 |

    Value

    185 | 186 |

    tree plot

    187 | 188 |

    Examples

    189 |
    library("DALEX") 190 | dragons_data <- dragons[,c(2,3,4,7,8)] 191 | group_variables(dragons_data, p = 0.7, clust_method = "complete", 192 | draw_tree = TRUE)
    #> $aspect.group1 193 | #> [1] "height" "weight" 194 | #> 195 | #> $aspect.group2 196 | #> [1] "scars" "life_length" 197 | #> 198 | #> $aspect.group3 199 | #> [1] "number_of_lost_teeth" 200 | #>
    201 |
    202 |
    203 | 208 |
    209 | 210 | 211 |
    212 | 215 | 216 |
    217 |

    Site built with pkgdown.

    218 |
    219 | 220 |
    221 |
    222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | -------------------------------------------------------------------------------- /docs/reference/triplot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/reference/triplot-1.png -------------------------------------------------------------------------------- /docs/reference/triplot-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/reference/triplot-2.png -------------------------------------------------------------------------------- /docs/reference/triplot-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/reference/triplot-3.png -------------------------------------------------------------------------------- /docs/reference/triplot-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/docs/reference/triplot-4.png -------------------------------------------------------------------------------- /docs/tocBullet.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /man/aspect_importance.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/aspect_importance.R 3 | \name{aspect_importance} 4 | \alias{aspect_importance} 5 | \alias{aspect_importance.explainer} 6 | \alias{aspect_importance.default} 7 | \alias{lime} 8 | \alias{predict_aspects} 9 | \title{Calculates importance of variable groups (called aspects) for a selected 10 | observation} 11 | \usage{ 12 | aspect_importance(x, ...) 13 | 14 | \method{aspect_importance}{explainer}( 15 | x, 16 | new_observation, 17 | variable_groups, 18 | N = 1000, 19 | n_var = 0, 20 | sample_method = "default", 21 | f = 2, 22 | ... 23 | ) 24 | 25 | \method{aspect_importance}{default}( 26 | x, 27 | data, 28 | predict_function = predict, 29 | label = class(x)[1], 30 | new_observation, 31 | variable_groups, 32 | N = 100, 33 | n_var = 0, 34 | sample_method = "default", 35 | f = 2, 36 | ... 37 | ) 38 | 39 | lime(x, ...) 40 | 41 | predict_aspects(x, ...) 42 | } 43 | \arguments{ 44 | \item{x}{an explainer created with the \code{DALEX::explain()} function 45 | or a model to be explained.} 46 | 47 | \item{...}{other parameters} 48 | 49 | \item{new_observation}{selected observation with columns that corresponds to 50 | variables used in the model} 51 | 52 | \item{variable_groups}{list containing grouping of features into aspects} 53 | 54 | \item{N}{number of observations to be sampled (with replacement) from data 55 | NOTE: Small \code{N} may cause unstable results.} 56 | 57 | \item{n_var}{maximum number of non-zero coefficients after lasso fitting, 58 | if zero than linear regression is used} 59 | 60 | \item{sample_method}{sampling method in \code{\link{get_sample}}} 61 | 62 | \item{f}{frequency in \code{\link{get_sample}}} 63 | 64 | \item{data}{dataset, it will be extracted from \code{x} if it's an explainer 65 | NOTE: It is best when target variable is not present in the \code{data}} 66 | 67 | \item{predict_function}{predict function, it will be extracted from \code{x} 68 | if it's an explainer} 69 | 70 | \item{label}{name of the model. By default it's extracted from the 'class' 71 | attribute of the model.} 72 | } 73 | \value{ 74 | An object of the class \code{aspect_importance}. Contains data frame 75 | that describes aspects' importance. 76 | } 77 | \description{ 78 | Predict aspects function takes a sample from a given dataset and modifies 79 | it. Modification is made by replacing part of its aspects by values from the 80 | observation. Then function is calculating the difference between the 81 | prediction made on modified sample and the original sample. Finally, it 82 | measures the impact of aspects on the change of prediction by using the 83 | linear model or lasso. 84 | } 85 | \examples{ 86 | library("DALEX") 87 | 88 | model_titanic_glm <- glm(survived == 1 ~ 89 | class+gender+age+sibsp+parch+fare+embarked, 90 | data = titanic_imputed, 91 | family = "binomial") 92 | 93 | explain_titanic_glm <- explain(model_titanic_glm, 94 | data = titanic_imputed[,-8], 95 | y = titanic_imputed$survived == 1, 96 | verbose = FALSE) 97 | 98 | aspects <- list(wealth = c("class", "fare"), 99 | family = c("sibsp", "parch"), 100 | personal = c("gender", "age"), 101 | embarked = "embarked") 102 | 103 | predict_aspects(explain_titanic_glm, 104 | new_observation = titanic_imputed[1,], 105 | variable_groups = aspects) 106 | 107 | \donttest{ 108 | library("randomForest") 109 | library("DALEX") 110 | model_titanic_rf <- 111 | randomForest(factor(survived) ~ class + gender + age + sibsp + 112 | parch + fare + embarked, 113 | data = titanic_imputed) 114 | 115 | explain_titanic_rf <- explain(model_titanic_rf, 116 | data = titanic_imputed[,-8], 117 | y = titanic_imputed$survived == 1, 118 | verbose = FALSE) 119 | 120 | predict_aspects(explain_titanic_rf, 121 | new_observation = titanic_imputed[1,], 122 | variable_groups = aspects) 123 | 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /man/aspect_importance_single.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/aspect_importance_single.R 3 | \name{aspect_importance_single} 4 | \alias{aspect_importance_single} 5 | \alias{aspect_importance_single.explainer} 6 | \alias{aspect_importance_single.default} 7 | \title{Aspects importance for single aspects} 8 | \usage{ 9 | aspect_importance_single(x, ...) 10 | 11 | \method{aspect_importance_single}{explainer}( 12 | x, 13 | new_observation, 14 | N = 1000, 15 | n_var = 0, 16 | sample_method = "default", 17 | f = 2, 18 | ... 19 | ) 20 | 21 | \method{aspect_importance_single}{default}( 22 | x, 23 | data, 24 | predict_function = predict, 25 | label = class(x)[1], 26 | new_observation, 27 | N = 1000, 28 | n_var = 0, 29 | sample_method = "default", 30 | f = 2, 31 | ... 32 | ) 33 | } 34 | \arguments{ 35 | \item{x}{an explainer created with the \code{DALEX::explain()} function 36 | or a model to be explained.} 37 | 38 | \item{...}{other parameters} 39 | 40 | \item{new_observation}{selected observation with columns that corresponds to 41 | variables used in the model, should be without target variable} 42 | 43 | \item{N}{number of observations to be sampled (with replacement) from data 44 | NOTE: Small \code{N} may cause unstable results.} 45 | 46 | \item{n_var}{how many non-zero coefficients for lasso fitting, if zero than 47 | linear regression is used} 48 | 49 | \item{sample_method}{sampling method in \code{\link{get_sample}}} 50 | 51 | \item{f}{frequency in in \code{\link{get_sample}}} 52 | 53 | \item{data}{dataset, it will be extracted from \code{x} if it's an explainer 54 | NOTE: Target variable shouldn't be present in the \code{data}} 55 | 56 | \item{predict_function}{predict function, it will be extracted from \code{x} 57 | if it's an explainer} 58 | 59 | \item{label}{name of the model. By default it's extracted from the 'class' 60 | attribute of the model.} 61 | } 62 | \value{ 63 | An object of the class 'aspect_importance'. Contains dataframe that 64 | describes aspects' importance. 65 | } 66 | \description{ 67 | Calculates aspect_importance for single aspects (every aspect contains only 68 | one feature). 69 | } 70 | \examples{ 71 | library("DALEX") 72 | model_titanic_glm <- glm(survived == 1 ~ class + gender + age + 73 | sibsp + parch + fare + embarked, 74 | data = titanic_imputed, 75 | family = "binomial") 76 | 77 | explainer_titanic <- explain(model_titanic_glm, 78 | data = titanic_imputed[,-8], 79 | verbose = FALSE) 80 | aspect_importance_single(explainer_titanic, 81 | new_observation = titanic_imputed[1,-8]) 82 | 83 | } 84 | -------------------------------------------------------------------------------- /man/calculate_triplot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/triplot.R 3 | \name{calculate_triplot} 4 | \alias{calculate_triplot} 5 | \alias{calculate_triplot.explainer} 6 | \alias{calculate_triplot.default} 7 | \alias{print.triplot} 8 | \alias{model_triplot} 9 | \alias{predict_triplot} 10 | \title{Calculate triplot that sums up automatic aspect/feature importance grouping} 11 | \usage{ 12 | calculate_triplot(x, ...) 13 | 14 | \method{calculate_triplot}{explainer}( 15 | x, 16 | type = c("predict", "model"), 17 | new_observation = NULL, 18 | N = 1000, 19 | loss_function = DALEX::loss_root_mean_square, 20 | B = 10, 21 | fi_type = c("raw", "ratio", "difference"), 22 | clust_method = "complete", 23 | cor_method = "spearman", 24 | ... 25 | ) 26 | 27 | \method{calculate_triplot}{default}( 28 | x, 29 | data, 30 | y = NULL, 31 | predict_function = predict, 32 | label = class(x)[1], 33 | type = c("predict", "model"), 34 | new_observation = NULL, 35 | N = 1000, 36 | loss_function = DALEX::loss_root_mean_square, 37 | B = 10, 38 | fi_type = c("raw", "ratio", "difference"), 39 | clust_method = "complete", 40 | cor_method = "spearman", 41 | ... 42 | ) 43 | 44 | \method{print}{triplot}(x, ...) 45 | 46 | model_triplot(x, ...) 47 | 48 | predict_triplot(x, ...) 49 | } 50 | \arguments{ 51 | \item{x}{an explainer created with the \code{DALEX::explain()} function 52 | or a model to be explained.} 53 | 54 | \item{...}{other parameters} 55 | 56 | \item{type}{if \code{predict} then aspect_importance is used, if 57 | \code{model} than feature_importance is calculated} 58 | 59 | \item{new_observation}{selected observation with columns that corresponds to 60 | variables used in the model, should be without target variable} 61 | 62 | \item{N}{number of rows to be sampled from data 63 | NOTE: Small \code{N} may cause unstable results.} 64 | 65 | \item{loss_function}{a function that will be used to assess variable 66 | importance, if \code{type = model}} 67 | 68 | \item{B}{integer, number of permutation rounds to perform on each variable 69 | in feature importance calculation, if \code{type = model}} 70 | 71 | \item{fi_type}{character, type of transformation that should be applied for 72 | dropout loss, if \code{type = model}. "raw" results raw drop losses, 73 | "ratio" returns \code{drop_loss/drop_loss_full_model}.} 74 | 75 | \item{clust_method}{the agglomeration method to be used, see 76 | \code{\link[stats]{hclust}} methods} 77 | 78 | \item{cor_method}{the correlation method to be used see 79 | \code{\link[stats]{cor}} methods} 80 | 81 | \item{data}{dataset, it will be extracted from \code{x} if it's an explainer 82 | NOTE: Target variable shouldn't be present in the \code{data}} 83 | 84 | \item{y}{true labels for \code{data}, will be extracted from \code{x} 85 | if it's an explainer} 86 | 87 | \item{predict_function}{predict function, it will be extracted from \code{x} 88 | if it's an explainer} 89 | 90 | \item{label}{name of the model. By default it's extracted from the 'class' 91 | attribute of the model.} 92 | } 93 | \value{ 94 | triplot object 95 | } 96 | \description{ 97 | This function shows: 98 | \itemize{ \item plot for the importance of single variables, 99 | \item tree that shows importance for every newly expanded group of variables, 100 | \item clustering tree. } 101 | } 102 | \examples{ 103 | 104 | library(DALEX) 105 | set.seed(123) 106 | apartments_num <- apartments[,unlist(lapply(apartments, is.numeric))] 107 | apartments_num_lm_model <- lm(m2.price ~ ., data = apartments_num) 108 | apartments_num_new_observation <- apartments_num[30, ] 109 | explainer_apartments <- explain(model = apartments_num_lm_model, 110 | data = apartments_num[,-1], 111 | y = apartments_num[, 1], 112 | verbose = FALSE) 113 | apartments_tri <- calculate_triplot(x = explainer_apartments, 114 | new_observation = 115 | apartments_num_new_observation[-1]) 116 | apartments_tri 117 | 118 | 119 | } 120 | -------------------------------------------------------------------------------- /man/cluster_variables.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/group_variables.R 3 | \name{cluster_variables} 4 | \alias{cluster_variables} 5 | \alias{cluster_variables.default} 6 | \title{Creates a cluster tree from numeric features} 7 | \usage{ 8 | cluster_variables(x, ...) 9 | 10 | \method{cluster_variables}{default}(x, clust_method = "complete", cor_method = "spearman", ...) 11 | } 12 | \arguments{ 13 | \item{x}{dataframe with only numeric columns} 14 | 15 | \item{...}{other parameters} 16 | 17 | \item{clust_method}{the agglomeration method to be used 18 | see \code{\link[stats]{hclust}} methods} 19 | 20 | \item{cor_method}{the correlation method to be used 21 | see \code{\link[stats]{cor}} methods} 22 | } 23 | \value{ 24 | an hclust object 25 | } 26 | \description{ 27 | Creates a cluster tree from numeric features and their correlations. 28 | } 29 | \examples{ 30 | library("DALEX") 31 | dragons_data <- dragons[,c(2,3,4,7,8)] 32 | cluster_variables(dragons_data, clust_method = "complete") 33 | 34 | } 35 | -------------------------------------------------------------------------------- /man/figures/aspect-importance-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/man/figures/aspect-importance-1.png -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/man/figures/logo.png -------------------------------------------------------------------------------- /man/figures/model-triplot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/man/figures/model-triplot-1.png -------------------------------------------------------------------------------- /man/figures/predict-triplot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/man/figures/predict-triplot-1.png -------------------------------------------------------------------------------- /man/get_sample.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/aspect_importance.R 3 | \name{get_sample} 4 | \alias{get_sample} 5 | \title{Function for getting binary matrix} 6 | \usage{ 7 | get_sample(n, p, sample_method = c("default", "binom"), f = 2) 8 | } 9 | \arguments{ 10 | \item{n}{number of rows} 11 | 12 | \item{p}{number of columns} 13 | 14 | \item{sample_method}{sampling method} 15 | 16 | \item{f}{frequency for binomial sampling} 17 | } 18 | \value{ 19 | a binary matrix 20 | } 21 | \description{ 22 | Function creates binary matrix, to be used in aspect_importance method. It 23 | starts with a zero matrix. Then it replaces some zeros with ones. If 24 | \code{sample_method = "default"} it randomly replaces one or two zeros per 25 | row. If \code{sample_method = "binom"} it replaces random number of zeros 26 | per row - average number of replaced zeros can be controlled by parameter 27 | \code{sample_method = "f"}. Function doesn't allow the returned matrix to 28 | have rows with only zeros. 29 | } 30 | \examples{ 31 | get_sample(100,6,"binom",3) 32 | 33 | } 34 | -------------------------------------------------------------------------------- /man/group_variables.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/group_variables.R 3 | \name{group_variables} 4 | \alias{group_variables} 5 | \title{Helper function that combines clustering variables and creating aspect list} 6 | \usage{ 7 | group_variables(x, h, clust_method = "complete", cor_method = "spearman") 8 | } 9 | \arguments{ 10 | \item{x}{hclust object} 11 | 12 | \item{h}{correlation value for tree cutting} 13 | 14 | \item{clust_method}{the agglomeration method to be used 15 | see \code{\link[stats]{hclust}} methods} 16 | 17 | \item{cor_method}{the correlation method to be used 18 | see \code{\link[stats]{cor}} methods} 19 | } 20 | \value{ 21 | list with aspect 22 | } 23 | \description{ 24 | Divides correlated features into groups, called aspects. Division is based on 25 | correlation cutoff level. 26 | } 27 | \examples{ 28 | library("DALEX") 29 | dragons_data <- dragons[,c(2,3,4,7,8)] 30 | group_variables(dragons_data, h = 0.5, clust_method = "complete") 31 | 32 | } 33 | -------------------------------------------------------------------------------- /man/hierarchical_importance.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/hierarchical_importance.R 3 | \name{hierarchical_importance} 4 | \alias{hierarchical_importance} 5 | \alias{plot.hierarchical_importance} 6 | \title{Calculates importance of hierarchically grouped aspects} 7 | \usage{ 8 | hierarchical_importance( 9 | x, 10 | data, 11 | y = NULL, 12 | predict_function = predict, 13 | type = "predict", 14 | new_observation = NULL, 15 | N = 1000, 16 | loss_function = DALEX::loss_root_mean_square, 17 | B = 10, 18 | fi_type = c("raw", "ratio", "difference"), 19 | clust_method = "complete", 20 | cor_method = "spearman", 21 | ... 22 | ) 23 | 24 | \method{plot}{hierarchical_importance}( 25 | x, 26 | absolute_value = FALSE, 27 | show_labels = TRUE, 28 | add_last_group = TRUE, 29 | axis_lab_size = 10, 30 | text_size = 3, 31 | ... 32 | ) 33 | } 34 | \arguments{ 35 | \item{x}{a model to be explained.} 36 | 37 | \item{data}{dataset 38 | NOTE: Target variable shouldn't be present in the \code{data}} 39 | 40 | \item{y}{true labels for \code{data}} 41 | 42 | \item{predict_function}{predict function} 43 | 44 | \item{type}{if \code{predict} then aspect_importance is used, if 45 | \code{model} than feature_importance is calculated} 46 | 47 | \item{new_observation}{selected observation with columns that corresponds to 48 | variables used in the model, should be without target variable} 49 | 50 | \item{N}{number of rows to be sampled from data 51 | NOTE: Small \code{N} may cause unstable results.} 52 | 53 | \item{loss_function}{a function that will be used to assess variable 54 | importance, if \code{type = model}} 55 | 56 | \item{B}{integer, number of permutation rounds to perform on each variable 57 | in feature importance calculation, if \code{type = model}} 58 | 59 | \item{fi_type}{character, type of transformation that should be applied for 60 | dropout loss, if \code{type = model}. "raw" results raw drop losses, 61 | "ratio" returns \code{drop_loss/drop_loss_full_model}.} 62 | 63 | \item{clust_method}{the agglomeration method to be used, see 64 | \code{\link[stats]{hclust}} methods} 65 | 66 | \item{cor_method}{the correlation method to be used see 67 | \code{\link[stats]{cor}} methods} 68 | 69 | \item{...}{other parameters} 70 | 71 | \item{absolute_value}{if TRUE, aspects importance values will be drawn as 72 | absolute values} 73 | 74 | \item{show_labels}{if TRUE, plot will have annotated axis Y} 75 | 76 | \item{add_last_group}{if TRUE, plot will draw connecting line between last 77 | two groups} 78 | 79 | \item{axis_lab_size}{size of labels on axis Y, if applicable} 80 | 81 | \item{text_size}{size of labels annotating values of aspects importance} 82 | } 83 | \value{ 84 | ggplot 85 | } 86 | \description{ 87 | This function creates a tree that shows order of feature grouping and 88 | calculates importance of every newly created aspect. 89 | } 90 | \examples{ 91 | library(DALEX) 92 | apartments_num <- apartments[,unlist(lapply(apartments, is.numeric))] 93 | apartments_num_lm_model <- lm(m2.price ~ ., data = apartments_num) 94 | hi <- hierarchical_importance(x = apartments_num_lm_model, 95 | data = apartments_num[,-1], 96 | y = apartments_num[,1], 97 | type = "model") 98 | plot(hi, add_last_group = TRUE, absolute_value = TRUE) 99 | 100 | } 101 | -------------------------------------------------------------------------------- /man/list_variables.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/group_variables.R 3 | \name{list_variables} 4 | \alias{list_variables} 5 | \title{Cuts tree at custom height and returns a list} 6 | \usage{ 7 | list_variables(x, h) 8 | } 9 | \arguments{ 10 | \item{x}{hclust object} 11 | 12 | \item{h}{correlation value for tree cutting} 13 | } 14 | \value{ 15 | list of aspects 16 | } 17 | \description{ 18 | This function creates aspect list after cutting a cluster tree of features 19 | at a given height. 20 | } 21 | \examples{ 22 | library("DALEX") 23 | dragons_data <- dragons[,c(2,3,4,7,8)] 24 | cv <- cluster_variables(dragons_data, clust_method = "complete") 25 | list_variables(cv, h = 0.5) 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/plot.aspect_importance.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/aspect_importance.R 3 | \name{plot.aspect_importance} 4 | \alias{plot.aspect_importance} 5 | \title{Function for plotting aspect_importance results} 6 | \usage{ 7 | \method{plot}{aspect_importance}( 8 | x, 9 | ..., 10 | bar_width = 10, 11 | show_features = aspects_on_axis, 12 | aspects_on_axis = TRUE, 13 | add_importance = FALSE, 14 | digits_to_round = 2, 15 | text_size = 3 16 | ) 17 | } 18 | \arguments{ 19 | \item{x}{object of aspect_importance class} 20 | 21 | \item{...}{other parameters} 22 | 23 | \item{bar_width}{bar width} 24 | 25 | \item{show_features}{if TRUE, labels on axis Y show aspect names, otherwise 26 | they show features names} 27 | 28 | \item{aspects_on_axis}{alias for \code{show_features} held for backwards 29 | compatibility} 30 | 31 | \item{add_importance}{if TRUE, plot is annotated with values of aspects 32 | importance} 33 | 34 | \item{digits_to_round}{integer indicating the number of decimal places used 35 | for rounding values of aspects importance shown on the plot} 36 | 37 | \item{text_size}{size of labels annotating values of aspects importance, 38 | if applicable} 39 | } 40 | \value{ 41 | a ggplot2 object 42 | } 43 | \description{ 44 | This function plots the results of aspect_importance. 45 | } 46 | \examples{ 47 | library("DALEX") 48 | 49 | model_titanic_glm <- glm(survived == 1 ~ 50 | class+gender+age+sibsp+parch+fare+embarked, 51 | data = titanic_imputed, 52 | family = "binomial") 53 | 54 | explain_titanic_glm <- explain(model_titanic_glm, 55 | data = titanic_imputed[,-8], 56 | y = titanic_imputed$survived == 1, 57 | verbose = FALSE) 58 | 59 | aspects <- list(wealth = c("class", "fare"), 60 | family = c("sibsp", "parch"), 61 | personal = c("gender", "age"), 62 | embarked = "embarked") 63 | 64 | titanic_ai <- predict_aspects(explain_titanic_glm, 65 | new_observation = titanic_imputed[1,], 66 | variable_groups = aspects) 67 | plot(titanic_ai) 68 | 69 | } 70 | -------------------------------------------------------------------------------- /man/plot.cluster_variables.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/group_variables.R 3 | \name{plot.cluster_variables} 4 | \alias{plot.cluster_variables} 5 | \title{Plots tree with correlation values} 6 | \usage{ 7 | \method{plot}{cluster_variables}(x, p = NULL, show_labels = TRUE, axis_lab_size = 10, text_size = 3, ...) 8 | } 9 | \arguments{ 10 | \item{x}{\code{cluster_variables} or \code{hclust} object} 11 | 12 | \item{p}{correlation value for cutoff level, if not NULL, cutoff line will 13 | be drawn} 14 | 15 | \item{show_labels}{if TRUE, plot will have annotated axis Y} 16 | 17 | \item{axis_lab_size}{size of labels on axis Y, if applicable} 18 | 19 | \item{text_size}{size of labels annotating values of correlations} 20 | 21 | \item{...}{other parameters} 22 | } 23 | \value{ 24 | plot 25 | } 26 | \description{ 27 | Plots tree that illustrates the results of cluster_variables function. 28 | } 29 | \examples{ 30 | library("DALEX") 31 | dragons_data <- dragons[,c(2,3,4,7,8)] 32 | cv <- cluster_variables(dragons_data, clust_method = "complete") 33 | plot(cv, p = 0.7) 34 | 35 | } 36 | -------------------------------------------------------------------------------- /man/plot.triplot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/triplot.R 3 | \name{plot.triplot} 4 | \alias{plot.triplot} 5 | \title{Plots triplot} 6 | \usage{ 7 | \method{plot}{triplot}( 8 | x, 9 | absolute_value = FALSE, 10 | add_importance_labels = FALSE, 11 | show_model_label = FALSE, 12 | abbrev_labels = 0, 13 | add_last_group = TRUE, 14 | axis_lab_size = 10, 15 | text_size = 3, 16 | bar_width = 5, 17 | margin_mid = 0.3, 18 | ... 19 | ) 20 | } 21 | \arguments{ 22 | \item{x}{triplot object} 23 | 24 | \item{absolute_value}{if TRUE, aspect importance values will be drawn as 25 | absolute values} 26 | 27 | \item{add_importance_labels}{if TRUE, first plot is annotated with values of 28 | aspects importance on the bars} 29 | 30 | \item{show_model_label}{if TRUE, adds subtitle with model label} 31 | 32 | \item{abbrev_labels}{if greater than 0, labels for axis Y in single aspect 33 | importance plot will be abbreviated according to this parameter} 34 | 35 | \item{add_last_group}{if TRUE and \code{type = predict}, plot will 36 | draw connecting line between last two groups at the level of 105% of the 37 | biggest importance value, for \code{model} this line is always drawn at 38 | the baseline value} 39 | 40 | \item{axis_lab_size}{size of labels on axis} 41 | 42 | \item{text_size}{size of labels annotating values of aspects importance and 43 | correlations} 44 | 45 | \item{bar_width}{bar width in the first plot} 46 | 47 | \item{margin_mid}{size of a right margin of a middle plot} 48 | 49 | \item{...}{other parameters} 50 | } 51 | \value{ 52 | plot 53 | } 54 | \description{ 55 | Plots triplot that sum up automatic aspect/feature importance grouping 56 | } 57 | \examples{ 58 | library(DALEX) 59 | set.seed(123) 60 | apartments_num <- apartments[,unlist(lapply(apartments, is.numeric))] 61 | apartments_num_lm_model <- lm(m2.price ~ ., data = apartments_num) 62 | apartments_num_new_observation <- apartments_num[30, ] 63 | explainer_apartments <- explain(model = apartments_num_lm_model, 64 | data = apartments_num[,-1], 65 | y = apartments_num[, 1], 66 | verbose = FALSE) 67 | apartments_tri <- calculate_triplot(x = explainer_apartments, 68 | new_observation = apartments_num_new_observation[-1]) 69 | plot(apartments_tri) 70 | 71 | } 72 | -------------------------------------------------------------------------------- /man/print.aspect_importance.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/aspect_importance.R 3 | \name{print.aspect_importance} 4 | \alias{print.aspect_importance} 5 | \title{Function for printing aspect_importance results} 6 | \usage{ 7 | \method{print}{aspect_importance}(x, show_features = FALSE, show_corr = FALSE, ...) 8 | } 9 | \arguments{ 10 | \item{x}{object of aspect_importance class} 11 | 12 | \item{show_features}{show list of features for every aspect} 13 | 14 | \item{show_corr}{show if all features in aspect are pairwise positively 15 | correlated (for numeric features only)} 16 | 17 | \item{...}{other parameters} 18 | } 19 | \description{ 20 | This function prints the results of aspect_importance. 21 | } 22 | \examples{ 23 | library("DALEX") 24 | 25 | model_titanic_glm <- glm(survived == 1 ~ 26 | class+gender+age+sibsp+parch+fare+embarked, 27 | data = titanic_imputed, 28 | family = "binomial") 29 | 30 | explain_titanic_glm <- explain(model_titanic_glm, 31 | data = titanic_imputed[,-8], 32 | y = titanic_imputed$survived == 1, 33 | verbose = FALSE) 34 | 35 | aspects <- list(wealth = c("class", "fare"), 36 | family = c("sibsp", "parch"), 37 | personal = c("gender", "age"), 38 | embarked = "embarked") 39 | 40 | titanic_ai <- predict_aspects(explain_titanic_glm, 41 | new_observation = titanic_imputed[1,], 42 | variable_groups = aspects) 43 | print(titanic_ai) 44 | 45 | } 46 | -------------------------------------------------------------------------------- /misc/cheatsheet_code.R: -------------------------------------------------------------------------------- 1 | library(DALEX) 2 | library(triplot) 3 | 4 | # prepare data ------------------------------------------------------------ 5 | 6 | # excluding non numeric features and building model 7 | 8 | apartments_num <- apartments[,unlist(lapply(apartments, is.numeric))] 9 | apartments_no_target <- apartments_num[,-1] 10 | model_ap <- lm(m2.price ~ ., data = apartments_num) 11 | 12 | # predict aspects --------------------------------------------------------- 13 | 14 | set.seed(200) 15 | 16 | explainer <- explain(model_ap, data = apartments_num) 17 | 18 | aspects <- list( 19 | living.area = c("surface", "no.rooms"), 20 | construction.year = "construction.year", 21 | floor = "floor") 22 | 23 | new_apartment <- data.frame(construction.year = 1985, 24 | surface = 25, 25 | floor = 3, 26 | no.rooms = 1) 27 | 28 | pa <- predict_aspects( 29 | x = explainer, 30 | new_observation = new_apartment, 31 | variable_groups = aspects) 32 | 33 | print(pa, show_features = TRUE) 34 | plot(pa) 35 | 36 | 37 | # triplots ---------------------------------------------------------------- 38 | 39 | set.seed(200) 40 | 41 | explainer <- explain(model_ap, 42 | data = apartments_no_target, 43 | y = apartments_num$m2.price) 44 | 45 | triplot <- model_triplot(explainer) 46 | plot(triplot) 47 | 48 | triplot <- predict_triplot(explainer, 49 | new_observation = new_apartment) 50 | plot(triplot) 51 | 52 | 53 | # group variables --------------------------------------------------------- 54 | 55 | group_variables(apartments_num, h = 0.5) 56 | 57 | 58 | -------------------------------------------------------------------------------- /misc/medium_example.R: -------------------------------------------------------------------------------- 1 | library("DALEX") 2 | data(fifa) 3 | fifa$value_eur <- fifa$value_eur/10^6 4 | fifa[, c("nationality", "overall", "potential", 5 | "wage_eur")] <- NULL 6 | 7 | library("dplyr") 8 | fifa_subset <- fifa %>% 9 | select(matches('goalkeeping|skill')) 10 | 11 | library("corrplot") 12 | corrplot(cor(fifa_subset), 13 | method = "color", type = "upper", order = "hclust", 14 | addCoef.col = "black",number.cex = .7, diag = FALSE) 15 | 16 | library("ranger") 17 | set.seed(2020) 18 | fifa_model <- ranger(value_eur~., data = fifa) 19 | fifa_explainer <- DALEX::explain(fifa_model, 20 | data = fifa[,-1], 21 | y = fifa$value_eur, 22 | label = "Random Forest", 23 | verbose = FALSE) 24 | 25 | library("triplot") 26 | fifa_triplot_global <- model_triplot(fifa_explainer, 27 | B = 1, 28 | N = 5000, 29 | cor_method = "pearson") 30 | plot(fifa_triplot_global, margin_mid = 0) 31 | 32 | -------------------------------------------------------------------------------- /misc/medium_example_part2.R: -------------------------------------------------------------------------------- 1 | # read data --------------------------------------------------------------- 2 | 3 | library("DALEX") 4 | data(fifa) 5 | fifa$value_eur <- fifa$value_eur/10^6 6 | fifa[, c("nationality", "overall", "potential", 7 | "wage_eur")] <- NULL 8 | 9 | # create model ------------------------------------------------------------ 10 | 11 | library("ranger") 12 | set.seed(2020) 13 | fifa_model_rf <- ranger(value_eur~., data = fifa) 14 | fifa_expl_rf <- DALEX::explain(fifa_model_rf, 15 | data = fifa[,-1], 16 | y = fifa$value_eur, 17 | label = "Random Forest") 18 | 19 | # select player ----------------------------------------------------------- 20 | 21 | top_player <- fifa[order(fifa$value_eur, decreasing = TRUE),][1,] 22 | 23 | 24 | # local triplot ----------------------------------------------------------- 25 | 26 | fifa_triplot_local <- predict_triplot(fifa_explainer, top_player, 27 | N = 5000, 28 | cor_method = "pearson") 29 | plot(fifa_triplot_local) 30 | 31 | # build second model ------------------------------------------------------ 32 | 33 | library("gbm") 34 | fifa_model_gbm <- gbm(value_eur ~ ., data = fifa, 35 | n.trees = 250, 36 | interaction.depth = 4, 37 | distribution = "gaussian") 38 | fifa_expl_gbm <- DALEX::explain(fifa_model_gbm, 39 | data = fifa[,-1], 40 | y = fifa$value_eur, 41 | label = "Gradient Boosting") 42 | 43 | # analyze predictions with predict_aspects -------------------------------- 44 | 45 | top_player$value_eur 46 | fifa_expl_rf$y_hat[order(fifa$value_eur, decreasing = TRUE)[1]] 47 | fifa_expl_gbm$y_hat[order(fifa$value_eur, decreasing = TRUE)[1]] 48 | 49 | fifa_aspects <- list( 50 | "age" = "age", 51 | "body" = c("height_cm", "weight_kg"), 52 | "attacking" = c("attacking_crossing", 53 | "attacking_finishing", 54 | "attacking_heading_accuracy", 55 | "attacking_short_passing", 56 | "attacking_volleys"), 57 | "skill" = c("skill_dribbling", 58 | "skill_curve", "skill_fk_accuracy", 59 | "skill_long_passing", 60 | "skill_ball_control"), 61 | "movement" = c("movement_acceleration", "movement_sprint_speed", 62 | "movement_agility", "movement_reactions", 63 | "movement_balance"), 64 | "power" = c("power_shot_power", "power_jumping", "power_stamina", 65 | "power_strength", "power_long_shots"), 66 | "mentality" = c("mentality_aggression", "mentality_interceptions", 67 | "mentality_positioning", "mentality_vision", 68 | "mentality_penalties", "mentality_composure"), 69 | "defending" = c("defending_marking", "defending_standing_tackle", 70 | "defending_sliding_tackle"), 71 | "goalkeeping" = c("goalkeeping_diving", 72 | "goalkeeping_handling", "goalkeeping_kicking", 73 | "goalkeeping_positioning", 74 | "goalkeeping_reflexes")) 75 | 76 | fifa_pa_rf <- predict_aspects(fifa_expl_rf, 77 | new_observation = top_player, 78 | variable_groups = fifa_aspects) 79 | 80 | fifa_pa_gbm <- predict_aspects(fifa_expl_gbm, 81 | new_observation = top_player, 82 | variable_groups = fifa_aspects) 83 | 84 | plot(fifa_pa_rf, fifa_pa_gbm) 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /misc/triplot_cheatsheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/misc/triplot_cheatsheet.pdf -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/pkgdown/favicon/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/pkgdown/favicon/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/pkgdown/favicon/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/pkgdown/favicon/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/pkgdown/favicon/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/pkgdown/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/pkgdown/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/pkgdown/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModelOriented/triplot/a9721315b13228ecf6998125c3c36be188d9355b/pkgdown/favicon/favicon.ico -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(triplot) 3 | 4 | test_check("triplot") 5 | -------------------------------------------------------------------------------- /tests/testthat/helper-objects.R: -------------------------------------------------------------------------------- 1 | library("DALEX") 2 | 3 | # titanic ----------------------------------------------------------------- 4 | 5 | titanic_data <- DALEX::titanic_imputed 6 | 7 | titanic_glm_model <- glm(survived == 1 ~ class + gender + age + sibsp + 8 | parch + fare + embarked, 9 | titanic_data, family = "binomial") 10 | 11 | titanic_new_observation <- data.frame( 12 | class = factor("1st", levels = c("1st", "2nd", "3rd", "deck crew", 13 | "engineering crew", "restaurant staff", 14 | "victualling crew")), 15 | gender = factor("male", levels = c("female", "male")), 16 | age = 8, 17 | sibsp = 0, 18 | parch = 0, 19 | fare = 72, 20 | embarked = factor("Southampton", levels = c("Belfast","Cherbourg", 21 | "Queenstown","Southampton")) 22 | ) 23 | 24 | titanic_aspects <- list(wealth = c("class", "fare"), 25 | family = c("gender", "sibsp", "parch"), 26 | age = "age", 27 | embarked = "embarked") 28 | 29 | # apartments -------------------------------------------------------------- 30 | 31 | apartments_data <- DALEX::apartments 32 | 33 | apartments_lm_model <- lm(m2.price ~ ., data = apartments_data) 34 | apartments_aspects <- list(space = c("surface", "no.rooms"), 35 | construction.year = "construction.year", 36 | floor = "floor", 37 | district = "district") 38 | apartments_new_observation <- DALEX::apartments_test[30,] 39 | apartments_num <- apartments_data[,unlist(lapply(apartments_data, is.numeric))] 40 | apartments_num_lm_model <- lm(m2.price ~ ., data = apartments_num) 41 | apartments_num_new_observation <- apartments_num[30, ] 42 | apartments_explain <- explain(model = apartments_num_lm_model, 43 | data = apartments_num[,-1], 44 | y = apartments_num[, 1], 45 | verbose = FALSE) 46 | -------------------------------------------------------------------------------- /tests/testthat/test_aspect_importance_single.R: -------------------------------------------------------------------------------- 1 | context("Check aspect_importance_single() functions") 2 | 3 | test_that("check aspect_importance_single function",{ 4 | library("DALEX") 5 | library("triplot") 6 | 7 | aspect_importance_titanic_single <- 8 | aspect_importance_single(x = apartments_lm_model, 9 | data = 10 | apartments[, colnames(apartments) != "m2.price"], 11 | new_observation = apartments_new_observation) 12 | 13 | expect_true("data.frame" %in% class(aspect_importance_titanic_single)) 14 | expect_true(dim(aspect_importance_titanic_single)[1] == 5) 15 | expect_true(dim(aspect_importance_titanic_single)[2] == 5) 16 | 17 | }) 18 | 19 | test_that("check aspect_importance_single.explainer function",{ 20 | library("DALEX") 21 | library("triplot") 22 | 23 | titanic_without_target <- titanic_data[,colnames(titanic_data)!="survived"] 24 | 25 | titanic_explainer <- explain(model = titanic_glm_model, 26 | data = titanic_without_target, 27 | verbose = FALSE) 28 | 29 | aspect_importance_titanic_glm_single <- 30 | aspect_importance_single(titanic_explainer, 31 | new_observation = titanic_new_observation) 32 | 33 | expect_true("data.frame" %in% class(aspect_importance_titanic_glm_single)) 34 | 35 | }) 36 | -------------------------------------------------------------------------------- /tests/testthat/test_group_variables.R: -------------------------------------------------------------------------------- 1 | context("Check group_variables() functions") 2 | 3 | test_that("check cluster_variables function",{ 4 | library("DALEX") 5 | library("triplot") 6 | 7 | cv <- cluster_variables(apartments_num, clust_method = "single") 8 | 9 | expect_true(length(cv$labels) == 5) 10 | expect_true("cluster_variables" %in% class(cv)) 11 | expect_true("hclust" %in% class(cv)) 12 | 13 | }) 14 | 15 | test_that("check plot.cluster_variables function",{ 16 | library("DALEX") 17 | library("triplot") 18 | 19 | cv <- cluster_variables(apartments_num, clust_method = "single") 20 | p <- plot(cv, p = 0.5) 21 | 22 | expect_true("ggplot" %in% class(p)) 23 | expect_error(plot(p), NA) 24 | 25 | }) 26 | 27 | test_that("check list_variables function",{ 28 | library("DALEX") 29 | library("triplot") 30 | 31 | cv <- cluster_variables(apartments_num, clust_method = "single") 32 | aspect_list <- list_variables(cv, 0.6) 33 | one_aspect <- list_variables(cv, 0) 34 | 35 | expect_true(class(aspect_list) == "list") 36 | expect_true(length(aspect_list) == 4) 37 | expect_true(length(one_aspect) == 1) 38 | expect_true("surface" %in% aspect_list$aspect.group3) 39 | 40 | }) 41 | 42 | test_that("check group_variables function",{ 43 | library("DALEX") 44 | library("triplot") 45 | 46 | aspect_list <- group_variables(x = apartments_num, h = 0.6, 47 | clust_method = "single") 48 | 49 | expect_true(class(aspect_list) == "list") 50 | 51 | }) 52 | -------------------------------------------------------------------------------- /tests/testthat/test_hierarchical_importance.R: -------------------------------------------------------------------------------- 1 | context("Check hierarchical_importance() functions") 2 | 3 | test_that("check hierarchical_importance function for aspects_importance",{ 4 | library("DALEX") 5 | library("triplot") 6 | 7 | hi <- hierarchical_importance(x = apartments_num_lm_model, 8 | data = apartments_num[,-1], 9 | new_observation = 10 | apartments_num_new_observation[-1]) 11 | 12 | expect_true("hclust" %in% class(hi[[1]])) 13 | expect_true("hierarchical_importance" %in% class(hi)) 14 | expect_true("floor" %in% hi[[1]]$labels) 15 | }) 16 | 17 | test_that("check hierarchical_importance function for feature_importance",{ 18 | library("DALEX") 19 | library("triplot") 20 | 21 | hi <- hierarchical_importance(x = apartments_num_lm_model, 22 | data = apartments_num[,-1], 23 | y = apartments_num[,1], 24 | type = "model") 25 | 26 | expect_true("hierarchical_importance" %in% class(hi)) 27 | expect_true("floor" %in% hi[[1]]$labels) 28 | }) 29 | 30 | 31 | test_that("check plot.hierarchical_importance function",{ 32 | library("DALEX") 33 | library("triplot") 34 | 35 | hi <- hierarchical_importance(x = apartments_num_lm_model, 36 | data = apartments_num[,-1], 37 | new_observation = 38 | apartments_num_new_observation[-1]) 39 | 40 | p <- plot(hi, add_last_group = TRUE, 41 | absolute_value = TRUE) 42 | 43 | expect_true("ggplot" %in% class(p)) 44 | }) 45 | 46 | test_that("check for hierarchical_importance error",{ 47 | library("DALEX") 48 | library("triplot") 49 | 50 | expect_error(hierarchical_importance(x = apartments_num_lm_model, 51 | data = apartments_num[,-1], 52 | type = "model")) 53 | }) 54 | -------------------------------------------------------------------------------- /tests/testthat/test_triplot.R: -------------------------------------------------------------------------------- 1 | context("Check triplot() functions") 2 | 3 | test_that("check calculate_triplot.default function",{ 4 | library("DALEX") 5 | library("triplot") 6 | 7 | apartments_tri <- calculate_triplot(x = apartments_num_lm_model, 8 | data = apartments_num[,-1], 9 | y = apartments_num[, 1], 10 | new_observation = 11 | apartments_num_new_observation[-1]) 12 | expect_true("list" %in% class(apartments_tri)) 13 | }) 14 | 15 | 16 | 17 | test_that("check calculate_triplot.explainer function",{ 18 | library("DALEX") 19 | library("triplot") 20 | 21 | apartments_tri <- calculate_triplot(x = apartments_explain, 22 | new_observation = 23 | apartments_num_new_observation[-1]) 24 | 25 | expect_true("list" %in% class(apartments_tri)) 26 | }) 27 | 28 | test_that("check print of triplot",{ 29 | library("DALEX") 30 | library("triplot") 31 | 32 | apartments_tri <- calculate_triplot(x = apartments_explain, 33 | new_observation = 34 | apartments_num_new_observation[-1]) 35 | apartments_tri_fi <- calculate_triplot(x = apartments_num_lm_model, 36 | data = apartments_num[,-1], 37 | y = apartments_num[, 1], 38 | type = "model") 39 | expect_output(print(apartments_tri), "Triplot object") 40 | expect_output(print(apartments_tri_fi), "Triplot object") 41 | }) 42 | 43 | test_that("check warning in calculate_triplot.explainer",{ 44 | library("DALEX") 45 | library("triplot") 46 | 47 | apartments_num_explain_2 <- explain(model = apartments_num_lm_model, 48 | data = apartments_num, 49 | y = apartments_num[, 1], 50 | verbose = FALSE) 51 | 52 | expect_warning(calculate_triplot(apartments_num_explain_2, 53 | new_observation = 54 | apartments_num_new_observation)) 55 | 56 | }) 57 | 58 | test_that("check calculate_triplot.default function for FI",{ 59 | library("DALEX") 60 | library("triplot") 61 | 62 | apartments_tri <- calculate_triplot(x = apartments_num_lm_model, 63 | data = apartments_num[,-1], 64 | y = apartments_num[, 1], 65 | type = "model") 66 | expect_true("list" %in% class(apartments_tri)) 67 | }) 68 | 69 | test_that("check calculate_triplot.explainer function for FI",{ 70 | library("DALEX") 71 | library("triplot") 72 | apartments_tri <- calculate_triplot(x = apartments_explain, 73 | type = "model") 74 | 75 | expect_true("list" %in% class(apartments_tri)) 76 | }) 77 | 78 | 79 | test_that("check plot.calculate_triplot function",{ 80 | library("DALEX") 81 | library("triplot") 82 | 83 | apartments_tri <- calculate_triplot(x = apartments_explain, 84 | new_observation = 85 | apartments_num_new_observation[-1]) 86 | p <- plot(apartments_tri) 87 | 88 | p2 <- plot(apartments_tri, 89 | abbrev_labels = 5, 90 | text_size = 4, 91 | absolute_value = TRUE, 92 | add_importance_labels = TRUE, 93 | show_model_label = TRUE, 94 | add_last_group = FALSE, 95 | axis_lab_size = 4, 96 | bar_width = 3, 97 | margin_mid = 0.1) 98 | 99 | expect_true("patchwork" %in% class(p)) 100 | expect_true("gg" %in% class(p)) 101 | expect_true("ggplot" %in% class(p2)) 102 | expect_error(plot(p), NA) 103 | expect_error(plot(p2), NA) 104 | }) 105 | 106 | test_that("check plot.calculate_triplot function for FI",{ 107 | library("DALEX") 108 | library("triplot") 109 | 110 | apartments_tri <- calculate_triplot(x = apartments_explain, 111 | type = "model") 112 | p <- plot(apartments_tri, 113 | abbrev_labels = 5) 114 | 115 | p2 <- plot(apartments_tri, 116 | add_last_group = FALSE) 117 | 118 | 119 | expect_true("patchwork" %in% class(p)) 120 | expect_true("gg" %in% class(p)) 121 | expect_true("ggplot" %in% class(p2)) 122 | expect_error(plot(p), NA) 123 | expect_error(plot(p2), NA) 124 | 125 | }) 126 | 127 | test_that("",{ 128 | library("DALEX") 129 | library("triplot") 130 | 131 | apartments_tri <- calculate_triplot(x = apartments_explain, 132 | type = "model") 133 | 134 | expect_true(dim(apartments_tri[[1]])[1] == 66) 135 | expect_true(class(apartments_tri[[2]]) == "hierarchical_importance") 136 | expect_true("hclust" %in% class(apartments_tri[[3]])) 137 | expect_true(apartments_tri[[5]] == "model") 138 | 139 | }) 140 | 141 | 142 | test_that("check triplot aliases",{ 143 | library("DALEX") 144 | library("triplot") 145 | 146 | apartments_tri_model <- model_triplot(x = apartments_explain) 147 | 148 | apartments_tri_predict <- predict_triplot(x = apartments_explain, 149 | new_observation = 150 | apartments_num_new_observation[-1]) 151 | 152 | expect_true("triplot" %in% class(apartments_tri_model)) 153 | expect_true("triplot" %in% class(apartments_tri_predict)) 154 | 155 | }) 156 | 157 | test_that("check for triplot error",{ 158 | library("DALEX") 159 | library("triplot") 160 | 161 | expect_error(predict_triplot(x = apartments_explain)) 162 | 163 | 164 | }) 165 | 166 | -------------------------------------------------------------------------------- /vignettes/vignette_aspect_importance_fifa.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Usecase with FIFA 20 dataset" 3 | author: "Katarzyna Pękala" 4 | date: "`r Sys.Date()`" 5 | output: rmarkdown::html_document 6 | vignette: > 7 | %\VignetteIndexEntry{Usecase with FIFA 20 dataset} 8 | %\VignetteEncoding{UTF-8} 9 | %\VignetteEngine{knitr::rmarkdown} 10 | editor_options: 11 | chunk_output_type: inline 12 | --- 13 | 14 | ```{r setup, include = FALSE} 15 | knitr::opts_chunk$set( 16 | collapse = FALSE, 17 | comment = "#>", 18 | warning = FALSE, 19 | message = FALSE, 20 | fig.align = 'center', 21 | fig.width = 12, 22 | fig.height = 8 23 | ) 24 | 25 | ``` 26 | 27 | 28 | # Data 29 | 30 | This vignette demonstrates the use of the triplot package on Fifa20 dataset. Dataset was downloaded from the Kaggle website, preprocessed and made available in DALEX package. 31 | 32 | Dataset contains 37 features that describe each player performance. We will be exploring models that are predicting players value in Euro (in millions). 33 | 34 | 35 | ```{r} 36 | library("DALEX") 37 | library("triplot") 38 | 39 | data(fifa) 40 | 41 | fifa$value_eur <- fifa$value_eur/10^6 42 | 43 | fifa[, c("nationality", "overall", "potential", 44 | "wage_eur")] <- NULL 45 | 46 | head(fifa[,c(1:6)]) 47 | 48 | ``` 49 | 50 | # Build models for predicting players value 51 | 52 | For the further analysis, we prepare 3 models: 53 | 54 | * random forest, 55 | * tuned random forest, 56 | * gradient boosting machine. 57 | 58 | 59 | ```{r} 60 | library("ranger") 61 | library("gbm") 62 | 63 | fifa_rf <- ranger(value_eur~., data = fifa) 64 | 65 | fifa_rf_mod <- ranger(value_eur~., data = fifa, 66 | mtry = 18, splitrule = "variance", min.node.size = 5) 67 | 68 | fifa_gbm <- gbm(value_eur~., data = fifa, n.trees = 250, 69 | interaction.depth = 4, distribution = "gaussian") 70 | 71 | ``` 72 | 73 | # Build explainers 74 | 75 | For each of those models, we build DALEX explainer. Using explainers, simplifies further models analysis. 76 | 77 | 78 | ```{r} 79 | 80 | fifa_rf_exp <- DALEX::explain(fifa_rf, 81 | data = fifa[,-1], #without target coulmn 82 | y = fifa$value_eur, 83 | label = "RF", 84 | verbose = FALSE) 85 | 86 | fifa_rf_m_exp <- DALEX::explain(fifa_rf_mod, 87 | data = fifa[,-1], 88 | y = fifa$value_eur, 89 | label = "RF tuned", 90 | verbose = FALSE) 91 | 92 | fifa_gbm_exp <- DALEX::explain(fifa_gbm, 93 | data = fifa[, -1], 94 | y = fifa$value_eur, 95 | predict_function = 96 | function(m, x) 97 | predict(m, x, n.trees = 250), 98 | label = "GBM", 99 | verbose = FALSE) 100 | 101 | ``` 102 | 103 | # Triplot for model 104 | 105 | 'Triplot' objects allow us to investigate the importance of each feature (plot on the left), features correlation (plot on the right) as well as the change hierarchical aspects importance (plot in the middle). 106 | 107 | ```{r} 108 | 109 | fifa_rf_tri <- model_triplot(fifa_rf_exp, B = 1, N = 5000) 110 | 111 | fifa_rf_m_tri <- model_triplot(fifa_rf_m_exp, B = 1, N = 5000) 112 | 113 | fifa_gbm_tri <- model_triplot(fifa_gbm_exp, B = 1, N = 5000) 114 | 115 | plot(fifa_rf_tri, show_model_label = TRUE, margin_mid = 0) 116 | 117 | plot(fifa_rf_m_tri, show_model_label = TRUE, margin_mid = 0) 118 | 119 | plot(fifa_gbm_tri, show_model_label = TRUE, margin_mid = 0) 120 | 121 | ``` 122 | 123 | 124 | ```{r} 125 | 126 | fifa_vg <- list( 127 | "age" = "age", 128 | "body" = c("height_cm", "weight_kg"), 129 | "attacking" = c("attacking_crossing", 130 | "attacking_finishing", "attacking_heading_accuracy", 131 | "attacking_short_passing", "attacking_volleys"), 132 | "skill" = c("skill_dribbling", 133 | "skill_curve", "skill_fk_accuracy", "skill_long_passing", 134 | "skill_ball_control"), 135 | "movement" = c("movement_acceleration", "movement_sprint_speed", 136 | "movement_agility", "movement_reactions", "movement_balance"), 137 | "power" = c("power_shot_power", "power_jumping", "power_stamina", "power_strength", 138 | "power_long_shots"), 139 | "mentality" = c("mentality_aggression", "mentality_interceptions", 140 | "mentality_positioning", "mentality_vision", "mentality_penalties", 141 | "mentality_composure"), 142 | "defending" = c("defending_marking", "defending_standing_tackle", 143 | "defending_sliding_tackle"), 144 | "goalkeeping" = c("goalkeeping_diving", 145 | "goalkeeping_handling", "goalkeeping_kicking", 146 | "goalkeeping_positioning", "goalkeeping_reflexes")) 147 | 148 | ``` 149 | 150 | # Investigate models for chosen instances (players) 151 | 152 | For the instance level model analysis, we choose top player (value wise). 153 | 154 | ```{r fig.height = 4} 155 | set.seed(123) 156 | 157 | top_player <- fifa[order(fifa$value_eur, decreasing = TRUE),][1,] 158 | 159 | print(top_player) 160 | 161 | aspects_top_player_rf <- predict_aspects(fifa_rf_exp, 162 | new_observation = top_player, 163 | variable_groups = fifa_vg) 164 | 165 | aspects_top_player_rf_m <- predict_aspects(fifa_rf_m_exp, 166 | new_observation = top_player, 167 | variable_groups = fifa_vg) 168 | 169 | aspects_top_player_gbm <- predict_aspects(fifa_gbm_exp, 170 | new_observation = top_player, 171 | variable_groups = fifa_vg) 172 | 173 | plot(aspects_top_player_rf, 174 | aspects_top_player_rf_m, 175 | aspects_top_player_gbm) 176 | 177 | ``` 178 | 179 | ```{r} 180 | fifa_rf_m_tri_player <- predict_triplot(fifa_rf_m_exp, top_player) 181 | 182 | plot(fifa_rf_m_tri_player, show_model_label = TRUE, margin_mid = 0.2) 183 | 184 | ``` 185 | 186 | 187 | For comparison, for next analysis we pick one of the goal keeper's prediction to be explained. 188 | 189 | ```{r fig.height = 4, fig.width = 8} 190 | set.seed(123) 191 | 192 | player_gk <- fifa["J. Oblak",] 193 | 194 | print(player_gk) 195 | 196 | aspects_gk_rf <- predict_aspects(fifa_rf_exp, 197 | new_observation = player_gk, 198 | variable_groups = fifa_vg) 199 | 200 | aspects_gk_rf_m <- predict_aspects(fifa_rf_m_exp, 201 | new_observation = player_gk, 202 | variable_groups = fifa_vg) 203 | 204 | aspects_gk_gbm <- predict_aspects(fifa_gbm_exp, 205 | new_observation = player_gk, 206 | variable_groups = fifa_vg) 207 | 208 | 209 | ``` 210 | 211 | ```{r fig.height = 4, fig.width = 12} 212 | 213 | plot(aspects_gk_rf, 214 | aspects_gk_rf_m, 215 | aspects_gk_gbm) 216 | ``` 217 | 218 | 219 | 220 | 221 | # Session info 222 | 223 | ```{r} 224 | sessionInfo() 225 | ``` 226 | 227 | --------------------------------------------------------------------------------