rpart icon indicating copy to clipboard operation
rpart copied to clipboard

How to specify a loss matrix in rpart?

Open A-Pai opened this issue 1 year ago • 1 comments

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 avatar Feb 24 '24 09:02 A-Pai

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

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

A-Pai avatar Feb 24 '24 12:02 A-Pai