Created
June 8, 2011 19:46
-
-
Save actsasgeek/1015211 to your computer and use it in GitHub Desktop.
Improved version of the Nearest Neighbor "walking skeleton"
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
class Instance( featureValues: List[Double], classLabel: Option[String] = None) { | |
def assignClassLabel( assignedClassLabel: Option[String]): Instance = { | |
new Instance( featureValues, assignedClassLabel) | |
} | |
override def toString(): String = { | |
"<'"+classLabel.getOrElse( "None")+"' is ["+featureValues.mkString( ", ")+"]>" | |
} | |
} | |
class NearestNeighbor( library: List[Instance]) { | |
def classify( query: Instance): Instance = { | |
query.assignClassLabel( Some( "Unknown")) | |
} | |
} | |
object NearestNeighbor { | |
def create( libraryFileName: String): NearestNeighbor = { | |
val library = new List[ Instance]( 10) | |
new NearestNeighbor( library) | |
} | |
} | |
val nearestNeighbor = NearestNeighbor.create( "library.data") | |
val query = new Instance( List( 0.0, 0.0, 0.0, 0.0)) | |
val classifiedQuery = nearestNeighbor.classify( query) | |
println( classifiedQuery) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment