Skip to content

Instantly share code, notes, and snippets.

@bdewilde
Created October 29, 2012 21:56
Show Gist options
  • Save bdewilde/3976802 to your computer and use it in GitHub Desktop.
Save bdewilde/3976802 to your computer and use it in GitHub Desktop.
optimal implementation of a weighted knn model
# load test datasets
test <- read.csv("test.csv", header=TRUE)
# train the optimal kknn model
model <- kknn(as.factor(label) ~ ., train, test, k=9, kernel="triangular")
results <- model$fitted.values
# save the class predictions in a column vector
write(as.numeric(levels(results))[results], file="kknn_submission.csv", ncolumns=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment