An implementation of the Nearest Neighbor algorithm, but with a British spelling! How fancy. @author Edward Raff
| 25 | * @author Edward Raff |
| 26 | */ |
| 27 | public 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 |
nothing calls this directly
no outgoing calls
no test coverage detected