user42
user42

Reputation: 959

How to print the summary of SVM in Python (equivalent to R)?

I have fitted an SVM with a linear kernel to some randomly generated data. The code is shown below.

import pandas as pd
import numpy as np
from sklearn.svm import SVC


np.random.seed(3)
x = np.random.randn(20,2)
y = np.repeat([1,-1], 10)

#Adding 1 to each of the observations:
x[y == -1] = x[y == -1]+1
from sklearn.svm import SVC
#Fitting the SVM
svc = SVC(kernel='linear', C=10)
svmfit = svc.fit(x,y)

In R, using the command summary(svmfit) gives a nice and brief description of the parameters of the SVM as shown below (I have taken the image from Introduction to Statistical Learning, Chapter 9 - Support Vector Machines from the lab exercises) Introduction to Statistical Learning, Chapter 9.

I'm unable to find a similar function in Python. I am aware I can use the attributes of SVM like the classes_, support_vectors_, n_support_ to get them individually. But I would like to have it similar to the summary() function in R.

Is there such a function or library that exists which I might have missed while searching? (Because I also know that statsmodels gives a very nice description of the regression models similar to R)

Upvotes: 2

Views: 1577

Answers (1)

Ailurophile
Ailurophile

Reputation: 3005

Well AFAIK, there is no package that provides a summary of the SVM model in Python, and sklearn is used for predictive modeling/machine learning and the evaluation criteria are based on performance on previously unseen data.

Alternatively, Similar to R ---> summary(svmfit) , if you

print(svmfit)
SVC(C=10, break_ties=False, cache_size=200, class_weight=None, coef0=0.0,
    decision_function_shape='ovr', degree=3, gamma='scale', kernel='linear',
    max_iter=-1, probability=False, random_state=None, shrinking=True,
    tol=0.001, verbose=False)

You get all the parameters with initiated and default values in the SVM model.

Upvotes: 2

Related Questions