-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkgdown.yaml and R-CMD-check.yaml scripts are commented out
- Loading branch information
1 parent
c8fd12e
commit 328ff88
Showing
8 changed files
with
839 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,50 @@ | ||
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples | ||
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help | ||
on: | ||
push: | ||
branches: [main, master] | ||
pull_request: | ||
branches: [main, master] | ||
release: | ||
types: [published] | ||
workflow_dispatch: | ||
|
||
name: pkgdown.yaml | ||
|
||
permissions: read-all | ||
|
||
jobs: | ||
pkgdown: | ||
runs-on: ubuntu-latest | ||
# Only restrict concurrency for non-PR jobs | ||
concurrency: | ||
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} | ||
env: | ||
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | ||
permissions: | ||
contents: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: r-lib/actions/setup-pandoc@v2 | ||
|
||
- uses: r-lib/actions/setup-r@v2 | ||
with: | ||
use-public-rspm: true | ||
|
||
- uses: r-lib/actions/setup-r-dependencies@v2 | ||
with: | ||
extra-packages: any::pkgdown, local::. | ||
needs: website | ||
|
||
- name: Build site | ||
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) | ||
shell: Rscript {0} | ||
|
||
- name: Deploy to GitHub pages 🚀 | ||
if: github.event_name != 'pull_request' | ||
uses: JamesIves/[email protected] | ||
with: | ||
clean: false | ||
branch: gh-pages | ||
folder: docs | ||
# on: | ||
# push: | ||
# branches: [main, master] | ||
# pull_request: | ||
# branches: [main, master] | ||
# release: | ||
# types: [published] | ||
# workflow_dispatch: | ||
# | ||
# name: pkgdown.yaml | ||
# | ||
# permissions: read-all | ||
# | ||
# jobs: | ||
# pkgdown: | ||
# runs-on: ubuntu-latest | ||
# # Only restrict concurrency for non-PR jobs | ||
# concurrency: | ||
# group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} | ||
# env: | ||
# GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | ||
# permissions: | ||
# contents: write | ||
# steps: | ||
# - uses: actions/checkout@v4 | ||
# | ||
# - uses: r-lib/actions/setup-pandoc@v2 | ||
# | ||
# - uses: r-lib/actions/setup-r@v2 | ||
# with: | ||
# use-public-rspm: true | ||
# | ||
# - uses: r-lib/actions/setup-r-dependencies@v2 | ||
# with: | ||
# extra-packages: any::pkgdown, local::. | ||
# needs: website | ||
# | ||
# - name: Build site | ||
# run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) | ||
# shell: Rscript {0} | ||
# | ||
# - name: Deploy to GitHub pages 🚀 | ||
# if: github.event_name != 'pull_request' | ||
# uses: JamesIves/[email protected] | ||
# with: | ||
# clean: false | ||
# branch: gh-pages | ||
# folder: docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,9 @@ Imports: | |
tidyr, | ||
ggplot2, | ||
matrixStats, | ||
haven | ||
haven, | ||
tree, | ||
plotrix | ||
Suggests: | ||
knitr, | ||
rmarkdown, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#' Representative trees from ensembles | ||
#' | ||
#' This package implements the concept of representative trees from ensemble | ||
#' tree-based learners introduced by Banerjee, et al, (2012). Representative trees | ||
#' are, in some sense, trees in the ensemble which are on average the "closest" to | ||
#' all the other trees in the ensemble. Several trees can be representative of the | ||
#' ensemble in general. This package currently implements the d2 metric of tree closeness | ||
#' (close in prediction) from Banerjee, et al. | ||
#' | ||
#' @name reprtree-package | ||
#' @references M. Banerjee, Y. Ding and A-M Noone (2012) "Identifying representative | ||
#' trees from ensembles". Statistics in Medicine, 31(15):1601-1616. | ||
#' @import randomForest tree | ||
#' @docType package | ||
#' @name reprtree | ||
#' @examples | ||
#' library(reprtree) | ||
#' rforest <- randomForest(Species~., data=iris) | ||
#' reptree <- ReprTree(rforest, iris, metric='d2') | ||
#' plot(reptree, index=1) | ||
NULL | ||
|
||
|
||
#' Identifying and extracting representative trees from a random forest | ||
#' | ||
#' This function takes a random forest object and data to run predictions on | ||
#' and identifies representative trees based on the d0, d1 or d2 metric defined | ||
#' in Banerjee, et al (2012). Currently only the d2 metric is implemented, using | ||
#' either a euclidean distance (for numeric predictions) or a mismatch distance | ||
#' (for categorical predictions). The average distance D(T) of each tree in the | ||
#' set of trees in computed, and trees with the lowest D(T) value are extracted | ||
#' and formatted to be compatible with the \code{\link{tree}} class. Trees can then | ||
#' be visualized using \code{plot.tree} and \code{text.tree}, or using a custom | ||
#' plot function (to be defined) | ||
#' | ||
#' @param rforest A randomForest object | ||
#' @param newdata The data on which predictions will be computed | ||
#' @param metric The metric to be used to evaluate distance between trees. Currently | ||
#' only the d2 metric is implemented | ||
#' @return A list object containing representations of the representative trees | ||
#' conformable with the \code{tree} class. Names of the list give the indices | ||
#' of the representative trees in the set of trees. | ||
#' @import randomForest tree | ||
#' @export | ||
#' @references M. Banerjee, Y. Ding and A-M Noone (2012) "Identifying representative | ||
#' trees from ensembles". Statistics in Medicine, 31(15):1601-1616. | ||
#' @examples | ||
#' library(randomForest) | ||
#' library(tree) | ||
#' rforest <- randomForest(Species~., data=iris) | ||
#' reptree <- ReprTree(rforest, iris, metric='d2') | ||
ReprTree <- function(rforest, newdata, metric='d2'){ | ||
if(metric!='d2') stop('invalid metric!') | ||
require(randomForest) | ||
print('Constructing distance matrix...') | ||
preds <- predict2(rforest, newdata=newdata, predict.all=T) | ||
preds.indiv <- preds$individual | ||
d <- dist.fn(t(preds.indiv), method=ifelse(rforest$type=='classification', | ||
'mismatch', | ||
'euclidean')) | ||
print('Finding representative trees...') | ||
D <- colMeans(d) | ||
index <- which(D==min(D)) | ||
trees <- lapply(as.list(index), function(i) getTree(rforest, i, labelVar=TRUE)) | ||
names(trees) <- as.character(index) | ||
trees <- lapply(trees, as.tree, rforest) | ||
out <- list(trees=trees,D = D) | ||
class(out) <- c('reprtree','list') | ||
return(out) | ||
} |
Oops, something went wrong.