Re: [問題] 隨機森林畫決策樹

看板R_Language作者 (攸藍)時間8年前 (2015/07/26 14:48), 8年前編輯推噓1(106)
留言7則, 1人參與, 最新討論串3/3 (看更多)
※ 引述《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
大大我用git載下來也修改了 可是跑的時候他還是給我
07/26 16:24, 1F

07/26 16:25, , 2F
Error:"cex.label" 不是一個繪圖參數
07/26 16:25, 2F

07/26 16:25, , 3F
我是把載下來的資料夾覆蓋原本R library裡面的reptree
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
輸入後他寫ERROR:dependencies 'randomForest',
07/26 16:32, 5F
這個問題比較複雜一點QQ...我不知道你為啥會出問題(嘆氣

07/26 16:32, , 6F
'tree', 'plotrix' are not available for package
07/26 16:32, 6F

07/26 16:33, , 7F
'reprtree' *removing '~/reprtree'
07/26 16:33, 7F
你的系統是什麼?這個問題通常出現在你使用R的資料夾是否有正確被囊括在路徑中 試試看將reprtree的資料夾壓縮成tar.gz,用R的manu選用本機的zip安裝程式套件 結果回報:成功 ※ 編輯: celestialgod (123.205.27.107), 07/26/2015 17:51:33
文章代碼(AID): #1Lj8BRd2 (R_Language)
文章代碼(AID): #1Lj8BRd2 (R_Language)