Catalano.MachineLearning.Classification
Class KNearestNeighbors
- java.lang.Object
-
- Catalano.MachineLearning.Classification.KNearestNeighbors
-
- All Implemented Interfaces:
- IClassifier, java.io.Serializable, java.lang.Cloneable
public class KNearestNeighbors extends java.lang.Object implements IClassifier, java.io.Serializable
K Nearest Neighbour classifier.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description KNearestNeighbors()Initializes a new instance of the KNearestNeighbors class.KNearestNeighbors(int k)Initializes a new instance of the KNearestNeighbors class.KNearestNeighbors(int k, IDivergence divergence)Initializes a new instance of the KNearestNeighbors class.KNearestNeighbors(int k, IMercerKernel kernel)Initializes a new instance of the KNearestNeighbors class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description IClassifierclone()Clone of the object.IDivergencegetDistance()Get the divergence function.intgetK()Get number of neighbours.IMercerKernelgetKernel()Get the kernel metric.voidLearn(DatasetClassification dataset)Learn from a dataset.voidLearn(double[][] input, int[] output)Learn.intPredict(double[] feature)Compute.voidsetDistance(IDivergence divergence)Set the divergence function.voidsetK(int k)Set number of neighbours.voidsetMercerKernel(IMercerKernel kernel)Set the kernel metric.
-
-
-
Constructor Detail
-
KNearestNeighbors
public KNearestNeighbors()
Initializes a new instance of the KNearestNeighbors class.
-
KNearestNeighbors
public KNearestNeighbors(int k)
Initializes a new instance of the KNearestNeighbors class.- Parameters:
k- Number of neighbors.
-
KNearestNeighbors
public KNearestNeighbors(int k, IDivergence divergence)Initializes a new instance of the KNearestNeighbors class.- Parameters:
k- Number of neighbors.divergence- Distance.
-
KNearestNeighbors
public KNearestNeighbors(int k, IMercerKernel kernel)Initializes a new instance of the KNearestNeighbors class.- Parameters:
k- Number of neighbors.kernel- Kernel.
-
-
Method Detail
-
getK
public int getK()
Get number of neighbours.- Returns:
- Number of neighbours.
-
setK
public void setK(int k)
Set number of neighbours.- Parameters:
k- Number of neighbours.
-
getKernel
public IMercerKernel getKernel()
Get the kernel metric.- Returns:
- Kernel.
-
setMercerKernel
public void setMercerKernel(IMercerKernel kernel)
Set the kernel metric.- Parameters:
kernel- Kernel.
-
getDistance
public IDivergence getDistance()
Get the divergence function.- Returns:
- Divergence.
-
setDistance
public void setDistance(IDivergence divergence)
Set the divergence function.- Parameters:
divergence- Divergence.
-
Learn
public void Learn(DatasetClassification dataset)
Description copied from interface:IClassifierLearn from a dataset.- Specified by:
Learnin interfaceIClassifier- Parameters:
dataset- Dataset.
-
Learn
public void Learn(double[][] input, int[] output)Description copied from interface:IClassifierLearn.- Specified by:
Learnin interfaceIClassifier- Parameters:
input- Matrix of features.output- Labels.
-
Predict
public int Predict(double[] feature)
Compute.- Specified by:
Predictin interfaceIClassifier- Parameters:
feature- Feature to compute.- Returns:
- Object.
-
clone
public IClassifier clone()
Description copied from interface:IClassifierClone of the object.- Specified by:
clonein interfaceIClassifier- Overrides:
clonein classjava.lang.Object- Returns:
- A new copy of the object.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG