Skip to content

Instantly share code, notes, and snippets.

@actsasgeek
Created June 9, 2011 02:29
Show Gist options
  • Save actsasgeek/1015926 to your computer and use it in GitHub Desktop.
Save actsasgeek/1015926 to your computer and use it in GitHub Desktop.
The spec for NearestNeighbor
class NearestNeighborSpec extends Spec with ShouldMatchers {
describe( "A Nearest Neighbor classifier") {
val library = List(
new Instance( List( 3.0, 3.0), Some( "A")),
new Instance( List( 4.0, 2.0), Some( "A")),
new Instance( List( 2.0, 2.0), Some( "B"))
)
val nearestNeighbor = new NearestNeighbor( library)
it( "can find the 1st closest example in the library to a query") {
val query = new Instance( List( 0.0, 0.0))
val queryResult = nearestNeighbor.classify( query)
queryResult.classLabel should be === Some( "B")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment