Class KNNClassifier<O>

  • Type Parameters:
    O - the type of objects handled by this algorithm
    All Implemented Interfaces:
    Algorithm, Classifier<O>

    @Description("Lazy classifier classifies a given instance to the majority class of the k-nearest neighbors.")
    public class KNNClassifier<O>
    extends java.lang.Object
    implements Classifier<O>
    KNNClassifier classifies instances based on the class distribution among the k nearest neighbors in a database.
    Arthur Zimek
    • Field Detail

      • k

        protected int k
        Holds the value of @link #K_PARAM}.
      • distance

        protected Distance<? super O> distance
        Distance function
    • Constructor Detail

      • KNNClassifier

        public KNNClassifier​(Distance<? super O> distance,
                             int k)
        distance - Distance function
        k - Number of nearest neighbors to access.
    • Method Detail

      • getInputTypeRestriction

        public TypeInformation[] getInputTypeRestriction()
        Description copied from interface: Algorithm
        Get the input type restriction used for negotiating the data query.
        Specified by:
        getInputTypeRestriction in interface Algorithm
        Type restriction
      • buildClassifier

        public void buildClassifier​(Database database,
                                    Relation<? extends ClassLabel> labels)
        Description copied from interface: Classifier
        Performs the training. Sets available labels.
        Specified by:
        buildClassifier in interface Classifier<O>
        database - the database to build the model on
        labels - the classes to be learned
      • classify

        public ClassLabel classify​(O instance)
        Description copied from interface: Classifier
        Classify a single instance.
        Specified by:
        classify in interface Classifier<O>
        instance - an instance to classify
        predicted class label of the given instance
      • classProbabilities

        public double[] classProbabilities​(O instance,
                                           java.util.ArrayList<ClassLabel> labels)
      • model

        public java.lang.String model()
        Description copied from interface: Classifier
        Produce a String representation of the classification model.
        Specified by:
        model in interface Classifier<O>
        a String representation of the classification model
      • getDistance

        public Distance<? super O> getDistance()
        Returns the distance.
        the distance