Debian Codegraph @

R/as.dendrogram.randomForest.R

raw
1 # plotting a randomForest tree!
2 # https://stats.stackexchange.com/questions/2344/best-way-to-present-a-random-forest-in-a-publication
3 # I will still need to clean this into this:
4 # as.dendrogram.randomForest
5
6
7
8
9 # to.dendrogram <- function(dfrep,rownum=1,height.increment=0.1){
10
11 # if(dfrep[rownum,'status'] == -1){
12 # rval <- list()
13
14 # attr(rval,"members") <- 1
15 # attr(rval,"height") <- 0.0
16 # attr(rval,"label") <- dfrep[rownum,'prediction']
17 # attr(rval,"leaf") <- TRUE
18
19 # }else{##note the change "to.dendrogram" and not "to.dendogram"
20 # left <- to.dendrogram(dfrep,dfrep[rownum,'left daughter'],height.increment)
21 # right <- to.dendrogram(dfrep,dfrep[rownum,'right daughter'],height.increment)
22 # rval <- list(left,right)
23
24 # attr(rval,"members") <- attr(left,"members") + attr(right,"members")
25 # attr(rval,"height") <- max(attr(left,"height"),attr(right,"height")) + height.increment
26 # attr(rval,"leaf") <- FALSE
27 # attr(rval,"edgetext") <- dfrep[rownum,'split var']
28 # }
29
30 # class(rval) <- "dendrogram"
31
32 # return(rval)
33 # }
34
35
36 # library(randomForest)
37 # set.seed(1)
38 # data(iris, envir = environment())
39 # iris.rf <- randomForest(Species ~ ., iris, proximity=TRUE,
40 # keep.forest=FALSE)
41 # MDSplot(iris.rf, iris$Species)
42
43
44 # set.seed(1)
45 # mod <- randomForest(Species ~ .,data=iris)
46 # tree <- getTree(mod,1,labelVar=TRUE)
47
48
49
50
51 # d <- to.dendrogram(tree)
52 # str(d)
53 # plot(d,center=TRUE,leaflab='none',edgePar=list(t.cex=1,p.col=NA,p.lty=0))