MCPcopy Create free account
hub / github.com/EdwardRaff/JSAT / NearestNeighbour

Class NearestNeighbour

JSAT/src/jsat/classifiers/knn/NearestNeighbour.java:27–334  ·  view source on GitHub ↗

An implementation of the Nearest Neighbor algorithm, but with a British spelling! How fancy. @author Edward Raff

Source from the content-addressed store, hash-verified

25 * @author Edward Raff
26 */
27public class NearestNeighbour implements Classifier, Regressor, Parameterized
28{
29
30 private static final long serialVersionUID = 4239569189624285932L;
31 private int k;
32 private boolean weighted;
33 private DistanceMetric distanceMetric;
34 private CategoricalData predicting;
35
36 private VectorCollectionFactory<VecPaired<Vec, Double>> vcf;
37 private VectorCollection<VecPaired<Vec, Double>> vecCollection;
38
39 /**
40 * Returns the number of neighbors currently consulted to make decisions
41 * @return the number of neighbors
42 */
43 public int getNeighbors()
44 {
45 return k;
46 }
47
48 /**
49 * Sets the number of neighbors to consult when making decisions
50 * @param k the number of neighbors to use
51 */
52 public void setNeighbors(int k)
53 {
54 if(k < 1)
55 throw new ArithmeticException("Must be a positive number of neighbors");
56 this.k = k;
57 }
58
59 public int getNeighbors(int k)
60 {
61 return k;
62 }
63
64 public DistanceMetric getDistanceMetric()
65 {
66 return distanceMetric;
67 }
68
69 public void setDistanceMetric(DistanceMetric distanceMetric)
70 {
71 if(distanceMetric == null)
72 throw new NullPointerException("given metric was null");
73 this.distanceMetric = distanceMetric;
74 }
75
76
77
78 @Override
79 public List<Parameter> getParameters()
80 {
81 return Parameter.getParamsFromMethods(this);
82 }
83
84 @Override

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected