We are using Java-ML(LibSVM) in order to execute the SVM algorithm over a multi-class problem
Classifier clas = new LibSVM();
clas.buildClassifier(data);
Dataset dataForClassification= FileHandler.loadDataset(new File(.), 0, ",");
/* Counters for correct and wrong predictions. */
int correct = 0, wrong = 0;
/* Classify all instances and check with the correct class values */
for (Instance inst : dataForClassification) {
Object predictedClassValue开发者_JAVA百科 = clas.classify(inst);
Map<Object,Double> map = clas.classDistribution(inst);
Object realClassValue = inst.classValue();
if (predictedClassValue.equals(realClassValue))
correct++;
else
wrong++;
}
the classDistributtion()
returns a standard vector ( meaning all values are 0 but one value which equals to 1)
java-ml - http://java-ml.sourceforge.net/
Despite the other answers, it is possible to output probability estimates for SVMs and LibSVM does do this. However, I'm fairly sure you can't use this feature from Java-ML. The file LibSVM.java
only ever refers to the function svm_predict_values
and never svm_predict_probabilities
. It probably wouldn't be too hard to add this functionality in to Java-ML if you felt you really needed it.
AFAIK, LibSVM is a deterministic classifier, meaning that the only distributions you will see are concentrated on a single class i.e. a standard vector. This is different than a probabilistic classifier such as Naive Bayes, which may give values different than 0.0 and 1.0.
精彩评论