@Test public void testTrain() { try { svmClassifier.train(null); fail("SVM Train with null data fail"); } catch (Exception e) { } assertEquals("SVM Train with valid data fail", svmClassifier.train(data), true); }
@Override public boolean train(List<FeatureVector> data) throws IllegalArgumentException{ if (data == null || data.size() < 1) throw new IllegalArgumentException("Invalid data"); svm_problem problem = new svm_problem(); problem.l = data.size(); problem.y = new double[data.size()]; problem.x = new svm_node[data.size()][]; for (int i = 0; i < data.size(); i++){ problem.x[i] = new svm_node[this.numFeatures]; for (int j = 0; j < this.numFeatures; j++){ svm_node node = new svm_node(); node.index = j; node.value = data.get(i).get(j, 0); problem.x[i][j] = node; } problem.y[i] = (double) data.get(i).getIntClassLabel(); } this.model = svm.svm_train(problem, this.parameter); if (this.model == null) throw new IllegalArgumentException("Malformed data. " + "Failed to train"); setState(ClassifierState.TRAINED); return true; }
SVMClassifier extends Classifier { @Override public boolean train(List<FeatureVector> data) throws IllegalArgumentException{ if (data == null || data.size() < 1) throw new IllegalArgumentException("Invalid data"); svm_problem problem = new svm_problem(); problem.l = data.size(); problem.y = new double[data.size()]; problem.x = new svm_node[data.size()][]; for (int i = 0; i < data.size(); i++){ problem.x[i] = new svm_node[this.numFeatures]; for (int j = 0; j < this.numFeatures; j++){ svm_node node = new svm_node(); node.index = j; node.value = data.get(i).get(j, 0); problem.x[i][j] = node; } problem.y[i] = (double) data.get(i).getIntClassLabel(); } this.model = svm.svm_train(problem, this.parameter); if (this.model == null) throw new IllegalArgumentException("Malformed data. " + "Failed to train"); setState(ClassifierState.TRAINED); return true; } }
SVMClassifier extends Classifier { @Override public boolean train(List<FeatureVector> data) throws IllegalArgumentException{ if (data == null || data.size() < 1) throw new IllegalArgumentException("Invalid data"); svm_problem problem = new svm_problem(); problem.l = data.size(); problem.y = new double[data.size()]; problem.x = new svm_node[data.size()][]; for (int i = 0; i < data.size(); i++){ problem.x[i] = new svm_node[this.numFeatures]; for (int j = 0; j < this.numFeatures; j++){ svm_node node = new svm_node(); node.index = j; node.value = data.get(i).get(j, 0); problem.x[i][j] = node; } problem.y[i] = (double) data.get(i).getIntClassLabel(); } this.model = svm.svm_train(problem, this.parameter); if (this.model == null) throw new IllegalArgumentException("Malformed data. " + "Failed to train"); setState(ClassifierState.TRAINED); return true; } SVMClassifier(int numFeatures); }
SVMClassifier extends Classifier { @Override public boolean train(List<FeatureVector> data) throws IllegalArgumentException{ if (data == null || data.size() < 1) throw new IllegalArgumentException("Invalid data"); svm_problem problem = new svm_problem(); problem.l = data.size(); problem.y = new double[data.size()]; problem.x = new svm_node[data.size()][]; for (int i = 0; i < data.size(); i++){ problem.x[i] = new svm_node[this.numFeatures]; for (int j = 0; j < this.numFeatures; j++){ svm_node node = new svm_node(); node.index = j; node.value = data.get(i).get(j, 0); problem.x[i][j] = node; } problem.y[i] = (double) data.get(i).getIntClassLabel(); } this.model = svm.svm_train(problem, this.parameter); if (this.model == null) throw new IllegalArgumentException("Malformed data. " + "Failed to train"); setState(ClassifierState.TRAINED); return true; } SVMClassifier(int numFeatures); void setSVMParameter(int probability, double gamma, 
			double nu, double C, int svmType, int kernelType,
			double cacheSize, double eps); @Override boolean train(List<FeatureVector> data); @Override int classify(FeatureVector fv); @Override Object getModel(); }
SVMClassifier extends Classifier { @Override public boolean train(List<FeatureVector> data) throws IllegalArgumentException{ if (data == null || data.size() < 1) throw new IllegalArgumentException("Invalid data"); svm_problem problem = new svm_problem(); problem.l = data.size(); problem.y = new double[data.size()]; problem.x = new svm_node[data.size()][]; for (int i = 0; i < data.size(); i++){ problem.x[i] = new svm_node[this.numFeatures]; for (int j = 0; j < this.numFeatures; j++){ svm_node node = new svm_node(); node.index = j; node.value = data.get(i).get(j, 0); problem.x[i][j] = node; } problem.y[i] = (double) data.get(i).getIntClassLabel(); } this.model = svm.svm_train(problem, this.parameter); if (this.model == null) throw new IllegalArgumentException("Malformed data. " + "Failed to train"); setState(ClassifierState.TRAINED); return true; } SVMClassifier(int numFeatures); void setSVMParameter(int probability, double gamma, 
			double nu, double C, int svmType, int kernelType,
			double cacheSize, double eps); @Override boolean train(List<FeatureVector> data); @Override int classify(FeatureVector fv); @Override Object getModel(); public svm_model model; final double threshold; }