修复r中不可读的postscript树输出

时间:2011-04-26 14:49:14

标签: r machine-learning postscript

我有一个相对复杂的分类树,我正在尝试输出。产生的postscript输出看起来非常混乱。

> fit = rpart(virility ~ friend_count  + recip_count + twitter_handles + has_email + 
                          has_bio + has_foursquare + has_linkedin + auto_tweet + 
                          interaction_visibility + site_own_cnt + site_rec_cnt + has_url +
                          has_linkedin_url + lb_cnt, + mob_own_cnt + mob_rec_cnt + 
                          twt_own_cnt + twt_rec_cnt, method="class", data=vir)
> fit
n= 9704 

node), split, n, loss, yval, (yprob)
      * denotes terminal node

 1) root 9704 3742 virile (0.39970092 0.60029908)  
   2) recip_count< 15.5 9610 3159 mule (0.52005469 0.47994531)  
     4) site_own_cnt< 0.5 7201 1372 mule (0.65423387 0.34576613)  
       8) friend_count< 2.5 6763  948 mule (0.69566613 0.30433387)  
        16) has_bio>=0.5 4030  601 mule (0.73743993 0.26256007) *
        17) has_bio< 0.5 2733  347 mule (0.57990315 0.42009685)  
          34) recip_count< 0.5 2496   88 mule (0.78000000 0.22000000) *
          35) recip_count>=0.5 237  167 virile (0.39201878 0.60798122) *
       9) friend_count>=2.5 438  424 mule (0.50293083 0.49706917)  
        18) lb_cnt< 2.5 427  344 mule (0.55208333 0.44791667)  
          36) has_foursquare< 0.5 401  257 mule (0.61353383 0.38646617)  
            72) twitter_handles>=0.5 382  210 mule (0.65742251 0.34257749) *
            73) twitter_handles< 0.5 19    5 virile (0.09615385 0.90384615) *
          37) has_foursquare>=0.5 26   16 virile (0.15533981 0.84466019) *
        19) lb_cnt>=2.5 11    5 virile (0.05882353 0.94117647) *
     5) site_own_cnt>=0.5 2409  827 virile (0.31637337 0.68362663)  
      10) recip_count< 0.5 1344  274 mule (0.62102351 0.37897649)  
        20) friend_count< 0.5 955   75 mule (0.81155779 0.18844221) *
        21) friend_count>=0.5 389  126 virile (0.38769231 0.61230769)  
          42) twitter_handles< 0.5 62    3 mule (0.93181818 0.06818182) *
          43) twitter_handles>=0.5 327   85 virile (0.30249110 0.69750890) *
      11) recip_count>=0.5 1065  378 virile (0.19989424 0.80010576) *
   3) recip_count>=15.5 94  319 virile (0.11474820 0.88525180)  
     6) friend_count< 2.5 40  265 virile (0.32435741 0.67564259)  
      12) site_rec_cnt>=1.5 24  175 mule (0.59112150 0.40887850)  
        24) site_rec_cnt< 4 13   46 mule (0.80257511 0.19742489) *
        25) site_rec_cnt>=4 11   66 virile (0.33846154 0.66153846) *
      13) site_rec_cnt< 1.5 16   12 virile (0.03084833 0.96915167) *
     7) friend_count>=2.5 54   54 virile (0.02750891 0.97249109) *

> post(fit, file = "/tmp/blah.ps", title = "virility model")

这导致:

enter image description here

树的节点都是一半写在彼此之上。有没有办法让这个输出看起来相当可读?

1 个答案:

答案 0 :(得分:5)

post的{​​{1}}方法实际上首先调用rpart方法,然后调用rpart的plot方法。这意味着您可以研究text?plot.rpart的帮助,以找到改善情节输出的方法。

?text.rpart提供了一些非常好的指示。我建议你尝试以下参数:

  • ?text.rpart将移除省略号和框。你的情节显然太忙了,而且很大。删除它会增加易读性。
  • fancy=FALSE会将字体大小减小到正常大小的0.8。略小的字体可能会增加图上元素之间的间距。

以下是使用适合cex=0.8diamonds数据的模型所做出的差异示例:

ggplot2

enter image description here