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

415 questions
31
votes
1 answer

How to compute error rate from a decision tree?

Does anyone know how to calculate the error rate for a decision tree with R? I am using the rpart() function.
teo6389
  • 513
  • 1
  • 5
  • 10
28
votes
5 answers

Warning message: "missing values in resampled performance measures" in caret train() using rpart

I am using the caret package to train a model with "rpart" package; tr = train(y ~ ., data = trainingDATA, method = "rpart") Data has no missing values or NA's, but when running the command a warning message comes up; Warning message: In…
USER_1
  • 2,096
  • 1
  • 23
  • 27
25
votes
3 answers

How to make a tree plot in caret package?

I'm using caret package to model the data using rpart package. library('caret') data(iris) formula <- as.formula(Species ~.) t <- train(formula,iris,method = "rpart",cp=0.002,maxdepth=8) plot(t) As a result I get object 't' and I'm trying to plot…
Jot eN
  • 4,817
  • 3
  • 31
  • 50
20
votes
4 answers

R: plotting decision tree labels leaves text cut off

(I'm still learning how to handle images in R; this is sort of a continuation of rpart package: Save Decision Tree to PNG ) I'm trying to save a decision tree plot from rpart in PNG form, instead of the provided postscript. My code looks like this:…
rhae66
  • 283
  • 1
  • 4
  • 8
18
votes
3 answers

The result of rpart is just with 1 root

As in my dataset ,the Leakage have two value 1,0. There are just about 300 rows with 1 and extra in 569378 rows are with 1. This would be the reason that I just got 1 root in the rpart result. How can I solve this? fm.pipe<-Leakage~PipeAge…
user3172776
  • 201
  • 1
  • 3
  • 5
17
votes
4 answers

Error in eval(expr, envir, enclos) : object not found

I cannot understand what is going wrong here. data.train <- read.table("Assign2.WineComplete.csv",sep=",",header=T) # Building decision tree Train <- data.frame(residual.sugar=data.train$residual.sugar, …
Rads
  • 325
  • 1
  • 4
  • 11
15
votes
3 answers

Regression tree in R

I am having trouble making a regression tree in R. I have a data frame with 17 attributes library(rpart) rt.model <- rpart(razlika ~ ., learn) I get an error: Error in `[.data.frame`(frame, predictors) : undefined columns selected Seems weird…
Borut Flis
  • 12,872
  • 26
  • 74
  • 102
13
votes
1 answer

How to prune a tree in R?

I'm doing a classification using rpart in R. The tree model is trained by: > tree <- rpart(activity ~ . , data=trainData) > pData1 <- predict(tree, testData, type="class") The accuracy for this tree model is: >…
zfz
  • 1,535
  • 1
  • 20
  • 43
12
votes
1 answer

result of rpart is a root, but data shows Information Gain

I have a dataset with an event rate of less than 3% (i.e. there are about 700 records with class 1 and 27000 records with class 0). ID V1 V2 V3 V5 V6 Target SDataID3 161 ONE 1 FOUR 0 0 SDataID4 11 TWO 2 …
10
votes
1 answer

Using a survival tree from the 'rpart' package in R to predict new observations

I'm attempting to use the "rpart" package in R to build a survival tree, and I'm hoping to use this tree to then make predictions for other observations. I know there have been a lot of SO questions involving rpart and prediction; however, I have…
jwdink
  • 3,278
  • 3
  • 15
  • 19
9
votes
3 answers

Applying k-fold Cross Validation model using caret package

Let me start by saying that I have read many posts on Cross Validation and it seems there is much confusion out there. My understanding of that it is simply this: Perform k-fold Cross Validation i.e. 10 folds to understand the average error across…
pman1971
  • 151
  • 1
  • 1
  • 7
9
votes
1 answer

Caret train method complains Something is wrong; all the RMSE metric values are missing

On numerous occasions I've been getting this error when trying to fit a gbm or rpart model. Finally I was able to reproduce it consistently using publicly available data. I have noticed that this error happens when using CV (or repeated cv). When I…
Fred R.
  • 435
  • 2
  • 6
  • 13
9
votes
1 answer

Get decision tree rule/path pattern for every row of predicted dataset for rpart/ctree package in R

I have built a decision tree model in R using rpart and ctree. I also have predicted a new dataset using the built model and got predicted probabilities and classes. However, I would like to extract the rule/path, in a single string, for every…
arindam adak
  • 91
  • 1
  • 5
9
votes
1 answer

Why do results using caret::train(..., method = "rpart") differ from rpart::rpart(...)?

I'm taking part in the Coursera Practical Machine Learning course, and the coursework requires building predictive models using this dataset. After splitting the data into training and testing datasets, based on the outcome of interest (herewith…
Jonny
  • 2,251
  • 2
  • 20
  • 33
8
votes
2 answers

Decision tree using rpart to produce a sankey diagram

I can create a tree with Rpart using the Kyphosis data set which is part of base R: fit <- rpart(Kyphosis ~ Age + Number + Start, method="class", data=kyphosis) printcp(fit) plot(fit, uniform=TRUE,main="Classification Tree for…
Matt Lourens
  • 171
  • 9
1
2 3
27 28