1

I'm using the mlr package for knn (both for classification and regression problems), e.g.:

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, e.g. 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,

Adam_Smith
  • 31
  • 3
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Feb 07 '20 at 17:06

1 Answers1

1

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.

Lars Kotthoff
  • 107,425
  • 16
  • 204
  • 204