Caret using C5.0 method, how to plot the final tree

1.6k views Asked by At

I am using the train package method=C5.0 and would like to see the finalModel plotted as a tree. The resulting tree has been defined :

The final values used for the model were trials = 15, model = tree and winnow = FALSE.

When I tried to plot the tree using plot or the rattle's fancyRplotModel, i get the errors below:

Using plot:

plot(diabetes.c50$finalModel,trials=15)
Error in plot(diabetes.c50$finalModel, trials = 15) : 
  object 'diabetes.c50' not found

Using rattle:

fancyRpartPlot(diabetes.C50$finalModel,trials=15)
Error in if (model$method == "class") { : argument is of length zero

The finalModel has been defined:

> diabetes.C50$finalModel

Call:
C5.0.default(x = structure(c(6, 8, 0, 8, 4, 10, 10, 1, 5, 7, 1, 1, 3, 8, 7, 9, 11, 10, 7, 1, 13, 5, 5, 3, 6, 4, 11, 9, 4, 3, 9, 7, 0,
 "outcome", seed = 2187L), .Names = c("subset", "bands", "winnow", "noGlobalPruning", "CF", "minCases", "fuzzyThreshold",
 "sample", "earlyStopping", "label", "seed")), verbose = FALSE)

Classification Tree
Number of samples: 538 
Number of predictors: 8 

Number of boosting iterations: 15 
Average tree size: 12.9 

Non-standard options: attempt to group attributes
1

There are 1 answers

0
Graham Williams On

The data structure representing a C5.0 tree is different to that representing an rpart tree. Rattle's fancyRpartPlot() assumes an rpart tree hence you get an error (recent versions of rattle check for the model class and explain this error rather than failing with the above indecipherable message).

You first error though looks like a typo and the error message is self explanatory. You meant diabetes.C50$finalModel rather than diabetes.c50$finalModel (capital C50 rather than lower c50).