scalation.analytics

KNN_Classifier

class KNN_Classifier extends ClassifierReal

The KNN_Classifier class is used to classify a new vector 'z' into one of 'k' classes. It works by finding its 'knn' 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 'knn' 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 that 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: Any): Boolean

    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

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

    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  5. 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
  6. 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
  7. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. 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

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

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

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

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  12. 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
  13. final def getClass(): Class[_]

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

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

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

    Find the 'knn' nearest neighbors (top-knn) to vector 'z' and store in topK array.

    Find the 'knn' nearest neighbors (top-knn) to vector 'z' and store in topK array.

    z

    the vector to be classified

  17. 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
  18. val md: Double

    the training-set size as a Double

    the training-set size as a Double

    Attributes
    protected
    Definition Classes
    ClassifierReal
  19. val n: Int

    the number of features/variables (# columns)

    the number of features/variables (# columns)

    Attributes
    protected
    Definition Classes
    ClassifierReal
  20. val nd: Double

    the feature-set size as a Double

    the feature-set size as a Double

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

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

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

    Definition Classes
    AnyRef
  24. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  25. 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
  26. def toString(): String

    Definition Classes
    AnyRef → Any
  27. 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
  28. final def wait(): Unit

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

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  30. 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