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
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,703
  • 2
  • 27
  • 35
9
votes
2 answers

Tree sizes given by CP table in rpart

In the R package rpart, what determines the size of trees presented within the CP table for a decision tree? In the below example, the CP table defaults to presenting only trees with 1, 2, and 5 nodes (as nsplit = 0, 1 and 4…
alopex
  • 133
  • 1
  • 2
  • 7
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
8
votes
4 answers

Search for corresponding node in a regression tree using rpart

I'm pretty new to R and I'm stuck with a pretty dumb problem. I'm calibrating a regression tree using the rpart package in order to do some classification and some forecasting. Thanks to R the calibration part is easy to do and easy to control. #the…
antoine
  • 123
  • 1
  • 5
8
votes
3 answers

R caret rpart returns Error in `[.data.frame`(m, labs) : undefined columns selected

I am running a classification for rpart. I needed to prepare the data into a sparse format to run multiple models to it . When I run the rpart method, using this call: control <- trainControl(method="repeatedcv", number=10, repeats=3) #Metric…
E B
  • 1,073
  • 3
  • 23
  • 36
8
votes
6 answers

Getting the observations in a rpart's node (i.e.: CART)

I would like to inspect all the observations that reached some node in an rpart decision tree. For example, in the following code: fit <- rpart(Kyphosis ~ Age + Start, data = kyphosis) fit n= 81 node), split, n, loss, yval, (yprob) *…
Tal Galili
  • 24,605
  • 44
  • 129
  • 187
8
votes
3 answers

r caret predict returns fewer output than input

I used caret to train an rpart model below. trainIndex <- createDataPartition(d$Happiness, p=.8, list=FALSE) dtrain <- d[trainIndex, ] dtest <- d[-trainIndex, ] fitControl <- trainControl(## 10-fold CV method = "repeatedcv", number=10,…
Ricky
  • 4,616
  • 6
  • 42
  • 72
8
votes
2 answers

building classification tree having categorical variables using rpart

I have a data set with 14 features and few of them are as below, where sex and marital status are categorical variables. height,sex,maritalStatus,age,edu,homeType SEX 1. Male 2. Female MARITAL STATUS 1. Married …
user4251309
  • 113
  • 1
  • 2
  • 6
8
votes
2 answers

rpart: Computational time for categorical vs continuous regressors

i am currently using the rpart package to fit a regression tree to a data with relatively few observations and several thousand categorical predictors taking two possible values. from testing the package out on smaller data i know that in this…
stas g
  • 1,503
  • 2
  • 10
  • 20
8
votes
1 answer

Is rpart automatic pruning?

Is rpart automatic pruning? The decision tree produced by rpart is much more levels than that produced by Oracle Data Mining which has the automatic pruning.
Jack Han
  • 81
  • 1
  • 2
7
votes
2 answers

What is the difference between rel error and x error in a rpart decision tree?

I have a purely categorical dataframe from the UCI machine learning database https://archive.ics.uci.edu/ml/datasets/Diabetes+130-US+hospitals+for+years+1999-2008 I am using rpart to form a decision tree based on a new category on whether patients…
user1745691
  • 305
  • 2
  • 5
  • 12
7
votes
1 answer

How do I interpret rpart splits on factor variables when building classification trees in R?

If the factor variable is Climate, with 4 possible values: Tropical, Arid, Temperate, Snow, and a node in my rpart tree is labeled as "Climate:ab", what is the split?
user281537
  • 111
  • 1
  • 2
  • 4
7
votes
4 answers

Get id/name of rpart model nodes

How can I get ID (or name) of terminal node of rpart model for every row? predict.rpart can return only predicted class (number or factor) or class probability or some combination (using type="matrix") for classification tree. I would like to do…
Tomas Greif
  • 21,685
  • 23
  • 106
  • 155
7
votes
3 answers

Testing rules generated by Rpart package

I want to test in a programmatically way one rule generated from a tree. In the trees the path between the root and a leaf (terminal node) could be interpreted as a rule. In R, we could use the rpart package and do the following: (In this post, I…
nanounanue
  • 7,942
  • 7
  • 41
  • 73
6
votes
2 answers

caret rpart decision tree plotting result

I am training a decision tree model based on the heart disease data from Kaggle. Since I am also building other models using 10-fold CV, I am trying to use caret package with rpart method to build the tree. However, the plot result is weird as…
Rui Tongyu
  • 79
  • 4
1
2
3
29 30