Skip to content

Commit

Permalink
Merge pull request #15 from Yue-Jiang/master
Browse files Browse the repository at this point in the history
prep for new cran release
  • Loading branch information
Yue-Jiang authored Sep 18, 2019
2 parents b35f4da + 555a2f6 commit e2fe27f
Show file tree
Hide file tree
Showing 50 changed files with 1,215 additions and 3,761 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ materials*
^_pkgdown\.yml$
^\.travis\.yml$
^cran-comments\.md$
^doc$
^Meta$
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.Rproj.user
.Rhistory
.RData
doc
Meta
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: randomForestExplainer
Title: Explaining and Visualizing Random Forests in Terms of Variable Importance
Version: 0.9
Version: 0.10.0
Authors@R: c(
person("Aleksandra", "Paluszynska", email = "[email protected]", role = c("aut")),
person("Przemyslaw", "Biecek", email = "[email protected]", role = c("aut","ths")),
Expand All @@ -18,13 +18,13 @@ Imports:
GGally (>= 1.3.0),
ggplot2 (>= 2.2.1),
ggrepel (>= 0.6.5),
MASS (>= 7.3.47),
randomForest (>= 4.6.12),
ranger(>= 0.9.0),
reshape2 (>= 1.4.2),
rmarkdown (>= 1.5)
Suggests:
knitr,
MASS (>= 7.3.47),
testthat
VignetteBuilder: knitr
RoxygenNote: 6.1.1
Expand Down
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# randomForestExplainer 0.10.0
## New features
* Added support for ranger forests.
* Added support for unsupervised randomForest.
* Added tests for most functions.

## Bug fixes
* Fixed bug for explain_forest not finding templates.
* Added more intuitive error message for explain_forest when local importance is absent.
3 changes: 2 additions & 1 deletion R/measure_importance.R
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ measure_importance.randomForest <- function(forest, mean_sample = "top_trees", m
}
forest_table <-
lapply(1:forest$ntree, function(i) randomForest::getTree(forest, k = i, labelVar = T) %>%
mutate_if(is.factor, as.character) %>%
calculate_tree_depth() %>% cbind(tree = i)) %>% rbindlist()
min_depth_frame <- dplyr::group_by(forest_table, tree, `split var`) %>%
dplyr::summarize(min(depth))
Expand Down Expand Up @@ -245,7 +246,7 @@ measure_importance.ranger <- function(forest, mean_sample = "top_trees", measure
#' @param importance_frame A result of using the function measure_importance() to a random forest or a randomForest object
#' @param measures A character vector specifying the measures of importance to be used
#' @param k The number of variables to extract
#' @param ties_action One of three: c("none", "all", "draw"); specifies which variables to pick when ties occur. When set to "none" we may get less than k variables, when "all" whe may get more and "draw" makes us get exactly k.
#' @param ties_action One of three: c("none", "all", "draw"); specifies which variables to pick when ties occur. When set to "none" we may get less than k variables, when "all" we may get more and "draw" makes us get exactly k.
#'
#' @return A character vector with names of k variables with highest sum of rankings
#'
Expand Down
5 changes: 3 additions & 2 deletions R/min_depth_distribution.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ calculate_tree_depth_ranger <- function(frame){
#' @return A data frame with the value of minimal depth for every variable in every tree
#'
#' @examples
#' min_depth_distribution(randomForest::randomForest(Species ~ ., data = iris))
#' min_depth_distribution(ranger::ranger(Species ~ ., data = iris))
#' min_depth_distribution(randomForest::randomForest(Species ~ ., data = iris, ntree = 100))
#' min_depth_distribution(ranger::ranger(Species ~ ., data = iris, num.trees = 100))
#'
#' @export
min_depth_distribution <- function(forest){
Expand All @@ -54,6 +54,7 @@ min_depth_distribution.randomForest <- function(forest){
tree <- NULL; `split var` <- NULL; depth <- NULL
forest_table <-
lapply(1:forest$ntree, function(i) randomForest::getTree(forest, k = i, labelVar = T) %>%
mutate_if(is.factor, as.character) %>%
calculate_tree_depth() %>% cbind(tree = i)) %>% rbindlist()
min_depth_frame <- dplyr::group_by(forest_table, tree, `split var`) %>%
dplyr::summarize(min(depth))
Expand Down
6 changes: 4 additions & 2 deletions R/min_depth_interactions.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ min_depth_interactions_values <- function(forest, vars){
`.` <- NULL; .SD <- NULL; tree <- NULL; `split var` <- NULL
interactions_frame <-
lapply(1:forest$ntree, function(i) randomForest::getTree(forest, k = i, labelVar = T) %>%
mutate_if(is.factor, as.character) %>%
calculate_tree_depth() %>% cbind(., tree = i, number = 1:nrow(.))) %>%
data.table::rbindlist() %>% as.data.frame()
interactions_frame[vars] <- as.numeric(NA)
Expand Down Expand Up @@ -109,11 +110,11 @@ min_depth_interactions_values_ranger <- function(forest, vars){
#' Calculate mean conditional minimal depth with respect to a vector of variables
#'
#' @param forest A randomForest object
#' @param vars A character vector with variables with respect to which conditional minimal depth will be calculated; by defalt it is extracted by the important_variables function but this may be time consuming
#' @param vars A character vector with variables with respect to which conditional minimal depth will be calculated; by default it is extracted by the important_variables function but this may be time consuming
#' @param mean_sample The sample of trees on which conditional mean minimal depth is calculated, possible values are "all_trees", "top_trees", "relevant_trees"
#' @param uncond_mean_sample The sample of trees on which unconditional mean minimal depth is calculated, possible values are "all_trees", "top_trees", "relevant_trees"
#'
#' @return A data frame with each observarion giving the means of conditional minimal depth and the size of sample for a given interaction
#' @return A data frame with each observation giving the means of conditional minimal depth and the size of sample for a given interaction
#'
#' @examples
#' forest <- randomForest::randomForest(Species ~ ., data = iris, ntree = 100)
Expand Down Expand Up @@ -164,6 +165,7 @@ min_depth_interactions.randomForest <- function(forest, vars = important_variabl
interactions_frame$interaction <- paste(interactions_frame$root_variable, interactions_frame$variable, sep = ":")
forest_table <-
lapply(1:forest$ntree, function(i) randomForest::getTree(forest, k = i, labelVar = T) %>%
mutate_if(is.factor, as.character) %>%
calculate_tree_depth() %>% cbind(tree = i)) %>% rbindlist()
min_depth_frame <- dplyr::group_by(forest_table, tree, `split var`) %>%
dplyr::summarize(min(depth))
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
[![codecov](https://codecov.io/gh/ModelOriented/randomForestExplainer/branch/master/graph/badge.svg)](https://codecov.io/gh/ModelOriented/randomForestExplainer)
[![DOI](https://zenodo.org/badge/97007621.svg)](https://zenodo.org/badge/latestdoi/97007621)

A set of tools to understand what is happening inside a Random Forest. A detailed discussion of the package and importance measures it implements can be found here: [Master thesis on randomForestExplainer](https://rawgit.com/geneticsMiNIng/BlackBoxOpener/master/randomForestExplainer_Master_thesis.pdf).
A set of tools to understand what is happening inside a Random Forest. A detailed discussion of the package and importance measures it implements can be found here: [Master thesis on randomForestExplainer](https://cdn.staticaly.com/gh/geneticsMiNIng/BlackBoxOpener/master/randomForestExplainer_Master_thesis.pdf).

## Instalation
## Installation

randomForestExplainer can be installed from [CRAN](https://cran.r-project.org/package=randomForestExplainer) as follows:

Expand All @@ -26,12 +26,12 @@ library(randomForestExplainer)

## Vignette

* [Understanding random forests with randomForestExplainer](https://rawgit.com/ModelOriented/randomForestExplainer/master/inst/doc/randomForestExplainer.html)
* [Understanding random forests with randomForestExplainer](https://modeloriented.github.io/randomForestExplainer/articles/randomForestExplainer.html)

## Cheatsheets

* [A one-page summary](https://github.com/ModelOriented/randomForestExplainer/blob/master/materials/cheatsheet.pdf)

## Examples

* [Initial vignette for glioblastoma data](https://rawgit.com/geneticsMiNIng/BlackBoxOpener/master/randomForestExplainer/inst/doc/randomForestExplainer.html)
* [Initial vignette for glioblastoma data](https://cdn.staticaly.com/gh/geneticsMiNIng/BlackBoxOpener/master/randomForestExplainer/inst/doc/randomForestExplainer.html)
22 changes: 22 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Test environments
* local OS X install, R 3.6.1
* ubuntu 16.04 (on travis-ci, devel and release)
* win-builder (devel and release)

## R CMD check results
There were no ERRORs or WARNINGs.

There was one NOTE:
```
* checking CRAN incoming feasibility ... NOTE
Maintainer: 'Yue Jiang <[email protected]>'
New maintainer:
Yue Jiang <[email protected]>
Old maintainer(s):
Aleksandra Paluszynska <[email protected]>
```
The maintainer role has been passed along to Yue Jiang and this is correct.

## Downstream dependencies
There are no downstream dependencies at this time.
19 changes: 13 additions & 6 deletions docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions docs/articles/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e2fe27f

Please sign in to comment.