Search code examples
matlabmachine-learninglibsvmpattern-recognition

svmtrain returns a single floating value instead of a structure after training


I am using LIBSVM SVR for prediction in MATLAB. The output of svmtrain is supposed to be a model which is in this case should be a structure. But sometimes it returns just a single value. Can someone tell me what that mean. Below is one such data for which it returned me a single output value (7.586428304542136e-05)

Input X training instance matrix is
[0.416804048175116;0.725969684480469;0.727160324220360;0.566114850941063;0.718127490039841;0.646792141777717;0.642830974950772;0.748591839538398;0.639923066355269;0.368491551037230] and 
corresponding output Y training instance matrix is
[0.034441805225653;0.030878859857482;0.032066508313539;0.030878859857482;0.030878859857482;0.030878859857482;0.034441805225653;0.023752969121140;0.032066508313539;0.054631828978622]
SVM code:
model = svmtrain(Y,X,['-s 3 -t 2 -c 1 -p 0.001 -g 1 -v 5']);

The values of c and g are varied from 2.^[-6:6].


Solution

  • From the libsvm/matlab README:

    If the '-v' option is specified, cross validation is conducted and the returned model is just a scalar: cross-validation accuracy for classification and mean-squared error for regression.

    This is the only case that I know of in which libsvm should return a scalar from training.

    From your post:

    model = svmtrain(Y,X,['-s 3 -t 2 -c 1 -p 0.001 -g 1 -v 5']);
    

    That -v 5 on the end causes it to do cross-validation, and then model is a scalar (mse) as noted in the README above.