rpart

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

拜拜、爱过 提交于 2019-11-27 14:09:47
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 observation (in predicted dataset) has followed. Storing this data in tabular format, I can explain prediction with reason in a automated manner without opening R. Which means I want to got following. ObsID Probability PredictedClass PathFollowed 1 0.68 Safe CarAge < 10 & Country = Germany & Type = Compact & Price < 12822.5 2 0.76 Safe CarAge < 10 &

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

折月煮酒 提交于 2019-11-27 11:19:57
问题 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, total.sulfur.dioxide=data.train$total.sulfur.dioxide, alcohol=data.train$alcohol, quality=data.train$quality) Pre <- as.formula("pre ~ quality") fit <- rpart(Pre, method="class",data=Train) I am getting the following error : Error in eval(expr, envir, enclos) : object 'pre' not found 回答1: Don

The result of rpart is just with 1 root

爱⌒轻易说出口 提交于 2019-11-27 02:38:30
问题 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 +PipePressure > printcp(CART.fit) Regression tree: rpart(formula = fm.pipe, data = Data) Variables actually used in tree construction: character(0) Root node error: 299.84/569378 = 0.00052661 n= 569378 CP nsplit rel error xerror xstd 1 0.0033246 0 1 0 0 回答1