Created
June 9, 2011 17:18
-
-
Save actsasgeek/1017210 to your computer and use it in GitHub Desktop.
Changes to Nearest Neighbor object to support loading instances from a file.
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
object NearestNeighbor { | |
def create( libraryFileName: String): NearestNeighbor = { | |
val instances = getInstancesFromFile( libraryFileName) | |
val library = createLibraryFromCSVs( instances) | |
new NearestNeighbor( library) | |
} | |
def getInstancesFromFile( libraryFileName: String): List[ String] = { | |
Source.fromFile( new File( libraryFileName)).getLines().toList | |
} | |
def createLibraryFromCSVs( instances: List[ String]): List[Instance] = { | |
instances.map( Instance.parseString( _)) | |
} | |
def main( args: Array[ String]) { | |
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