c - Classification using LibSVM -
i using libsvm carry out multi-class classifications. trained model using matlab interface of libsvm. saved model in format recognized in c. want classify using svm_predict in c. having trouble being able reproduce results saw in matlab. in fact same class output irrespective of test vector feed in (even vector of zeros) think issue way loading test vector x svm_node structure. below code snippet. let me know if correct way or if missing something.
struct svm_model *libsvm_model = svm_load_model('mymodel.svm'); struct svm_node x[2001]; // 1 feature vector of size 2000x1 int index = 1; int = 0; (i = 0; < features.size(); i++) { x[i].index = index; x[i].value = features.at(i); index = index + 1; } x[i+1].index = -1; x[i+1].value = '?'; double result = svm_predict(libsvm_model, x);
this seems problem:
x[i+1].index = -1; x[i+1].value = '?';
libsvm
requires svm_node
input vector, should have positive indexes, , double values. should not "leave" weird empty dimension.
and way, don't need index
variable
for (i = 0; < features.size(); i++) { x[i].index = index; x[i].value = features.at(i); index = index + 1; }
is equivalent to
for (i = 0; < features.size(); i++) { x[i].index = + 1; x[i].value = features.at(i); }
Comments
Post a Comment