Added brian.md to 04-ML_KNN

Oh. I see.


On Monday, August 4, 2014 4:35 PM, Aaron Schumacher <notifications@github.com> wrote:
 


In 04-ML_KNN/brian.R:
> @@ -0,0 +1,23 @@
> +assign.score <- function(test.row, labels, training.data, K = 1) {
> +  training.data$score <- apply(training.data[,1:4], 1, function(x) { sqrt((x[1] - test.row[1])^2 + (x[2] - test.row[2])^2 + (x[3] - test.row[3])^2 + (x[4] - test.row[4])^2)})
> +  sorted <- training.data[with(training.data, order(score)), ]
> +  return(sample(sorted[K, as.character(labels)], 1))
> +  # This does not implement the voting functionality.
> +}
> +
> +iris.nn <- function(training_data, labels, test_data, K = 1) {
> +  test_data[labels] <- NA
> +  predicto <- apply(test_data, 1, function(x){ assign.score(x, labels, training_data) })
> +  test_data[labels] <- predicto
> +  return(test_data) 
This is another design change; what we were really looking for was a function that returns a vector of predicted labels, rather than a data frame with labels changed.
—
Reply to this email directly or view it on GitHub.