I'm using the mlr package for knn (both for classification and regression problems), eg:
knnTask <- makeClassifTask(data = df_train, target = "CLASS")
knn <- makeLearner("classif.knn", par.vals = list("k" = 4))
knnModel <- train(knn, knnTask )
knnPred <- predict(knnModel, newdata = df_train)
I have two question:
1) Is there a way to view all individual neighbors when predicting?
2) Furthermore, is there a way to change the voting rule, eg using the median instead of the mean when applying knn to a regression problem?
If possible, I would like to stick to the mlr environment.
Thanks!
Best,
Unfortunately, neither of those are supported (and regression for knn
isn't supported at all). This is because the underlying knn
classifier doesn't support these things -- nothing to do with mlr itself.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.