0

Is it possible to get the number of support vectors and (or) their values for an RBF SVC when it is fit using a sklearn Pipeline object? My pipeline looks like this

dim_reduction = TruncatedSVD( n_components = dim_reduction_n_comp, random_state = 611 )   
classifier_obj = sklearn.pipeline.Pipeline([
        ('scaler', sklearn.preprocessing.StandardScaler()),
        ( 'dim_reduction', dim_reduction ),
        ( 'svc', sklearn.svm.SVC(C= svc_c, gamma = svc_gamma, probability = True ) )
    ])

I want to calculate the footprint of the SVC by getting the support vectors and their coefficients and use it as a parameter to optuna optimization study.

Shahnawaz
  • 3
  • 2
  • Have you check [the docs](https://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html) for the attributes of the SVC? A fitted SVC object has attributes for `support_vectors_` and `coef_` that you can access, have you tried either? – G. Anderson Aug 16 '22 at 16:23

1 Answers1

0

The Number of support vectors for each class can be retrieved from the property n_support_ of the SVC object, using:

classifier_obj[2].n_support_

The result will be an ndarray of shape (n_classes,) with integers which represent the number of vectors for each class, in the corresponding order as in the property classes_, which contains the classes labels:

classifier_obj[2].classes_

nferreira78
  • 1,013
  • 4
  • 17
  • 1
    Thank you. That helps. I am trying to figure out the size of the ```classifier_obj```. I can use the brute method of using something like ```len(pickle.dumps(classifier_obj))```. However, I am trying to use something more meaningful and explainable, like adding the size of the support vectors and dim_reduction matrices, (```sum( n_support) * n_features +( n_features * n_componets) + ...```. – Shahnawaz Aug 17 '22 at 09:46
  • Glad to know it helped. If you please vote up on my answer, that would be appreciated – nferreira78 Aug 17 '22 at 11:46
  • Unfortunately, I can not. Stackoverflow told me that I am too new for upvoting and need to earn more reputation before I can do it... – Shahnawaz Aug 19 '22 at 08:11
  • No rush, come back later once you have the possibility to upvote ;) – nferreira78 Aug 19 '22 at 09:48