sjwhitworth/golearn — pull request #87 by Sentimentron (2014-09-30 22:05:49+00:00)
Title: Optimised version of KNN for Euclidean distances

This patch also:
* Completes removal of the `edf`/ package
* Corrects an erroneous print statement
* Introduces two new CSV functions
* `ParseCSVToInstancesTemplated` makes sure that
reading a second CSV file maintains strict Attribute
compatibility with an existing `DenseInstances`
* `ParseCSVToInstancesWithAttributeGroups` gives more control
over where Attributes end up in memory, important for
gaining predictable control over the KNN optimisation
* Decouples `BinaryAttributeGroup` from `FixedAttributeGroup` for
better casting support

On my desktop (Core i7 870 @ 2.93Ghz, [about half as fast as the fastest thing you can get](http://www.cpubenchmark.net/cpu.php?cpu=Intel+Core+i7+870+%40+2.93GHz)), this cuts the time KNN takes on the MNIST dataset from 74.803 seconds to around 9.616/9.818 seconds, with the same overall accuracy.

Some strict conditions are needed for the optimisation to work: the training and prediction instances must have exactly the same attributes in exactly the same order, and class attributes can't be mixed in with data attributes within the same `AttributeGroup`. The revised `knn.go` implements these checks.