/** * SVM trainer * * @param dataTrain * @param dataTest */ public static void trainModelLibSVM(Instances dataTrain, Instances dataTest) { try { LibSVM classifier = new LibSVM(); CVParameterSelection ps = new CVParameterSelection(); ps.setClassifier(classifier); ps.setNumFolds(5); // using 5-fold CV // ps.addCVParameter("C 0.1 0.5 5"); // build and output best options ps.buildClassifier(dataTrain); Evaluation eval = new Evaluation(dataTrain); eval.evaluateModel(ps, dataTest); System.out.println("Results of the set :::::::::::::::::::::: "); System.out.println( "Percentage of correctly classified instances : " + eval.pctCorrect() + "\n" + "Percentage of incorrectly classified instances : " + eval.pctIncorrect()); System.out.println("No of correct predictions : " + eval.correct()); System.out.println("TRUTHFUL"); System.out.println( "Precision : " + eval.precision(0) + "\n" + "Recall : " + eval.recall(0) + "\n" + "F measure/score : " + eval.fMeasure(0)); System.out.println("DECEPTIVE"); System.out.println( "Precision : " + eval.precision(0) + "\n" + "Recall : " + eval.recall(1) + "\n" + "F measure/score : " + eval.fMeasure(1)); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }