# svmclassify

Classify using support vector machine (SVM)

`svmclassify` will be removed in a future release. See `fitcsvm`, `ClassificationSVM`, and `CompactClassificationSVM` instead.

## Syntax

`Group = svmclassify(SVMStruct,Sample)Group = svmclassify(SVMStruct,Sample,'Showplot',true)`

## Description

`Group = svmclassify(SVMStruct,Sample)` classifies each row of the data in `Sample`, a matrix of data, using the information in a support vector machine classifier structure `SVMStruct`, created using the `svmtrain` function. Like the training data used to create `SVMStruct`, `Sample` is a matrix where each row corresponds to an observation or replicate, and each column corresponds to a feature or variable. Therefore, `Sample` must have the same number of columns as the training data. This is because the number of columns defines the number of features. `Group` indicates the group to which each row of `Sample` has been assigned.

`Group = svmclassify(SVMStruct,Sample,'Showplot',true)` plots the `Sample` data in the figure created using the `Showplot` property with the `svmtrain` function. This plot appears only when the data is two-dimensional.

## Input Arguments

 `SVMStruct` Support vector machine classifier structure created using the `svmtrain` function. `Sample` A matrix where each row corresponds to an observation or replicate, and each column corresponds to a feature or variable. Therefore, `Sample` must have the same number of columns as the training data. This is because the number of columns defines the dimensionality of the data space. `Showplot` Describes whether to display a plot of the classification. Displays only for 2-D problems. Follow with a Boolean argument: `true` to display the plot, `false` to give no display.

## Output Arguments

 `Group` Column vector with the same number of rows as `Sample`. Each entry (row) in `Group` represents the class of the corresponding row of `Sample`.

## Examples

collapse all

### Classify an Observation Using a Trained SVM Classifier.

Find a line separating the Fisher iris data on versicolor and virginica species, according to the petal length and petal width measurements. These two species are in rows 51 and higher of the data set, and the petal length and width are the third and fourth columns.

```load fisheriris xdata = meas(51:end,3:4); group = species(51:end); figure; svmStruct = svmtrain(xdata,group,'ShowPlot',true); ```

Classify two new flowers, one with petal length 5 and petal width 2 and the other with petal length 4 and petal width 1.5.

```Xnew = [5 2; 4 1.5]; species = svmclassify(svmStruct,Xnew,'ShowPlot',true) hold on; plot(Xnew(:,1),Xnew(:,2),'ro','MarkerSize',12); hold off ```
```species = 'virginica' 'versicolor' ```

expand all

### Algorithms

The `svmclassify` function uses results from `svmtrain` to classify vectors x according to the following equation:

$c=\sum _{i}{\alpha }_{i}k\left({s}_{i},x\right)+b,$

where si are the support vectors, αi are the weights, b is the bias, and k is a kernel function. In the case of a linear kernel, k is the dot product. If c ≥ 0, then x is classified as a member of the first group, otherwise it is classified as a member of the second group.

## References

[1] Kecman, V., Learning and Soft Computing, MIT Press, Cambridge, MA. 2001.

[2] Suykens, J.A.K., Van Gestel, T., De Brabanter, J., De Moor, B., and Vandewalle, J., Least Squares Support Vector Machines, World Scientific, Singapore, 2002.

[3] Scholkopf, B., and Smola, A.J., Learning with Kernels, MIT Press, Cambridge, MA. 2002.

[4] Cristianini, N., and Shawe-Taylor, J. (2000). An Introduction to Support Vector Machines and Other Kernel-based Learning Methods, First Edition (Cambridge: Cambridge University Press). `http://www.support-vector.net/`