Class AbstractKNearestNeighbours

    • Field Detail

      • numOutcomes

        protected final int numOutcomes
      • k

        protected final int k
    • Constructor Detail

      • AbstractKNearestNeighbours

        public AbstractKNearestNeighbours​(int numOutcomes,
                                          int k)
        Constructs a new knn classifier.
        Parameters:
        numOutcomes - the number of different outcomes that can be predicted.
        k - the number of neighbours to analyse to get a prediction (it does so by majority voting).
    • Method Detail

      • predict

        public de.jungblut.math.DoubleVector predict​(de.jungblut.math.DoubleVector features)
        Description copied from interface: Predictor
        Classifies the given features.
        Returns:
        If the number of outcomes is 2 (binary prediction) the returned vector contains the class id (0 or 1) at the first index. If not, a histogram of the classes that were predicted.
      • predictProbability

        public de.jungblut.math.DoubleVector predictProbability​(de.jungblut.math.DoubleVector features)
        Description copied from interface: Predictor
        Classifies the given features.
        Specified by:
        predictProbability in interface Predictor
        Overrides:
        predictProbability in class AbstractPredictor
        Returns:
        a vector that returns the probability of all outcomes. The output vector should sum to one.
      • getNearestNeighbours

        protected abstract java.util.List<de.jungblut.jrpt.VectorDistanceTuple<de.jungblut.math.DoubleVector>> getNearestNeighbours​(de.jungblut.math.DoubleVector feature,
                                                                                                                                    int k)
        Find the k nearest neighbours for the given feature.
        Parameters:
        feature - the feature to find neighbours for.
        k - the number of neighbours to find.
        Returns:
        a list of VectorDistanceTuple's that contain the outcome of the retrieved vectors.