File: as.dendrogram.randomForest.R

package info (click to toggle)
r-cran-dendextend 1.19.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,076 kB
  • sloc: sh: 13; makefile: 2
file content (53 lines) | stat: -rw-r--r-- 1,426 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
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
# plotting a randomForest tree!
# https://stats.stackexchange.com/questions/2344/best-way-to-present-a-random-forest-in-a-publication
# I will still need to clean this into this:
# as.dendrogram.randomForest




# to.dendrogram <- function(dfrep,rownum=1,height.increment=0.1){

# if(dfrep[rownum,'status'] == -1){
# rval <- list()

# attr(rval,"members") <- 1
# attr(rval,"height") <- 0.0
# attr(rval,"label") <- dfrep[rownum,'prediction']
# attr(rval,"leaf") <- TRUE

# }else{##note the change "to.dendrogram" and not "to.dendogram"
# left <- to.dendrogram(dfrep,dfrep[rownum,'left daughter'],height.increment)
# right <- to.dendrogram(dfrep,dfrep[rownum,'right daughter'],height.increment)
# rval <- list(left,right)

# attr(rval,"members") <- attr(left,"members") + attr(right,"members")
# attr(rval,"height") <- max(attr(left,"height"),attr(right,"height")) + height.increment
# attr(rval,"leaf") <- FALSE
# attr(rval,"edgetext") <- dfrep[rownum,'split var']
# }

# class(rval) <- "dendrogram"

# return(rval)
# }


# library(randomForest)
# set.seed(1)
# data(iris, envir = environment())
# iris.rf <- randomForest(Species ~ ., iris, proximity=TRUE,
# keep.forest=FALSE)
# MDSplot(iris.rf, iris$Species)


# set.seed(1)
# mod <- randomForest(Species ~ .,data=iris)
# tree <- getTree(mod,1,labelVar=TRUE)




# d <- to.dendrogram(tree)
# str(d)
# plot(d,center=TRUE,leaflab='none',edgePar=list(t.cex=1,p.col=NA,p.lty=0))