The accepted answer worked like a charm. Be sure to set probability = 1 during your workout.
If you are trying to drop the prediction when confidence does not fit the threshold, here is a sample code:
double confidenceScores[] = new double[model.nr_class]; svm.svm_predict_probability(model, svmVector, confidenceScores); /*System.out.println("text="+ text); for (int i = 0; i < model.nr_class; i++) { System.out.println("i=" + i + ", labelNum:" + model.label[i] + ", name=" + classLoadMap.get(model.label[i]) + ", score="+confidenceScores[i]); }*/ //finding max confidence; int maxConfidenceIndex = 0; double maxConfidence = confidenceScores[maxConfidenceIndex]; for (int i = 1; i < confidenceScores.length; i++) { if(confidenceScores[i] > maxConfidence){ maxConfidenceIndex = i; maxConfidence = confidenceScores[i]; } } double threshold = 0.3; // set this based data & no. of classes int labelNum = model.label[maxConfidenceIndex]; // reverse map number to name String targetClassLabel = classLoadMap.get(labelNum); LOG.info("classNumber:{}, className:{}; confidence:{}; for text:{}", labelNum, targetClassLabel, (maxConfidence), text); if (maxConfidence < threshold ) { LOG.info("Not enough confidence; threshold={}", threshold); targetClassLabel = null; } return targetClassLabel;
source share