Skip to content

Instantly share code, notes, and snippets.

@actsasgeek
Created July 8, 2011 17:37
Show Gist options
  • Select an option

  • Save actsasgeek/1072337 to your computer and use it in GitHub Desktop.

Select an option

Save actsasgeek/1072337 to your computer and use it in GitHub Desktop.
Instance object...scalafied!
object Instance {
def parseCSV( instanceAsCSVString: String): Instance = {
def extractFeatureValues( tokenizedFeatures: List[ String]): List[ Option[Double]] = {
tokenizedFeatures.map { token =>
try {
Some( token.toDouble)
} catch {
case nfe: NumberFormatException => {
if ( token == "?") {
None
} else {
throw new MalformedInstanceException
}
}
}
}
}
val tokenizedInstance = instanceAsCSVString.split( ",").toList
val featureValues = extractFeatureValues( tokenizedInstance.init)
val classLabel = tokenizedInstance.last
new Instance( featureValues, Some( classLabel))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment