GLE Example: rt-y-is-x.gle

[PDF file]

 


size 12 10

set font texcmr hei 0.26
include "simpletree.gle"

! Draw the main graph (RMSE versus number of nodes in regression tree)
amove 1 6.5
begin graph
   size 6 3
   fullsize
   title  "Regression trees approximating y = x"
   data   "rt-y-is-x-labels.dat"
   xtitle "Size (nodes)"
   ytitle "RMSE"
   xplaces 1 2 3 4  5  6
   xnames  1 3 7 20 50 250
   xaxis min 1 max 6
   yaxis max 0.3
   d3 line color red marker square
end graph

! Draw an example regression tree with 7 nodes
! x > 0.496
! +--yes: x > 0.738
! |       +--yes: 0.861
! |       +--no:  0.617
! +--no:  x > 0.248
!         +--yes: 0.377
!         +--no:  0.124

gsave
set just bc
amove (xg(6)+pagewidth())/2 pageheight()-0.9
write "Tree with 7 nodes"
binrootnode xpos() ypos()-0.3 "x > 0.496" "yes" "no" 1
  binnode "r1" "x > 0.738" "yes" "no" 0.5
    leaf "r11" "0.861"
    leaf "r12" "0.617"
  binnode "r2" "x > 0.248" "yes" "no" 0.5
    leaf "r21" "0.377"
    leaf "r22" "0.124"
grestore

sub bluediagonal
   set color rgb255(100,100,255)
   amove xg(0) yg(0); aline xg(1) yg(1)
   set color black
end sub

! Draw one of the small graphs (make sure the red goes over the blue)
sub plot x y n nodes
   amove x*3.9+1 y*2.9+0.4
   begin graph
      size 3.1 2.1
      fullsize
      data "rt-y-is-x.dat"
      d[n] line color red
      title "\expr{nodes} nodes"
      xaxis min 0 max 1 dticks 0.25
      yaxis min 0 max 1 dticks 0.25
      draw bluediagonal
   end graph
end sub

! Loop to draw the 6 small graphs
number = 1
fopen "rt-y-is-x-labels.dat" f1 read
for y = 1 to 0 step -1
   for x = 0 to 2
      fread f1 idx nodes mse rmse
      plot x y number nodes
      number = number+1
   next x
next y
fclose f1

 

[Return to examples page]