Created
October 27, 2012 00:52
-
-
Save bdewilde/3962506 to your computer and use it in GitHub Desktop.
benchmark knn model from kaggle hand-written digit classification competition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# fast nearest neighbor package | |
library(FNN) | |
# training and test sets, with variable names in the first row | |
train <- read.csv("train.csv", header=TRUE) | |
test <- read.csv("test.csv", header=TRUE) | |
# split train data frame in two | |
# first column is class labels (0, 1, ..., 9) | |
labels <- train[,1] | |
train <- train[,-1] | |
# save only the knn's class predictions for each observation in test set | |
results <- (0:9)[knn(train, test, labels, k = 10, algorithm="cover_tree")] | |
# output to file as a single column of class predictions | |
write(results, file="knn_benchmark.csv", ncolumns=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment