0

I am using R version 3.3.2 on windows 8. I am trying to create a decision tree using C5.0 algorithm in C50 package. Whenever I use cost matrix, the decision tree length is coming to be zero. On using similar code as well as data set, I have seen people getting results. Although, I am not absolutely certain about exact similarity of data set. Is it possible? Am I doing something wrong? I am attaching my code.

C5.0_test<-function(credit){
  credit$default<-factor(credit$default, levels = c(1, 2), labels = ("non-defaulter, defaulter"))
  set.seed(12345)
  credit_rand <- credit[order(runif(1000)), ]
  credit_train <- credit_rand[1:900, ]
  credit_test  <- credit_rand[901:1000, ]
  credit_model <- C5.0.default(credit_train[-17], credit_train$default)
  credit_pred <- predict(credit_model, credit_test)
  credit_boost10 <- C5.0.default(credit_train[-17], credit_train$default, trials = 10)
  credit_boost_pred10 <- predict(credit_boost10, credit_test)
  error_cost <- matrix(c(0, 1, 2, 0), nrow = 2) # create a cost matrix
  credit_cost <- C5.0.default(credit_train[-17], credit_train$default,
                      costs = error_cost) # Apply the cost matrix to the tree
  credit_cost_pred <- predict(credit_cost, credit_test)
  CrossTable(credit_test$default, credit_cost_pred, prop.chisq = F, prop.c = F, prop.r = F)
}
  • Are you getting any errors? One possible option is to type `debug(C5.0_test)` and see what is happening within the function. – manotheshark Feb 27 '17 at 21:07
  • What happens with a trivial cost matrix like `matrix(c(1,1,1,1), nrow=2)`? – vincentmajor Feb 27 '17 at 21:11
  • Also, as a new member you should read about [minimal reproducible examples.](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) Right now, no one can help you because we don't have a small sample of your data. – vincentmajor Feb 27 '17 at 21:14
  • I am not getting any errors. Just the tree size is zero. I tried with matrix(c(01,1,0), nrow=2), which makes it the case without any cost matrix and it is working fine and I am getting tree length as 57. – Manuj Garg Feb 27 '17 at 21:39

0 Answers0