Questions tagged [rpart]

An R package for fitting classification and regression trees.

rpart is an package for fitting and trees ().

Repositories

Vignettes

Other resources

Related tags

445 questions
6
votes
1 answer

Plot ctree using rpart.plot functionality

Been trying to use the rpart.plot package to plot a ctree from the partykit library. The reason for this being that the default plot method is terrible when the tree is deep. In my case, my max_depth = 5. I really enjoy rpart.plot's output as it…
Hanjo Odendaal
  • 1,395
  • 2
  • 13
  • 32
6
votes
1 answer

Missing values error in train() function Caret for trees

I'm new using R and I'm trying to build a decision tree. I've already used the package party for ctree and rpart for rpart. But, as I needed to do cross validation for my model I start using the caret package since I'm able to do that by using the…
6
votes
1 answer

Understanding of minbucket function in CART model using R

Assume the training data is "fruit", which I am going to use it for predict using CART model in R > fruit=data.frame( color=c("red", "red", "red", "yellow", "red","yellow", "orange","green","pink",…
GBOT
  • 93
  • 1
  • 1
  • 11
6
votes
2 answers

How to get terminal nodes for a new observation from an rpart object?

Say I have head(kyphosis) inTrain <- sample(1:nrow(kyphosis), 45, replace = F) TRAIN_KYPHOSIS <- kyphosis[inTrain,] TEST_KYPHOSIS <- kyphosis[-inTrain,] (kyph_tree <- rpart(Number ~ ., data = TRAIN_KYPHOSIS)) How to get the terminal node from the…
goldisfine
  • 4,742
  • 11
  • 59
  • 83
6
votes
2 answers

R caret package (rpart): constructing a classification tree

I am struggling for several days to perform a classification tree using the caret package. The problem are my factor variables. I generate the tree, but when I try to use the best model to make predictions on the test sample, it fails, because the…
lorelai
  • 147
  • 1
  • 2
  • 9
6
votes
2 answers

How to use all features in rpart?

I'm using the rpart package for decision tree classification. I have a data frame with around 4000 features (columns). I want to use all features in rpart() for my model. How can I do that? Basically, rpart() will ask me to use the function in this…
user3430235
  • 419
  • 1
  • 4
  • 12
6
votes
1 answer

How to count decision tree rules in R

I employed RPart to build a decision tree. Without a problem, I am doing this. But, I need to learn (or count) how many times the tree has been splitted? I mean, how many rules (if-else statement) the tree has? For instance: X …
user3692479
6
votes
1 answer

rpart plot text shorter

I am using the prp function from the rpart.plot package to plot a tree. For categorical data like states, it gives a really long list of variables and makes it less readable. Is there any way to wrap text to two or more lines if exceeds some length?
Yoki
  • 863
  • 4
  • 14
  • 26
5
votes
1 answer

How to make a decision tree chart using random forest and filtering it by category

I'm learning machine learning in R and making a decision tree in R of expired products, where i have the following data: Product, Category, Temperature, Expire_Day, Rotation_Day, Weight, State Tapa, Pulpa, 0, 30, 21, 4.21, No Tapa, Pulpa, 0, 30, 21,…
Aegis
  • 113
  • 7
  • 27
5
votes
0 answers

Converting "C50 models" to "rpart" models

Is there a way to use the rpart.plot library to plot objects that do not belong to rpart (used for making decision trees)? For instance, here is the classic rpart and rpart.plot library in action: #load libraries library(rpart) …
stats_noob
  • 5,401
  • 4
  • 27
  • 83
5
votes
1 answer

R: rpart tree grows using two explanatory variables, but not after removing less important variable

Data: I'm using the "attrition" dataset from the rsample package. Question: Using the attrition dataset and rpart library, I can grow a tree using the formula "Attrition ~ OverTime + JobRole", where OverTime is chosen as the first split. But when I…
sdevine188
  • 338
  • 3
  • 8
5
votes
0 answers

Transformation and representation of Randomforest tree into decision trees (rpart)

I have the following code for random forest: set.seed(71) rf = randomForest(Species~.,data=iris,ntree=200,mtry=2,sampsize=30,keep.forest=TRUE,replace=FALSE,keep.inbag=TRUE) I would like to get the 200th decision tree, so I use: > getTree (rf,200) …
Avi
  • 2,247
  • 4
  • 30
  • 52
5
votes
1 answer

How to apply weights in rpart?

I have this data on houses from the Kaggle practice competition and I'm using rpart to train a simple first model to predict the sale price. The model is not correctly identifying sales where the sale condition was abnormal or a down payment.…
GreenManXY
  • 401
  • 1
  • 5
  • 14
5
votes
1 answer

rpart.plot remove scientific notation

> fit <- rpart(price ~ carat + cut + clarity, diamonds_train, method = "anova") > rpart.plot(fit, type = 4, extra = 101) I tried options(scipen=10) but it didn't work. How can I remove the scientific notation?
Summer Mao
  • 51
  • 1
  • 4
5
votes
2 answers

Calculating prediction accuracy of a tree using rpart's predict method

I have constructed a decision tree using rpart for a dataset. I have then divided the data into 2 parts - a training dataset and a test dataset. A tree has been constructed for the dataset using the training data. I want to calculate the accuracy…
Arat254
  • 449
  • 2
  • 5
  • 17
1 2
3
29 30