0

i am new to R and rpart. i don't know why can i make tree. here is my code and result

library(rpart)
library(partykit)    
onp.tr <- rpart(rshares~., reonp)
onp.tr
> onp.tr
n= 39644 

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

str(reonp)
    data.frame':    39644 obs. of  22 variables:
     $ rshares             : Factor w/ 2 levels "A","B": 1 1 1 1 1 1 1 1 1 1 ...
     $ n_tokens_title      : int  12 9 9 9 13 10 8 12 11 10 ...
     $ n_tokens_content    : int  219 255 211 531 1072 370 960 989 97 231 ...
     $ n_unique_tokens     : num  0.664 0.605 0.575 0.504 0.416 ...
     $ num_hrefs           : int  4 3 3 9 19 2 21 20 2 4 ...
     $ num_self_hrefs      : int  2 1 1 0 19 2 20 20 0 1 ...
     $ num_imgs            : int  1 1 1 1 20 0 20 20 0 1 ...
     $ num_videos          : int  0 0 0 0 0 0 0 0 0 1 ...
     $ average_token_length: num  4.68 4.91 4.39 4.4 4.68 ...
     $ num_keywords        : int  5 4 6 7 7 9 10 9 7 5 ...
     $ kw_min_min          : int  0 0 0 0 0 0 0 0 0 0 ...
     $ kw_max_min          : num  0 0 0 0 0 0 0 0 0 0 ...
     $ kw_avg_min          : num  0 0 0 0 0 0 0 0 0 0 ...
     $ kw_min_max          : int  0 0 0 0 0 0 0 0 0 0 ...
     $ kw_max_max          : int  0 0 0 0 0 0 0 0 0 0 ...
     $ kw_avg_max          : num  0 0 0 0 0 0 0 0 0 0 ...
     $ kw_min_avg          : num  0 0 0 0 0 0 0 0 0 0 ...
     $ kw_max_avg          : num  0 0 0 0 0 0 0 0 0 0 ...
     $ kw_avg_avg          : num  0 0 0 0 0 0 0 0 0 0 ...
     $ is_weekend          : int  0 0 0 0 0 0 0 0 0 0 ...
     $ channel             : Factor w/ 6 levels "Bus","Ent","Life",..: 2 1 1 2 5 5 3 5 5 6 ...
     $ weekday             : Factor w/ 6 levels "Fri","Mon","THU",..: 2 2 2 2 2 2 2 2 2 2 ...


attributes(reonp)

  $names
      [1] "rshares"              "n_tokens_title"       "n_tokens_content"     "n_unique_tokens"     
     [5] "num_hrefs"            "num_self_hrefs"       "num_imgs"             "num_videos"          
     [9] "average_token_length" "num_keywords"         "kw_min_min"           "kw_max_min"          
    [13] "kw_avg_min"           "kw_min_max"           "kw_max_max"           "kw_avg_max"          
    [17] "kw_min_avg"           "kw_max_avg"           "kw_avg_avg"           "is_weekend"          
    [21] "channel"              "weekday"             

$class
[1] "data.frame"
김주형
  • 1
  • 1
  • Welcome to StackOverflow. Please see this guidance on how to make a [good question](https://stackoverflow.com/help/how-to-ask) that the community can help you with. In this case I think you need to specify your problem better. – geotheory Dec 03 '15 at 07:28
  • User Dinesh recommends following link as possibly related: http://www.statmethods.net/advstats/cart.html – Jiri Tousek Dec 03 '15 at 07:58

1 Answers1

0

Your question is bit unclear but looks like you want to visualize your tree. So

install the package rpart.plot. it will help u plot nice rpart trees

use

rpart.plot(onp.tr)

it will plot ur tree

Anuja Parikh
  • 53
  • 1
  • 14
  • my question is why my tree don't take a shape like tree. when i take rpart.plot(onp.tr) it shows only "A" – 김주형 Dec 05 '15 at 11:35