jsat.classifiers.knn
Class LWL
- java.lang.Object
-
- jsat.classifiers.knn.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 asNaiveBayesandLinearRegression.
If the learning algorithm used does not support weighted data points, it will be as if theuniform kernel fucntionwas 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 Summary
Constructors Constructor and Description LWL(Classifier classifier, int k, DistanceMetric dm)Creates a new LWL classifierLWL(Classifier classifier, int k, DistanceMetric dm, KernelFunction kf)Creates a new LWL classifierLWL(Classifier classifier, int k, DistanceMetric dm, KernelFunction kf, VectorCollection<VecPaired<Vec,java.lang.Double>> vcf)Creates a new LWL classifierLWL(Regressor regressor, int k, DistanceMetric dm)Creates a new LWL RegressorLWL(Regressor regressor, int k, DistanceMetric dm, KernelFunction kf)Creates a new LWL RegressorLWL(Regressor regressor, int k, DistanceMetric dm, KernelFunction kf, VectorCollection<VecPaired<Vec,java.lang.Double>> vcf)Creates a new LWL Regressor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description CategoricalResultsclassify(DataPoint data)Performs classification on the given data point.LWLclone()DistanceMetricgetDistanceMetric()Returns the distance metric in useKernelFunctiongetKernelFunction()Returns the kernel function that will be used to set the weights.intgetNeighbors()Returns the number of neighbors that will be used to create each local modelstatic DistributionguessNeighbors(DataSet d)Guesses the distribution to use for the number of neighbors to considerdoubleregress(DataPoint data)voidsetDistanceMetric(DistanceMetric dm)Sets the distance metric that will be used for the nearest neighbor searchvoidsetKernelFunction(KernelFunction kf)Sets the kernel function that will be used to set the weights of each data point in the local setvoidsetNeighbors(int k)Sets the number of neighbors that will be used to create the local modelbooleansupportsWeightedData()Indicates whether the model knows how to train using weighted data points.voidtrain(ClassificationDataSet dataSet, boolean parallel)Trains the classifier and constructs a model for classification using the given data set.voidtrain(RegressionDataSet dataSet, boolean parallel)-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.classifiers.Classifier
train
-
Methods inherited from interface jsat.parameters.Parameterized
getParameter, getParameters
-
-
-
-
Constructor Detail
-
LWL
public LWL(Classifier classifier, int k, DistanceMetric dm)
Creates a new LWL classifier- Parameters:
classifier- the local classifier tok- the number of neighbors to create a local classifier fromdm- 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 tok- the number of neighbors to create a local classifier fromdm- the metric to use when selecting the nearest points to a querykf- 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 tok- the number of neighbors to create a local classifier fromdm- the metric to use when selecting the nearest points to a querykf- the kernel function used to weight the local pointsvcf- 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 regressork- the number of neighbors to create a local classifier fromdm- 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 regressork- the number of neighbors to create a local classifier fromdm- the metric to use when selecting the nearest points to a querykf- 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 regressork- the number of neighbors to create a local classifier fromdm- the metric to use when selecting the nearest points to a querykf- the kernel function used to weight the local pointsvcf- the factory to create vector collections for storing the points
-
-
Method Detail
-
classify
public CategoricalResults classify(DataPoint data)
Description copied from interface:ClassifierPerforms classification on the given data point.- Specified by:
classifyin interfaceClassifier- 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:ClassifierTrains 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:
trainin interfaceClassifier- Parameters:
dataSet- the data set to train onparallel-trueif multiple threads should be used to train the model.falseif it should be done in a single threaded manner.
-
supportsWeightedData
public boolean supportsWeightedData()
Description copied from interface:ClassifierIndicates 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:
supportsWeightedDatain interfaceClassifier- Specified by:
supportsWeightedDatain interfaceRegressor- Returns:
- true if the model supports weighted data, false otherwise
-
train
public void train(RegressionDataSet dataSet, boolean parallel)
-
clone
public LWL clone()
- Specified by:
clonein interfaceClassifier- Specified by:
clonein interfaceRegressor- Overrides:
clonein classjava.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