[R] Rpart, custom penalty for an error
Maciej Bliziński
m.blizinski at wit.edu.pl
Fri Sep 15 23:26:11 CEST 2006
On Sun, 2006-09-10 at 20:36 +0100, Prof Brian Ripley wrote:
> > I am however interested in areas where the probability of success is
> > noticeably higher than 5%, for example 20%. I've tried rpart and the
> > weights option, increasing the weights of the success-observations.
>
> You are 'misleading' rpart by using 'weights', claiming to have case
> weights for cases you do not have. You need to use 'cost' instead.
As for the rpart() function, the `cost' parameter is for scaling the
variables, not for the cost of misclassifications. To specify it, the
parameter `parms' needs to be used, as a list with a `loss' element, in
form of a matrix. In other words, cost parm is not for cost, use loss
parm of the parms parm. Example usage:
tr <- rpart(y ~ x, data = some.data, method = 'class',
parms = list(loss = matrix(c(0, 1, 20, 0), nrow = 2)))
> This is a standard issue, discussed in all good books on classification
> (including mine).
Yes, in MASS, section 12.2, Classification Theory, page 338 (fourth edition).
I was looking for it in section 9.2, where rpart() is discussed.
Thanks!
Regards,
Maciej
--
http://automatthias.wordpress.com
More information about the R-help
mailing list