scalation.analytics

KNN_Classifier

class KNN_Classifier extends ClassifierReal

The KNN_Classifier class is used to classify a new vector 'z' into one of 'c' classes. It works by finding its 'k' nearest neighbors. These neighbors essentially vote according to their classification. The class with most votes is selected as the classification of 'z'. Using a distance metric, the 'k' vectors nearest to 'z' are found in the training data, which is stored row-wise in the data matrix 'x'. The corresponding classifications are given in the vector 'y', such the classification for vector 'x(i)' is given by 'y(i)'.

Linear Supertypes
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. KNN_Classifier
  2. ClassifierReal
  3. Error
  4. Classifier
  5. AnyRef
  6. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new KNN_Classifier(x: MatrixD, y: VectorI, fn: Array[String], k: Int, cn: Array[String], knn: Int = 3)

    x

    the vectors/points of classified data stored as rows of a matrix

    y

    the classification of each vector in x

    fn

    the names for all features/variables

    k

    the number of classes

    cn

    the names for all classes

    knn

    the number of nearest neighbors to consider

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def classify(z: VectorD): (Int, String)

    Given a new point/vector 'z', determine which class it belongs to (i.

    Given a new point/vector 'z', determine which class it belongs to (i.e., the class getting the most votes from its 'knn' nearest neighbors.

    z

    the vector to classify

    Definition Classes
    KNN_ClassifierClassifier
  8. def classify(z: VectorI): (Int, String)

    Given a new discrete (integer-valued) data vector 'z', determine which class it belongs to, by first converting it to a vector of doubles.

    Given a new discrete (integer-valued) data vector 'z', determine which class it belongs to, by first converting it to a vector of doubles.

    z

    the vector to classify

    Definition Classes
    ClassifierRealClassifier
  9. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  10. def distance(u: VectorD, v: VectorD): Double

    Compute a distance metric between vectors/points u and v.

    Compute a distance metric between vectors/points u and v.

    u

    the first vector/point

    v

    the second vector/point

  11. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  12. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  13. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  14. def flaw(method: String, message: String): Unit

    Show the flaw by printing the error message.

    Show the flaw by printing the error message.

    method

    the method where the error occurred

    message

    the error message

    Definition Classes
    Error
  15. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  16. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  17. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  18. def kNearest(z: VectorD): Unit

    Find the knn nearest neighbors (top-knn) to vector 'z'.

    Find the knn nearest neighbors (top-knn) to vector 'z'.

    z

    the vector to be classified

  19. val m: Int

    the number of data vectors in training-set (# rows)

    the number of data vectors in training-set (# rows)

    Attributes
    protected
    Definition Classes
    ClassifierReal
  20. val md: Double

    the training-set size as a Double

    the training-set size as a Double

    Attributes
    protected
    Definition Classes
    ClassifierReal
  21. val n: Int

    the number of features/variables (# columns)

    the number of features/variables (# columns)

    Attributes
    protected
    Definition Classes
    ClassifierReal
  22. val nd: Double

    the feature-set size as a Double

    the feature-set size as a Double

    Attributes
    protected
    Definition Classes
    ClassifierReal
  23. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  24. final def notify(): Unit

    Definition Classes
    AnyRef
  25. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  26. def replace(i: Int, di: Double): Double

    Remove the most distant neighbor and add new neighbor 'i'.

    Remove the most distant neighbor and add new neighbor 'i'. Maintain the 'topK' nearest neighbors in sorted order farthest to nearest.

  27. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  28. def test(xx: MatrixD, yy: VectorI): Double

    Test the quality of the training with a test-set and return the fraction of correct classifications.

    Test the quality of the training with a test-set and return the fraction of correct classifications.

    xx

    the real-valued test vectors stored as rows of a matrix

    yy

    the test classification vector, where yy_i = class for row i of xx

    Definition Classes
    ClassifierReal
  29. def toString(): String

    Definition Classes
    AnyRef → Any
  30. def train(): Unit

    Training involves resetting the data structures before each classification.

    Training involves resetting the data structures before each classification. KNN uses lazy training, so most of it is done during classification.

    Definition Classes
    KNN_ClassifierClassifier
  31. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  32. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  33. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from ClassifierReal

Inherited from Error

Inherited from Classifier

Inherited from AnyRef

Inherited from Any

Ungrouped