@Test public void testSetNumFeatures() { if (!knnClassifier.train(data)) fail("Train failed"); assertEquals("KnnClassifier.setNumFeatures fails for valid args", knnClassifier.setNumFeatures(3), true); try { knnClassifier.setNumFeatures(2); fail("KnnClassifier.setNumFeatures fails for invalid args"); } catch (Exception e) { } }
public boolean setNumFeatures(int numFeatures) throws IllegalArgumentException { if (model.data.size() > 0) if (model.data.get(0).size() <= numFeatures) throw new IllegalArgumentException("restriction: " + "numFeatures > 0 and existing dataset should " + " contain <= numFeatures features"); model.numFeatures = numFeatures; return true; }
KNNClassifier extends Classifier { public boolean setNumFeatures(int numFeatures) throws IllegalArgumentException { if (model.data.size() > 0) if (model.data.get(0).size() <= numFeatures) throw new IllegalArgumentException("restriction: " + "numFeatures > 0 and existing dataset should " + " contain <= numFeatures features"); model.numFeatures = numFeatures; return true; } }
KNNClassifier extends Classifier { public boolean setNumFeatures(int numFeatures) throws IllegalArgumentException { if (model.data.size() > 0) if (model.data.get(0).size() <= numFeatures) throw new IllegalArgumentException("restriction: " + "numFeatures > 0 and existing dataset should " + " contain <= numFeatures features"); model.numFeatures = numFeatures; return true; } KNNClassifier(int k, int numFeatures);  KNNClassifier(Object objModel); }
KNNClassifier extends Classifier { public boolean setNumFeatures(int numFeatures) throws IllegalArgumentException { if (model.data.size() > 0) if (model.data.get(0).size() <= numFeatures) throw new IllegalArgumentException("restriction: " + "numFeatures > 0 and existing dataset should " + " contain <= numFeatures features"); model.numFeatures = numFeatures; return true; } KNNClassifier(int k, int numFeatures);  KNNClassifier(Object objModel); @Override boolean train(List<FeatureVector> data); @Override int classify(FeatureVector featureVector); @Override Object getModel(); ArrayList<ComputedDistance> sortDistances(List<ComputedDistance> 
	computedDistance); int getMajorityLabel(List<ComputedDistance> sortedDistance ); int getK(); void setK(int k); int getNumFeatures(); boolean setNumFeatures(int numFeatures); }
KNNClassifier extends Classifier { public boolean setNumFeatures(int numFeatures) throws IllegalArgumentException { if (model.data.size() > 0) if (model.data.get(0).size() <= numFeatures) throw new IllegalArgumentException("restriction: " + "numFeatures > 0 and existing dataset should " + " contain <= numFeatures features"); model.numFeatures = numFeatures; return true; } KNNClassifier(int k, int numFeatures);  KNNClassifier(Object objModel); @Override boolean train(List<FeatureVector> data); @Override int classify(FeatureVector featureVector); @Override Object getModel(); ArrayList<ComputedDistance> sortDistances(List<ComputedDistance> 
	computedDistance); int getMajorityLabel(List<ComputedDistance> sortedDistance ); int getK(); void setK(int k); int getNumFeatures(); boolean setNumFeatures(int numFeatures); public KNNModel model; }