matlab libsvm:无法预测

时间:2014-11-10 21:25:56

标签: matlab libsvm

我在Matlab上使用libsvm。我想构建一个模型并使用该模型进行预测。  连接svmpredict([predict_label,accuracy_all,prob_values])的返回值为空。这是我的简单代码:

svm_model = svmtrain([train_label],[train],'-t 2, -c 100 -q');
[predict_label, accuracy_all, prob_values] = svmpredict(testlabels,testdata,svm_model,'-q, -b 1');

[predict_label,accuracy_all,prob_values]是0x0矩阵。而且Matlab还会显示一些警告信息:

Usage: [predicted_label, accuracy, decision_values/prob_estimates] = svmpredict(testing_label_vector, testing_instance_matrix, model, 'libsvm_options')
Parameters:
  model: SVM model structure from svmtrain.
  libsvm_options:
    -b probability_estimates: whether to predict probability estimates, 0 or 1 (default 0); one-class SVM not supported yet
Returns:
  predicted_label: SVM prediction output vector.
  accuracy: a vector with accuracy, mean squared error, squared correlation coefficient.
  prob_estimates: If selected, probability estimate vector.

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

SVM模型中的q是什么?它的价值在哪里?

SVM中有两个参数需要很好地定义c和g,你把100作为c的值但是q不是q的值(或者必须是g,称为gamma)

这就是你需要的

 cmd = ['-t 2 -c ',num2str(C), ' -g ',num2str(gamma) ];
model = svmtrain2(trainClass, trainData, cmd);
[predClass, acc, decVals] = svmpredict(testClass, testData, model);

另外我认为svmtrain必须重命名为svmtrain2,以避免与matlab的svmtrain函数混淆。