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
3
votes
0 answers

How to see the progress of the tree building during rpart execution?

Is there a way to see how much of the tree is built by the rpart at any point in time? Is there a way to see the progress of building or adding or splitting each node? If so, how do I do it?
Sandeep
  • 546
  • 1
  • 5
  • 22
3
votes
2 answers

How do I make a regression tree like this?

I would like to make a regression tree like the one in the picture. The tree was done in Cubist but I don't have that program. I do use R and Python. It seems to differ from the R packages rpart or tree in that the end nodes are linear formulas…
John
  • 336
  • 1
  • 4
  • 15
3
votes
2 answers

Cross-validating a CART model

In an assignment, we are asked to perform a cross-validation on a CART model. I have tried using the cvFit function from cvTools but got a strange error message. Here's a minimal…
krlmlr
  • 25,056
  • 14
  • 120
  • 217
3
votes
1 answer

rpart package: Save Decision Tree to PNG

I am working with a script that looks something like this: testplot <- plot(fit, uniform=TRUE, main="Classification Tree for MRC") text(fit, use.n=TRUE, all=TRUE, cex=.8) post(fit, file = "tree.ps", title = "Classification Tree") I'm…
rhae66
  • 293
  • 1
  • 4
  • 8
3
votes
3 answers

Rpart - NA handling

I am struggling with the NA functionality in the Rpart package. I got the following dataframe (code per below) Outcome VarA VarB 1 1 1 0 2 1 1 1 3 1 NA 1 4 0 0 1 5 0 0 0 6 0 NA …
user1885116
  • 1,757
  • 4
  • 26
  • 39
3
votes
1 answer

How to handle continuous and discrete variables in 'rpart' - decision trees using R?

I am creating some decision trees using the package rpart in R. I have discrete variables like age, no.of.children in my dataset. But the resulting decision tree has these variables n decimals. Which means, it is considered as continuous variables.…
Manoj G
  • 1,776
  • 2
  • 24
  • 29
2
votes
1 answer

rpart node assignment

Is it possible to extract the node assignment for a fitted rpart tree? What about when I apply the model to new data? The idea is that I would like to use the nodes as a way to cluster my data. In other packages (e.g. SPSS), I can save the…
Btibert3
  • 38,798
  • 44
  • 129
  • 168
2
votes
1 answer

How to extract the tree structure from an rpart object?

Warning to those who read this later ... My background in tree and graph algorithms meant that I expected this to be a simple question with a simple answer. But, it is not. How this could work in the context that I come from is, say, functions left…
Bruce
  • 301
  • 2
  • 13
2
votes
0 answers

Is there a way to replicate the SPSS CHAID algorithm in R?

I am trying to replicate the output obtained in SPSS doing it in R but I do not get the same results. I used the following libraries to help me, but I didn't get the same results as SPSS: library ("rpart") library ("readr") library…
2
votes
1 answer

rpart variable importance shows more variables than decision tree plots

I fitted an rpart model in Leave One Out Cross Validation on my data using Caret library in R. Everything is ok, but I want to understand the difference between model's variable importance and decision tree plot. Calling the variable importance with…
Carlo
  • 55
  • 7
2
votes
1 answer

Error in prune.tree can not prune singlenode tree in R.tree

The original data set is 7499 obs. of 19 variables. I'm using tree package in R to build up a classification tree. The result seems reasonable and the plot succeeded to show below: library(tree) tree.data = tree(Y~., data.train, control =…
Skye
  • 25
  • 4
2
votes
0 answers

Why using Rpart through caret transform my factor predictors into numerical?

I am running across the issue while working on my real data. Here is a reproducible example with some simulated data: library(caret) dummy <- cbind.data.frame(y = factor(rep(c("yes", "no"), each = 50)), x = factor(rep(c("A", "B"), each =…
MikeKatz45
  • 545
  • 5
  • 16
2
votes
1 answer

What is the loss function of `varImp` in `R` package `caret`?

I'm using varImp function from R package caret to get importance of variables. This is my code: library(caret) trctrl <- trainControl(method = "repeatedcv", number = 10, repeats = 20, search = "grid",summaryFunction =…
Mark
  • 1,577
  • 16
  • 43
2
votes
1 answer

Error in confusion matrix data can't have more levels CARET

dataset can be find here : https://archive.ics.uci.edu/ml/datasets/Bank+Marketing# set.seed(1234) ind <- sample(2, nrow(bank), replace = TRUE, prob = c(0.7, 0.3)) train.data <- bank[ind == 1, ] test.data <- bank[ind == 2, ] I was searching my…
2
votes
1 answer

Save a workspace and open it on another computer

I created a model (a tree object from a random forest) working on a old version of R (1.0.136) because the package (reprtree) I needed didn't work on the new version. Now I want to analyse my model using more recent packages (rpart.plot), which is…
c_R
  • 23
  • 3