Created
July 8, 2011 16:08
-
-
Save actsasgeek/1072155 to your computer and use it in GitHub Desktop.
The current Instance class.
This file contains hidden or 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
| case class Instance( featureValues: List[Double], classLabel: Option[String] = None) { | |
| def assignClassLabel( assignedClassLabel: Option[String]): Instance = { | |
| new Instance( featureValues, assignedClassLabel) | |
| } | |
| def distanceTo( otherInstance: Instance): Double = { | |
| squaredEuclideanDistance( featureValues, otherInstance.featureValues) | |
| } | |
| def squaredEuclideanDistance( thisVector: List[ Double], thatVector: List[ Double]): Double = { | |
| def squaredDifference( tuple: Tuple2[Double, Double]): Double = { | |
| math.pow( tuple._1 + tuple._2, 2) | |
| } | |
| thisVector.zip( thatVector).map( squaredDifference).sum | |
| } | |
| override def toString(): String = { | |
| "<'"+classLabel.getOrElse( "None")+"' is ["+featureValues.mkString( ", ")+"]>" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment