jsat.classifiers.knn
Class NearestNeighbour
- java.lang.Object
-
- jsat.classifiers.knn.NearestNeighbour
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Classifier, Parameterized, Regressor
public class NearestNeighbour extends java.lang.Object implements Classifier, Regressor, Parameterized
An implementation of the Nearest Neighbor algorithm, but with a British spelling! How fancy.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description NearestNeighbour(int k)Constructs a new Nearest Neighbor ClassifierNearestNeighbour(int k, boolean weighted)Constructs a new Nearest Neighbor ClassifierNearestNeighbour(int k, boolean weighted, DistanceMetric distanceMetric)Constructs a new Nearest Neighbor ClassifierNearestNeighbour(int k, boolean weighted, DistanceMetric distanceMetric, VectorCollection<VecPaired<Vec,java.lang.Double>> vcf)Constructs a new Nearest Neighbor ClassifierNearestNeighbour(int k, VectorCollection<VecPaired<Vec,java.lang.Double>> vcf)Constructs a new Nearest Neighbor Classifier
-
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.NearestNeighbourclone()DistanceMetricgetDistanceMetric()intgetNeighbors()Returns the number of neighbors currently consulted to make decisionsintgetNeighbors(int k)static DistributionguessNeighbors(DataSet d)Guesses the distribution to use for the number of neighbors to considerdoubleregress(DataPoint data)voidsetDistanceMetric(DistanceMetric distanceMetric)voidsetNeighbors(int k)Sets the number of neighbors to consult when making decisionsbooleansupportsWeightedData()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
-
NearestNeighbour
public NearestNeighbour(int k)
Constructs a new Nearest Neighbor Classifier- Parameters:
k- the number of neighbors to use
-
NearestNeighbour
public NearestNeighbour(int k, VectorCollection<VecPaired<Vec,java.lang.Double>> vcf)Constructs a new Nearest Neighbor Classifier- Parameters:
k- the number of neighbors to usevcf- the vector collection factory to use for storing and querying
-
NearestNeighbour
public NearestNeighbour(int k, boolean weighted)Constructs a new Nearest Neighbor Classifier- Parameters:
k- the number of neighbors to useweighted- whether or not to weight the influence of neighbors by their distance
-
NearestNeighbour
public NearestNeighbour(int k, boolean weighted, DistanceMetric distanceMetric)Constructs a new Nearest Neighbor Classifier- Parameters:
k- the number of neighbors to useweighted- whether or not to weight the influence of neighbors by their distancedistanceMetric- the method of computing distance between two vectors.
-
NearestNeighbour
public NearestNeighbour(int k, boolean weighted, DistanceMetric distanceMetric, VectorCollection<VecPaired<Vec,java.lang.Double>> vcf)Constructs a new Nearest Neighbor Classifier- Parameters:
k- the number of neighbors to useweighted- whether or not to weight the influence of neighbors by their distancedistanceMetric- the method of computing distance between two vectors.vcf- the vector collection factory to use for storing and querying
-
-
Method Detail
-
getNeighbors
public int getNeighbors()
Returns the number of neighbors currently consulted to make decisions- Returns:
- the number of neighbors
-
setNeighbors
public void setNeighbors(int k)
Sets the number of neighbors to consult when making decisions- Parameters:
k- the number of neighbors to use
-
getNeighbors
public int getNeighbors(int k)
-
getDistanceMetric
public DistanceMetric getDistanceMetric()
-
setDistanceMetric
public void setDistanceMetric(DistanceMetric distanceMetric)
-
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.
-
train
public void train(RegressionDataSet dataSet, boolean parallel)
-
clone
public NearestNeighbour clone()
- Specified by:
clonein interfaceClassifier- Specified by:
clonein interfaceRegressor- Overrides:
clonein classjava.lang.Object
-
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
-
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
-
-
DataMelt 3.0 © DataMelt by jWork.ORG