Skip to content

Instantly share code, notes, and snippets.

@actsasgeek
Created June 8, 2011 19:04
Show Gist options
  • Save actsasgeek/1015104 to your computer and use it in GitHub Desktop.
Save actsasgeek/1015104 to your computer and use it in GitHub Desktop.
"Walking skeleton" of the nearest neighbor algorithm.
class Instance( featureValues: List[Double], var classLabel: String) {
}
class NearestNeighbor( library: List[Instance]) {
def classify( query: Instance) {
query.classLabel = "unknown"
}
}
object NearestNeighbor {
def create( libraryFileName: String): NearestNeighbor = {
val library = new List[ Instance]( 10)
new NearestNeighbor( library)
}
}
val examples = NearestNeighbor.create( "library.data")
val query = new Instance( List( 0.0, 0.0, 0.0, 0.0), null)
examples.classify( query)
println( query.classLabel)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment