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

R rpart: No splits if I remove less important variables

I am trying to understand how rpart works in a project that I am trying to complete. I am relatively new to R but I have a lot of experience using SAS to build a variety of analytical models. First I ran this piece of code mtree1 <- rpart(X17~.,…
2
votes
1 answer

Tuning parms in rpart with MLR package?

I am trying to use the MLR package to tune the hyper-parameters of a decision tree built with the rpart package. Even if I can tune the basic parameters of the decision tree (e.g. minsplit, maxdepth and so on), I am not able to properly set the…
aprospero
  • 529
  • 3
  • 14
2
votes
1 answer

How to turn an rpart object into a dendrogram? (as.dendrogram.rpart ?))

I would like a way to turn an rpart tree object into a nested list of lists (a dendrogram). Ideally, the attributes in each node will include the information in the rpart object (impurity, variable and rule that is used for splitting, the number of…
Tal Galili
  • 24,605
  • 44
  • 129
  • 187
2
votes
0 answers

R: Error in model.frame.default(formula, data) : variable lengths differ (found for '.....')

I'm trying to tune my decision tree in R. I use the tune.rpart function in e1071 package. I have the following code: fm <- formula(classNames[y_train] ~ AirTemperature + WindSpeed + AtmosphericPressure + …
2
votes
1 answer

R predictive model reason for predicitions and propensity %

very new to R and machine learning however I'm having to undertake a project to predict customer churn based on a number of variables e.e. length of service, number of credit notes issued, number of missed deliveries, number of price increases…
2
votes
2 answers

changing font size in regression tree plot

library(rpart) library(rpart.plot) fit <- rpart(Kyphosis ~ Age + Number + Start, data = kyphosis) prp(fit, type = 4, extra = 101, leaf.round = 1, fallen.leaves = TRUE, varlen = 0, tweak = 0.8) I'm trying to get the text to fit inside the…
Adrian
  • 9,229
  • 24
  • 74
  • 132
2
votes
1 answer

Conflicting splits in CART decision tree

I'm currently using decision trees (CART) in R with packages rpart and rattle for classification. After training my CART tree, I found that some rules conflict with each other. Consider the following tree, with the conflicting rules indicated by…
Sharp Yan
  • 345
  • 1
  • 9
2
votes
1 answer

rpart change text size in node

I would like to change the text size of a node in rpart. The text does not fit into the box of the node if the text is too large. Still, there should be enough space. rpart.plot(pruned_tree_model, type=0,tweak=1.5,leaf.round=0) are there some…
Bukowski
  • 53
  • 1
  • 7
2
votes
1 answer

How to get root node error value from rpart printcp function?

From rpart package, it is possible to get following output from printcp function. But how to extract the root node error value? Classification tree: rpart(formula = survived ~ ., data = ptitanic, control = rpart.control(cp = 1e-04)) #Variables…
Ivan
  • 163
  • 1
  • 3
  • 15
2
votes
1 answer

Invalid prediction for "rpart" object Error

I am using the exact code for best first search from page 4 of this CRAN document (https://cran.r-project.org/web/packages/FSelector/FSelector.pdf), which uses the iris dataset. It works just fine on the iris dataset, but does not work on my ow…
Ashley A Holmes
  • 69
  • 3
  • 5
  • 10
2
votes
1 answer

Why do I get different cross validation errors with rpart if I specify parms with default values?

I am puzzled by the following: set.seed(144) df = data.frame(outcome=as.factor(sample(c('a','b','c'), 1000, replace=T)), x=rnorm(1000), y=rnorm(1000), z=rnorm(1000)) library(rpart) fit.default = rpart(outcome ~ x + y + z, data=df,…
Palace Chan
  • 8,845
  • 11
  • 41
  • 93
2
votes
1 answer

Why are the cp values in plotcp() chart modified from the original table?

What are the cp values on the rpart plotcp() chart? I would expect these values to match the cp column in printcp(), but instead the following scale is calculated (from the plotcp code): p.rpart <- x$cptable cp0 <- p.rpart[, 1L] cp <- sqrt(cp0 *…
Robert Kubrick
  • 8,413
  • 13
  • 59
  • 91
2
votes
1 answer

R classification tree with Rpart

I have some data which I would like to segment. My first thought was classification tree in R from Rpart package. My training data consists of many explanatory variables and one 0-1 response variable named "sold". The response value "1" appears in…
2
votes
1 answer

An error occurs when calling rpart for a large data set

I have a large data set which has 100k data fields. When I try str() or view the full data no glitched occurs, but when I run rpart on the training set it takes sometime and after about 3-4 minutes it shows up the following error, Error: Unable to…
Dinal24
  • 3,162
  • 2
  • 18
  • 32
2
votes
3 answers

Running rpart over multiple subsets of a data frame

I'm creating a decision tree with the R rpart package based on x number of variables and a dataframe: fit<-rpart(y~x1+x2+x3+x4,data=(mydataframe), control=rpart.control(minsplit = 20, minbucket = 0, cp=.01)) But instead of using the entire…
vko
  • 23
  • 5