The IDLmlSupportVectorMachineClassification class implements an SVM model that can be used for classification purposes. The following steps are described here.

For a detailed example of how to use the IDL Machine Learning Framework to train a model that learns to recognize hand-written digits, compile and run classify_digits.pro, which is located in the examples/machine_learning directory of your IDL installation.

Example


; Read data
read_seeds_example_data, data, labels, $
  N_ATTRIBUTES=nAttributes, N_EXAMPLES=nExamples, $
  N_LABELS=nLabels, UNIQUE_LABELS=uniqueLabels
 
; Shuffle data
IDLmlShuffle, data, labels
 
; Normalize data
Normalizer = IDLmlVarianceNormalizer(data)
Normalizer.Normalize, data
 
; Partition data
Part = IDLmlPartition({train:80, test:20}, data, labels)
 
; Define the model
Classifier = IDLmlSupportVectorMachineClassification(nAttributes, uniqueLabels)
 
; This model does not need multiple training iterations, 
; we can call it just once.
Loss = Classifier.Train(part.train['data'], LABELS=part.train['labels'])
confMatrix= IDLmlTestClassifier(Classifier, part.test['data'], $
  part.test['labels'], ACCURACY=accuracy)
Print, 'Model accuracy:', accuracy
 
; Classify the first example
Print, Classifier.Classify(data[*,0])

Syntax


Result = IDLmlSupportVectorMachineClassification(Nattributes, Outputs [, Keywords=Value])

Arguments


Nattributes

Specify the number of attributes that the input data will be required to have.

Outputs

Specify the array of possible outputs. It can be an array of numbers or strings. Outputs can also be a scalar number; in that case, the possible output values will be all integer numbers from 0 to 'outputs' minus one.

Keywords


KERNEL (optional)

Set this keyword to a valid kernel object (IDLmlSVM*Kernel) that encapsulates several SVM parameters. Valid options include IDLmlSVMLinearKernel, IDLmlSVMPolynomialKernel, IDLmlSVMRadialKernel (default), and IDLmlSVMSigmoidKernel.

PENALTY (optional)

Set this keyword to a value indicating the penalty parameter. The default value is 100.0. The optimal value for any particular model is highly variable and will most likely need to be adjusted. You should perform a grid search for parameter selection as described in Hsu, Chang, and Lin (2010).

References

Chih-Chung Chang and Chih-Jen Lin, LIBSVM: a library for support vector machines. ACM Transactions on Intelligent Systems and Technology, 2:27:1--27:27, 2011. Software available at http://www.csie.ntu.edu.tw/~cjlin/libsvm.

Hsu, C.-W., C.-C. Chang, and C.-J. Lin. (2010). A practical guide to support vector classification. National Taiwan University. http://ntu.csie.org/~cjlin/papers/guide/guide.pdf.

Wu, T.-F., C.-J. Lin, and R. C. Weng. (2004). Probability estimates for multi-class classification by pairwise coupling. Journal of Machine Learning Research, 5:975-1005, http://www.csie.ntu.edu.tw/~cjlin/papers/svmprob/svmprob.pdf.

PROBABILITY (optional)

Set this keyword to train the model for probability estimates. The default is 1 for classification problems.

SHRINK (optional)

Set this keyword to ask the model to use the shrinking heuristics. The default is 1.

Properties


CLASS_MAP

A hash that maps internal classification values to desired labels, if the model was defined using custom labels.

KERNEL

The kernel object used to define the model.

NATTRIBUTES

The number of input attributes the model requires.

NOUTPUTS

The number of possible outputs.

OUTPUTS

An array of possible outputs.

PENALTY

The penalty parameter used in the model.

Methods


IDLmlSupportVectorMachineClassification::Classify


The IDLmlSupportVectorMachineClassification::Classify method assigns each example to an output class, returning an array of label results.

Syntax


Result = Obj->[IDLmlSupportVectorMachineClassification::]Classify(Features [, Keywords=Value])

Return Value


The method returns an array of class values that correspond to the data provided.

Arguments


Features

Specify an array of features of size n x m, where n is the number of attributes and m is the number of examples.

Keywords


LOSS (optional)

Set this keyword to a variable that will contain the loss result, which is a unitless number that indicates how closely the model fits the training data.

SCORES (optional)

Set this keyword to an array of size m, where m is the number of examples containing the actual scores associated with the features. Use this keyword to pass in the actual scores associated with the features if you want to calculate the loss.

UNMAPPED_CLASSES (optional)

Set this keyword to a variable that will contain the actual internal class values for the classification results.

IDLmlSupportVectorMachineClassification::Evaluate


The IDLmlSupportVectorMachineClassification::Evaluate method evaluates a number of features and returns an array of scores that represent how closely each feature matches each output.

Syntax


Result = Obj->[IDLmlSupportVectorMachineClassification::]Evaluate(Features [, Keywords=Value])

Return Value


This method returns the scores associated with the features. Scores represent the actual numerical outputs obtained by the model in response to a number of inputs.

Arguments


Features

Specify an array of features of size n x m, where n is the number of attributes and m is the number of examples.

Keywords


LOSS (optional)

Set this keyword to a variable that will contain the loss result, which is a unitless number that indicates how closely the model fits the training data.

SCORES (optional)

Set this keyword to an array of size m, where m is the number of examples containing the actual scores associated with the features. Use this keyword to pass in the actual scores associated with the features if you want to calculate the loss.

IDLmlSupportVectorMachineClassification::Restore


The IDLmlSupportVectorMachineClassification::Restore static method restores the classifier from a file.

Syntax


Result = IDLmlSupportVectorMachineClassification.Restore(Filename)

Return Value


A reference to the object instance restored from the file.

Arguments


Filename

Specify the name of the file to restore.

Keywords


None

IDLmlSupportVectorMachineClassification::Save


The IDLmlSupportVectorMachineClassification::Save method saves the classifier to a file.

Syntax


Obj->[IDLmlSupportVectorMachineClassification::]Save, Filename

Arguments


Filename

Specify the name of the file to save.

Keywords


None

IDLmlSupportVectorMachineClassification::Train


The IDLmlSupportVectorMachineClassification::Train method performs training on the model and the loss, which is a unitless number that indicates how closely the model fits the training data. Unlike all other models, IDLmlSupportVectorMachineClassification only needs to be trained once. Calling this method multiple times will not result in a better trained model.

Syntax


Result = Obj->[IDLmlSupportVectorMachineClassification::]Train(Features [, Keywords=Value])

Return Value


This method returns the loss, which is a unitless number that indicates how closely the model fits the training data.

Arguments


Features

Specify an array of features of size n x m, where n is the number of attributes and m is the number of examples.

Keywords


CALLBACK_FUNCTION (optional)

An optional string with the name of an IDL function to be called on each training iteration. The callback function must accept two arguments: loss and state. The callback function must return 1 (!true) if the training should perform another iteration, or 0 (!false) if it should stop training.

LABELS (optional)

An array of size m, where m is the number of examples containing the actual labels associated with the features.

SCORES (optional)

An array of size m, where m is the number of examples containing the actual scores associated with the features.

TRAIN_STATE (optional)

Specify optional user data to provide for the callback function.

Version History


8.7.1

Introduced

See Also


IDLmlAutoEncoder, IDLmlFeedForwardNeuralNetwork, IDLmlKMeans, IDLmlSoftmax, IDLmlSupportVectorMachineRegression, IDLmlTestClassifier