bethatkinson / rpart

Recursive Partitioning and Regression Trees
46 stars 24 forks source link

How to specify a loss matrix in rpart? #61

Open A-Pai opened 7 months ago

A-Pai commented 7 months ago

Cost for mis-classification can be used as below:

fit <- rpart(target ~ ., data=dataset, method="class", parms=list(loss=matrix(c(0,1,2,0), byrow=TRUE, nrow=2)))

If there are two class A and B, the loss of A wrongly judged as B is 1, and the loss of B wrongly judged as A is 2, how to set the loss matrix?

A-Pai commented 7 months ago

image Horizontal is the actual value, vertical is the judgment value

loss=matrix(c(0,1,2,0), byrow=TRUE, nrow=2))