Complete example on classification in most general scenario
This code does the following:
- Automatic parameters selection for for c and gamma
- Train the svm model using train set
- Classify the test data set based on the trained svm model
- Make confusion matrix
- Dimensionality reduction of the data using MDS
- Plot the classification results in 2D dimension
More details about the procedures:
Get a train data set X with its label vector l
Parameters selection
Randomly pick some observations from X and their corresponding labels l, and let's call the data set X_param
Make Ncv_param-fold cross validation to select the parameters c and gamma from X_param
At the end you get bestc and bestg for c and gamma respectively
Train the svm model modelSVM using the best parameters bestc and bestg
modelSVM = svmtrain(l, X, bestc, bestg)
Get a test data set X_test with its label vector l_test
Classification the test set
accuracy = svmclassify(l_test, X_test, modelSVM)
matlab code: demo_libsvm_test10.