Documentation of 'jsat.classifiers.knn.LWL' Java class
LWL
jsat.classifiers.knn

Class LWL

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, Classifier, Parameterized, Regressor


    public class LWL
    extends java.lang.Object
    implements Classifier, Regressor, Parameterized
    Locally Weighted Learner (LW) is the combined generalized implementation of Locally Weighted Regression (LWR) and Locally Weighted Naive Bayes (LWNB). The concept is simple, prediction begins in a normal NN style. Instead of returning the prediction result as the average / majority of the found neighbors, a classifier is trained to represent the local area that is represented by the neighbors. The prediction result is then based on this locally trained model.
    Because NN search is already slow, and increasing the search size increases the search time, it is recommended to use moderate sized values of k with simple models such as NaiveBayes and LinearRegression.
    If the learning algorithm used does not support weighted data points, it will be as if the uniform kernel fucntion was used, regardless of whatever kernel function was set.

    See:
    • Atkeson, C., Moore, A.,&Schaal, S. (1997). Locally Weighted Learning. Artificial intelligence review, 11–73.
    • Frank, E., Hall, M.,&Pfahringer, B. (2003). Locally Weighted Naive Bayes. Proceedings of the Conference on Uncertainty in Artificial Intelligence (pp. 249–256). Morgan Kaufmann.
    See Also:
    Serialized Form
    • Constructor Detail

      • LWL

        public LWL(Classifier classifier,
                   int k,
                   DistanceMetric dm)
        Creates a new LWL classifier
        Parameters:
        classifier - the local classifier to
        k - the number of neighbors to create a local classifier from
        dm - the metric to use when selecting the nearest points to a query
      • LWL

        public LWL(Classifier classifier,
                   int k,
                   DistanceMetric dm,
                   KernelFunction kf)
        Creates a new LWL classifier
        Parameters:
        classifier - the local classifier to
        k - the number of neighbors to create a local classifier from
        dm - the metric to use when selecting the nearest points to a query
        kf - the kernel function used to weight the local points
      • LWL

        public LWL(Classifier classifier,
                   int k,
                   DistanceMetric dm,
                   KernelFunction kf,
                   VectorCollection<VecPaired<Vec,java.lang.Double>> vcf)
        Creates a new LWL classifier
        Parameters:
        classifier - the local classifier to
        k - the number of neighbors to create a local classifier from
        dm - the metric to use when selecting the nearest points to a query
        kf - the kernel function used to weight the local points
        vcf - the factory to create vector collections for storing the points
      • LWL

        public LWL(Regressor regressor,
                   int k,
                   DistanceMetric dm)
        Creates a new LWL Regressor
        Parameters:
        regressor - the local regressor
        k - the number of neighbors to create a local classifier from
        dm - the metric to use when selecting the nearest points to a query
      • LWL

        public LWL(Regressor regressor,
                   int k,
                   DistanceMetric dm,
                   KernelFunction kf)
        Creates a new LWL Regressor
        Parameters:
        regressor - the local regressor
        k - the number of neighbors to create a local classifier from
        dm - the metric to use when selecting the nearest points to a query
        kf - the kernel function used to weight the local points
      • LWL

        public LWL(Regressor regressor,
                   int k,
                   DistanceMetric dm,
                   KernelFunction kf,
                   VectorCollection<VecPaired<Vec,java.lang.Double>> vcf)
        Creates a new LWL Regressor
        Parameters:
        regressor - the local regressor
        k - the number of neighbors to create a local classifier from
        dm - the metric to use when selecting the nearest points to a query
        kf - the kernel function used to weight the local points
        vcf - the factory to create vector collections for storing the points
    • Method Detail

      • classify

        public CategoricalResults classify(DataPoint data)
        Description copied from interface: Classifier
        Performs classification on the given data point.
        Specified by:
        classify in interface Classifier
        Parameters:
        data - the data point to classify
        Returns:
        the results of the classification.
      • train

        public void train(ClassificationDataSet dataSet,
                          boolean parallel)
        Description copied from interface: Classifier
        Trains the classifier and constructs a model for classification using the given data set. If the training method knows how, it will used the threadPool to conduct training in parallel. This method will block until the training has completed.
        Specified by:
        train in interface Classifier
        Parameters:
        dataSet - the data set to train on
        parallel - true if multiple threads should be used to train the model. false if it should be done in a single threaded manner.
      • supportsWeightedData

        public boolean supportsWeightedData()
        Description copied from interface: Classifier
        Indicates whether the model knows how to train using weighted data points. If it does, the model will train assuming the weights. The values returned by this method may change depending on the parameters set for the model.
        Specified by:
        supportsWeightedData in interface Classifier
        Specified by:
        supportsWeightedData in interface Regressor
        Returns:
        true if the model supports weighted data, false otherwise
      • clone

        public LWL clone()
        Specified by:
        clone in interface Classifier
        Specified by:
        clone in interface Regressor
        Overrides:
        clone in class java.lang.Object
      • setNeighbors

        public void setNeighbors(int k)
        Sets the number of neighbors that will be used to create the local model
        Parameters:
        k - the number of neighbors to obtain
      • getNeighbors

        public int getNeighbors()
        Returns the number of neighbors that will be used to create each local model
        Returns:
        the number of neighbors that will be used
      • setDistanceMetric

        public void setDistanceMetric(DistanceMetric dm)
        Sets the distance metric that will be used for the nearest neighbor search
        Parameters:
        dm - the distance metric to use for nearest neighbor search
      • getDistanceMetric

        public DistanceMetric getDistanceMetric()
        Returns the distance metric in use
        Returns:
        the distance metric in use
      • setKernelFunction

        public void setKernelFunction(KernelFunction kf)
        Sets the kernel function that will be used to set the weights of each data point in the local set
        Parameters:
        kf - the kernel function to use for weighting
      • getKernelFunction

        public KernelFunction getKernelFunction()
        Returns the kernel function that will be used to set the weights.
        Returns:
        the kernel function that will be used to set the weights
      • guessNeighbors

        public static Distribution guessNeighbors(DataSet d)
        Guesses the distribution to use for the number of neighbors to consider
        Parameters:
        d - the dataset to get the guess for
        Returns:
        the guess for the Neighbors parameter

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.