Search code examples
matlablabelsvmpcalibsvm

Why is the predicted_label +1 even though it should be -1? Using LIBSVM in MATLAB


I extracted the principal components of training and testing data.
'trainingdata.train' has feature values from both +1(face 1) and -1(all other faces) labels. 'testdata.train' has feature values from face 2 and no label since i want the SVM to predict its label. The "predicted_label" given by LIBSVM is +1 even though it should be -1.

[training_label_matrix, training_instance_matrix] = libsvmread('trainingdata.train');
[testing_label_matrix, testing_instance_matrix] = libsvmread('testdata.train');
model = svmtrain(training_label_matrix, training_instance_matrix);
[predicted_label] = svmpredict(testing_label_matrix, testing_instance_matrix, model);

Please point me out to what i am doing wrong.


Solution

  • @Lennon : So should the code go like this?

    [training_label_matrix, training_instance_matrix] = libsvmread('trainingdata.train');
    [testing_label_matrix, testing_instance_matrix] = libsvmread('testdata.train');
    model = svmtrain(training_label_matrix, training_instance_matrix);
    [predict_label, accuracy, prob_values] = svmpredict(ones(size(testData,1),1), testing_instance_matrix, model, '-b 1');