in the class LibSVMModel, the methods for returning the number of support vectors and computing the weight vector are wrong.
getNumberOfSupportVectors should use the correct field computed by libSVM, as the current implementation will return the number of classes-1 not the number of support vectors.
public int getNumberOfSupportVectors() {
//return model.SV.length;
return model.l;
}
Furthermore, the weight vector w as computed by the implementation of createWeightsTable() in KernelModel is wrong. For LibSVM, the weight w[i] = m.getAlpha(i) * x[j]. Do not multiply with y here. Also I'm not sure if the implementation in KernelModel is correct, as y is either 0 or 1, however in SVM Literature it is -1 or 1. I suspect that replacing y with (y == 0 ? -1 : 1) is correct.
Hi there,
in the class LibSVMModel, the methods for returning the number of support vectors and computing the weight vector are wrong. getNumberOfSupportVectors should use the correct field computed by libSVM, as the current implementation will return the number of classes-1 not the number of support vectors.
Furthermore, the weight vector w as computed by the implementation of createWeightsTable() in KernelModel is wrong. For LibSVM, the weight
w[i] = m.getAlpha(i) * x[j]
. Do not multiply with y here. Also I'm not sure if the implementation in KernelModel is correct, as y is either 0 or 1, however in SVM Literature it is -1 or 1. I suspect that replacing y with (y == 0 ? -1 : 1) is correct.Best wishes
Lukas