Pass custom weight function to 'kknn' model in Caret package I am working on school project, where I'm trying to implement improvement for weighted kNN in CARET package. I basically need to replace standard 'weight' function used in KKNN model to something more sophisticated, described here: http://globaljournals.org/GJCST_Volume10/7-A-Modification-on-K-Nearest-Neighbor-Classifier.pdf
However, since I'm beginner, I have absolutely no idea how to do it. KKNN library documentation and examples are also not very helpful to me http://www.inside-r.org/packages/cran/kknn/docs/kknn
I have also considered to write my custom implementation of kNN, but it looks it is too much unnecessary work to make it compatible with Caret.
Do you have some clues, how should I approach this?
Thanks very much!
Here is how I use standard weigthed kNN:
library(ISLR)
library(caret)

set.seed(300)
Smarket_cut = Smarket[1:100,]
indxTrain <- createDataPartition(y = Smarket_cut$Direction,p = 0.75,list = FALSE)
training <- Smarket_cut[indxTrain,]
testing <- Smarket_cut[-indxTrain,]

############################################################################################
# Preprocessing
############################################################################################

trainX <- training[,!(names(training) %in% c("Today", "Direction"))]
preProcValues <- preProcess(x = trainX,method = c("center", "scale"))
preProcValues

############################################################################################
# Training and train control
############################################################################################
set.seed(400)
ctrl <- trainControl(method="repeatedcv",repeats = 3) #,classProbs=TRUE,summaryFunction = twoClassSummary)
knnFit <- train(Direction ~ ., data = training, method = "kknn", trControl = ctrl, preProcess = c("center","scale"), tuneLength = 20)

knnFit

plot(knnFit)

knnPredict <- predict(knnFit,newdata = testing )
confusionMatrix(knnPredict, testing$Direction )

 A: I realize this is an old post, but still a useful question.
Are you trying to use the additional tuning parameters in kknn that allow weighting? 
If so, you can use:
library(kknn)

Tune the cross-validation
trctrl <- trainControl(method = 'repeatedcv', number = 10, repeats = 3)

Tune kknn parameteres
tuneGrid <- expand.grid(kmax = 1:50,            # allows to test a range of k values
                        distance = 1:20,        # allows to test a range of distance values
                        kernel = c('gaussian',  # different weighting types in kknn
                               'triangular',
                               'rectangular',
                               'epanechnikov',
                               'optimal'))

Fit models
kknn_fit <- train(y ~ ., 
                  data = training, 
                  method = 'kknn',
                  trControl = trctrl,
                  preProcess = c('center', 'scale'),
                  tuneGrid = tuneGrid,
                  tuneLength = 10)`

kknn_fit will return the best fitting model. To get the results from all the different models you tuned, look at the kknn_fit$results object. 
