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
4
votes
1 answer

Interpret R output Rpart classification tree surrogate splits

Surrogate splits: ## bmi < 21.51 to the right, agree=0.858, adj=0.632, (0 split) I understand that this split send cases to the right child node based on a bmi value of < 21.51 and has a similar split to the primary variable (agree =…
alloemf
  • 109
  • 1
  • 10
4
votes
1 answer

Splits and Root node of binary decision tree(CART)

How to find a split and root node in a regression tree, I made a regression tree from multiple vectors now I have to extract root node of rpart of multiple vectors.file contains numeric value of multiple vectors A,B,C,D,E,F,G,H ex. A vector contains…
Aashu
  • 1,247
  • 1
  • 26
  • 41
3
votes
0 answers

R: how to instantiate a custom split (usersplit) in rpart which requires a vector as a parameter

I'm inspecting tests/usersplits.R in rpart, trying to get my head around how to pass data to the split function. I'm trying to instantiate a number of goodness measures which compare treatment vs control within splits. A simple example is…
justin cress
  • 1,745
  • 5
  • 24
  • 35
3
votes
2 answers

Reading rpart Input Parameters from a Text Variable

I'm using rpart to make a decision tree. For example: fit <- rpart(Kyphosis ~ Age + Number + Start, data=kyphosis) How do I read in the formula part from a text file and get it in a format that rpart likes? I've tried: predictor_variables <-…
Dave
  • 5,436
  • 11
  • 48
  • 74
3
votes
0 answers

how to merge nodes in a decision tree in R

I would like to use a decision tree as proposed by Yan et al. 2004; Adaptive Testing With Regression Trees in the Presence of Multidimensionality (https://journals.sagepub.com/doi/epdf/10.3102/10769986029003293) That produce trees like this: It…
user2173836
  • 1,461
  • 2
  • 15
  • 19
3
votes
1 answer

How to plot the recursive partitioning from the rpart package

I want to plot a partition of a two-dimensional covariate space constructed by recursive binary splitting. To be more precise, I would like to write a function that replicates the following graph (taken from Elements of Statistical Learning, pag.…
riccardo-df
  • 512
  • 4
  • 9
3
votes
0 answers

How to get the dataset imputed by rpart using surrogate splits

rpart has the ability to deal with na values by imputing them from surrogate splits. By setting usesurrogate = 2 in rpart.control, na values are dealt with. Is there a way to get the imputed version of the dataset from the rpart object? num <- c(5,…
Mine
  • 831
  • 1
  • 8
  • 27
3
votes
1 answer

ROC Curve in R with rpart for a decision tree

I have an issue with creating a ROC Curve for my decision tree created by the rpart package. My goal was to predict "y" the success of the bank's marketing campaign. In the end, you can get a "yes" or a "no" as a possible answer. How can I…
Meax
  • 31
  • 1
  • 2
3
votes
2 answers

Extract split values from rpart object in R

I can't find the split values (or other data) for nodes in an rpart object. I see it with summary(sample_model) but not in the list or data frame Some sample data foo.df <- structure(list(type = c("fudai", "fudai", "fudai", "fudai", "fudai", …
Mark R
  • 775
  • 1
  • 8
  • 23
3
votes
1 answer

Wrong labels in rpart tree

I am running into some labels issue when using rpart in R. Here's my situation. I'm working on a dataset with categorical variables, here's an extract of my data head(Dataset) Entity IL CP TD Budget 2 1 3 2 250 5 2 2 1…
Layale
  • 153
  • 1
  • 9
3
votes
1 answer

How to plot a decision tree horizontally in R Markdown?

In R Markdown, I would like to plot a decision tree horizontally, so that it fits better the entire PDF page. This code plots it vertically: ```{r, message=FALSE, warning = FALSE, echo=FALSE, cache = FALSE} rpart.lrn <- makeLearner("classif.rpart",…
Javide
  • 2,477
  • 5
  • 45
  • 61
3
votes
1 answer

Overlay histogram plot in a decision tree in r

I want to create a decision tree plot which display an overlay histogram in each node as shown in the picture: The following code creates the left side picture: library(earth) library(rpart) library(rpart.plot) a <- rpart(O3~., data=ozone1,…
Ushuaia81
  • 495
  • 1
  • 6
  • 14
3
votes
0 answers

How to get SQL case or C style if-else-if code from rpart in R

I am nearly certain that someone has done this before me. The final code will not be in R but rather SQL. require(rpart) model=rpart.m=rpart(clazz~.,data=df) printcp(rpart.m) summary(rpart.m) rpart.m Produces something like so n= 2500 node),…
Chris
  • 1,219
  • 2
  • 11
  • 21
3
votes
2 answers

Getting "Variable Importance" from rpart

I'm performing a tree analysis using rpart, and I need to access the values of "Variable importance" as shown when the rpart object is printed. Is there a way to do that? Thanks!
Roberto
  • 86
  • 1
  • 7
3
votes
2 answers

caret::train pass extra parameters rpart

I'm building a decision tree with rpart via the caret::train function. What I'm trying to do is to set the minsplit parameter of rpart equal to 1, in order to prune it afterwards with the cp. What I get from here is that the parameters should be…
Pablo
  • 613
  • 7
  • 11