Skip to content

Instantly share code, notes, and snippets.

@actsasgeek
Created July 8, 2011 16:01
Show Gist options
  • Select an option

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

Select an option

Save actsasgeek/1072140 to your computer and use it in GitHub Desktop.
the current Instance object.
object Instance {
def parseString( instanceAsCSVString: String): Instance = {
def extractFeatureValues( parsedInstance: Array[ String]): List[ Double] = {
val featuresStartIndex = 0
val featuresEndIndex = parsedInstance.length - 2
val featureBuffer = new ListBuffer[Double]()
for ( index <- featuresStartIndex to featuresEndIndex) {
featureBuffer += parsedInstance( index).toDouble
}
featureBuffer.toList
}
val parsedInstance = instanceAsCSVString.split( ",")
val featureValues = extractFeatureValues( parsedInstance)
val classLabelIndex = parsedInstance.length - 1
val classLabel = parsedInstance( classLabelIndex)
new Instance( featureValues, Some( classLabel))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment