Re: [問題] 隨機森林畫決策樹
※ 引述《SFMAndroid (安卓發送)》之銘言:
: 承前篇
: 目前成功用plot.getTree得到結果了
: #code
: library(tree)
: library(reprtree)
: library(plotrix)
: set.seed(100)
: jepg("~//tree.jpeg", width=1300, height=800)
: reprtree:::plot.getTree(rf, k=10, depth=0)
: dev.off()
我看了一下,原作者好像寫死了那個部分的參數(cex = 0.8)
所以你需要用git clone把package download之後自己做一些修改
plor.reptree.R的 labelBG加上一個input, cex.label
boxed.labels裡面的cex引數原本等於0.8要改成 cex = cex.label
像下面這樣:
labelBG <- function(tr, cex.label = 0.8){
## 中間省略
boxed.labels(xy$x[ind],xy$y[ind]+0.5*charht, rows[ind] , border=F,
bg='white', cex=cex.label, xpad=0.5, ypad=1)
}
plot.getTree.R的plot.getTree加上一個input, cex.label
然後改倒數第三行的labelBG,改成labelBG(x, cex.label)
像這樣
plot.getTree <- function(rforest=NULL,tr=NULL,k=1, depth=0,main=NULL,
cex.label = 0.8, ...){
## 中間省略
labelBG(x, cex.label)
labelYN(x)
title(main=main)
}
你接下來這樣就可以work了
library(reprtree)
set.seed(100)
data <- data.frame(y=sample(c("好", "不好"), 100, replace=TRUE),
x1=sample(c("學生", "老師", "教官"), 100, replace=TRUE),
x2=sample(c("20歲以下", "20~30歲", "30歲以上"), 100, replace=TRUE))
rf <- randomForest(y~., data=data, ntree=10, proximity=TRUE)
reprtree:::plot.getTree(rf, k=10, depth=0, cex.label = 2)
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.205.27.107
※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1437893339.A.9C2.html
※ 編輯: celestialgod (123.205.27.107), 07/26/2015 14:55:39
→
07/26 16:24, , 1F
07/26 16:24, 1F
→
07/26 16:25, , 2F
07/26 16:25, 2F
→
07/26 16:25, , 3F
07/26 16:25, 3F
不行這樣,你下載然後改CODE之後,要用命令列打R CMD INSTALL reprtree
→
07/26 16:26, , 4F
07/26 16:26, 4F
推
07/26 16:32, , 5F
07/26 16:32, 5F
這個問題比較複雜一點QQ...我不知道你為啥會出問題(嘆氣
→
07/26 16:32, , 6F
07/26 16:32, 6F
→
07/26 16:33, , 7F
07/26 16:33, 7F
你的系統是什麼?這個問題通常出現在你使用R的資料夾是否有正確被囊括在路徑中
試試看將reprtree的資料夾壓縮成tar.gz,用R的manu選用本機的zip安裝程式套件
結果回報:成功
※ 編輯: celestialgod (123.205.27.107), 07/26/2015 17:51:33
討論串 (同標題文章)