svmclassify - not enough input arguments

1 view (last 30 days)
ramin
ramin on 7 Jul 2014
Dear All I am trying to train and classify svm algorithm using k=10 fold cross-validation. I have input matrices for train and test data which are provided globally. I build the model suing svmtrain. But when I want to test it using svmclassify function, it return an error "not enough input arguments".
The question is although I have called the svmcalssify function at it mentioned in the documents of the matlab what causes this error ?
the dataset ordered in way that each row of the train_data matrix contains one sample, and columns are variables.
I would really appreciate your help on this issue.
Thanks in advance
Ramin
function test_result = train_svm_classifier()
global train_data ;%= 300*312[] ;
global train_labels; % =300*1 [];
global test_data;% = 194*312[];
global test_labels;% = 194*1*[];
global SVMmodel;
groups = train_labels;
k=10;
cvFolds = crossvalind('Kfold', groups, k); %# get indices of 10-fold CV
cp = classperf(groups); %# init performance tracker
for i = 1:k %# for each fold
testIdx = (cvFolds == i); %# get indices of test instances
trainIdx = ~testIdx; %# get indices training instances
SVMmodelCross = svmtrain(train_data(trainIdx,:),...
train_labels(trainIdx),'autoscale',false,'kernel_function'...
,'rbf','RBF_Sigma',1e-3,'BoxConstraint',1e3);
pred = svmclassify(SVMmodelCross,train_data(testIdx,1),'Showplot',false);<--- here is the error
cp = classperf(cp, pred, testIdx);
end
cp.CorrectRate
cp.CountingMatrix
SVMmodel = svmtrain(train_data,train_labels,...
'autoscale',false,'kernel_function'...
,'rbf','RBF_Sigma',1/size(train_data,2),'ShowPlot', false);
test_pred = svmclassify(SVMmodel, test_data, 'ShowPlot', false);
test_cp = classperf(test_labels);
test_cp = classperf(test_cp, test_pred);
test_cp.CorrectRate
test_cp.CountingMatrix
test_result = test_cp;
end

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!