Commits

Gary Chambers committed 1c5914d

Updated Model#classify to correctly compare against K points

Comments (0)

Files changed (1)

 
 		return prediction;
 	};
+	/**
+	 * Classifies a point based on the
+	 * dimensions of the training data.
+	 * @param {Number} K How many adjacent points to compare
+	 * @param {Point} point
+	 */
+	{
+		var distance,
+			f, i, j, p;
+
+		i = this.points.length;
+
+		points = [];
+
+		while( i-- )
+			p = this.points[ i ];
+			distance = 0;
+
+			{
+				f = this.features[ j ];
+				distance += Math.pow(
+					f.calcDistance( point, p ),
+					2
+				);
+
+			distance = Math.sqrt( distance );
+		}
+		points = sortPoints( points );
+		return predictCategory( K, point, points );
+	};
 })( this );