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:

  1. Get a train data set X with its label vector l
  2. Parameters selection
    1. Randomly pick some observations from X and their corresponding labels l, and let's call the data set X_param
    2. Make Ncv_param-fold cross validation to select the parameters c and gamma from X_param
    3. At the end you get bestc and bestg for c and gamma respectively
  3. Train the svm model modelSVM using the best parameters bestc and bestg
    1. modelSVM = svmtrain(l, X, bestc, bestg)
  4. Get a test data set X_test with its label vector l_test
  5. Classification the test set
    1. accuracy = svmclassify(l_test, X_test, modelSVM)

matlab code: demo_libsvm_test10.