In the current version the predict function returns only the fitted values for the test data. Would it be possible to add a type parameter so the function could return the probabilities for each class? This would make it possible to obtain the probabilities using predict.train.kknn.
For instance:
predict.kknn <- function(object, type = 'raw', ...)
{
pred <- switch(type, raw = object$fit,
prob = object$prob,
stop('invalid type for prediction'))
pred
}
predict.train.kknn <- function (object, newdata, ...)
{
if (missing(newdata))
return(object$fit)
res = kknn(formula(terms(object)), object$data, newdata,
k = object$best.parameters$k, kernel = object$best.parameters$kernel,
distance = object$distance)
return(predict(res, ...))
}
In the current version the predict function returns only the fitted values for the test data. Would it be possible to add a type parameter so the function could return the probabilities for each class? This would make it possible to obtain the probabilities using predict.train.kknn.
For instance: