How to set costs matrix for C5.0 Package in R?

浪尽此生 提交于 2019-12-04 11:34:46

Here is a quote from the help page of C5.0 (version 0.1.0-15):

The cost matrix should by CxC, where C is the number of classes. Diagonal elements are ignored. Columns should correspond to the true classes and rows are the predicted classes. For example, if C = 3 with classes Red, Blue and Green (in that order), a value of 5 in the (2,3) element of the matrix would indicate that the cost of predicting a Green sample as Blue is five times the usual value (of one).

Following the example in the help page, this would be a cost matrix:

cost.matrix <- matrix(c(
  NA, 2, 4,
  3, NA, 5,
  7, 1, NA

), 3, 3, byrow=TRUE)

rownames(cost.matrix) <- colnames(cost.matrix) <- c("Red", "Blue", "Green")

cost.matrix

      Red Blue Green
Red    NA    2     4
Blue    3   NA     5
Green   7    1    NA

This would mean the following:

  • Predicting a red sample as blue is 3 times the value as the usual value (one)
  • Predicting a red sample as green is 7 times the value as the usual
  • Predicting a blue sample as red is 2 times the ususal value
  • Predicting a blue sample as green is 1 times the ususal value
  • Predicting a green sample as red is 4 times the ususal value
  • Predicting a green sample as blue is 5 times the usual value
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!