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.

有帮助吗?

解决方案 2

@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');

其他提示

Use [predict_label, accuracy, prob_values] = svmpredict(testLabel, testData, model, '-b 1'); to observe the accuracy.

testLabel is the vector that includes the 'correct' labels of your test data. This parameter is given in order to calculate the accuracy. In the real case that labels of test data are unknown, simply use any random values to get the predict_label without calculating the accuracy.

Besides, although not required, you'd better specify the options in svmtrain, check their page for more details.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top