public class NearestNeighbour extends Object implements Classifier, Regressor, Parameterized
Constructor and Description |
---|
NearestNeighbour(int k)
Constructs a new Nearest Neighbor Classifier
|
NearestNeighbour(int k,
boolean weighted)
Constructs a new Nearest Neighbor Classifier
|
NearestNeighbour(int k,
boolean weighted,
DistanceMetric distanceMetric)
Constructs a new Nearest Neighbor Classifier
|
NearestNeighbour(int k,
boolean weighted,
DistanceMetric distanceMetric,
VectorCollectionFactory<VecPaired<Vec,Double>> vcf)
Constructs a new Nearest Neighbor Classifier
|
NearestNeighbour(int k,
VectorCollectionFactory<VecPaired<Vec,Double>> vcf)
Constructs a new Nearest Neighbor Classifier
|
Modifier and Type | Method and Description |
---|---|
CategoricalResults |
classify(DataPoint data)
Performs classification on the given data point.
|
NearestNeighbour |
clone() |
DistanceMetric |
getDistanceMetric() |
int |
getNeighbors()
Returns the number of neighbors currently consulted to make decisions
|
int |
getNeighbors(int k) |
Parameter |
getParameter(String paramName)
Returns the parameter with the given name.
|
List<Parameter> |
getParameters()
Returns the list of parameters that can be altered for this learner.
|
static Distribution |
guessNeighbors(DataSet d)
Guesses the distribution to use for the number of neighbors to consider
|
double |
regress(DataPoint data) |
void |
setDistanceMetric(DistanceMetric distanceMetric) |
void |
setNeighbors(int k)
Sets the number of neighbors to consult when making decisions
|
boolean |
supportsWeightedData()
Indicates whether the model knows how to train using weighted data points.
|
void |
train(RegressionDataSet dataSet) |
void |
train(RegressionDataSet dataSet,
ExecutorService threadPool) |
void |
trainC(ClassificationDataSet dataSet)
Trains the classifier and constructs a model for classification using the
given data set.
|
void |
trainC(ClassificationDataSet dataSet,
ExecutorService threadPool)
Trains the classifier and constructs a model for classification using the
given data set.
|
public NearestNeighbour(int k)
k
- the number of neighbors to usepublic NearestNeighbour(int k, VectorCollectionFactory<VecPaired<Vec,Double>> vcf)
k
- the number of neighbors to usevcf
- the vector collection factory to use for storing and queryingpublic NearestNeighbour(int k, boolean weighted)
k
- the number of neighbors to useweighted
- whether or not to weight the influence of neighbors by their distancepublic NearestNeighbour(int k, boolean weighted, DistanceMetric distanceMetric)
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.public NearestNeighbour(int k, boolean weighted, DistanceMetric distanceMetric, VectorCollectionFactory<VecPaired<Vec,Double>> vcf)
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 queryingpublic int getNeighbors()
public void setNeighbors(int k)
k
- the number of neighbors to usepublic int getNeighbors(int k)
public DistanceMetric getDistanceMetric()
public void setDistanceMetric(DistanceMetric distanceMetric)
public List<Parameter> getParameters()
Parameterized
getParameters
in interface Parameterized
public Parameter getParameter(String paramName)
Parameterized
getParameter
in interface Parameterized
paramName
- the name of the parameter to obtainpublic CategoricalResults classify(DataPoint data)
Classifier
classify
in interface Classifier
data
- the data point to classifypublic void trainC(ClassificationDataSet dataSet)
Classifier
trainC
in interface Classifier
dataSet
- the data set to train onpublic void trainC(ClassificationDataSet dataSet, ExecutorService threadPool)
Classifier
trainC
in interface Classifier
dataSet
- the data set to train onthreadPool
- the source of threads to use.public void train(RegressionDataSet dataSet)
public void train(RegressionDataSet dataSet, ExecutorService threadPool)
public NearestNeighbour clone()
public static Distribution guessNeighbors(DataSet d)
d
- the dataset to get the guess forpublic boolean supportsWeightedData()
Classifier
supportsWeightedData
in interface Classifier
supportsWeightedData
in interface Regressor
Copyright © 2017. All rights reserved.