I want to compare number of support vectors in different SVM model. I have data for training/testing. I wan't to see how different are the numbers of support vectors in case of One vs One and One vs All methods. How can I know it?

  • $\begingroup$ How should I calculate it? In what sense? Like, you calculate the number of Support Vectors in both regimes and compare it. Without further clarifications this sounds unclear. $\endgroup$
    – Firebug
    May 11, 2017 at 20:42
  • $\begingroup$ The time spent on one vs one is much less than one vs all both for training and testing of one feature. I want to see if the SV number is influencing it. Need exact numbers $\endgroup$
    – maximus
    May 12, 2017 at 4:12

2 Answers 2


One important concept in SVM is $\alpha$, (see this answer for details), the lagrange multipliers. For each data point $i$, there is associated $\alpha_i$. Most $\alpha_i$ will close to $0$, for non-zero ones, it is a support vector. Counting non-zero $\alpha$ is the way to go. Different software will have different implementations.

Here is a reproducible example in R.


svp <- ksvm(d$x,d$classes,type="C-svc",kernel="polydot",
            prob.model=TRUE,kpar=list(degree=1, scale=1, offset=0))


Here is the output for svp, and length(svp@alpha[[1]]). Note there are $6$ support vectors in this case (as plotted in the figure, $6$ solid black points), and the length of $\alpha$ is 6, since it contains only none-zero values.

> svp
Support Vector Machine object of class "ksvm" 

SV type: C-svc  (classification) 
 parameter : cost C = 1 

Polynomial kernel function. 
 Hyperparameters : degree =  1  scale =  1  offset =  0 

Number of Support Vectors : 6 

Objective Function Value : -2.6809 
Training error : 0 
Probability model included. 
> svp@alpha
[1] 1.0000000 0.3360636 1.0000000 0.8088748 1.0000000 0.1449384

enter image description here


If you are using scikit-learn library in Python, you can use


where clf is your support vector classifier. More information on the attributes can be found here.


Not the answer you're looking for? Browse other questions tagged or ask your own question.