0 votes
in Machine Learning by (30.5k points)

What is SVM (Support Vector Machines)?

1 Answer

0 votes
by (19.8k points)
SVM is a Machine Learning algorithm that is majorly used for classification. It is used on top of the high dimensionality of the characteristic vector.

Below is the code for the SVM classifier:

# Introducing required libraries

from sklearn import datasets

from sklearn.metrics import confusion_matrix

from sklearn.model_selection import train_test_split

# Stacking the Iris dataset

iris = datasets.load_iris()

# A -> features and B -> label

A = iris.data

B = iris.target

# Breaking A and B into train and test data

A_train, A_test, B_train, B_test = train_test_split(A, B, random_state = 0)

# Training a linear SVM classifier

from sklearn.svm import SVC

svm_model_linear = SVC(kernel = 'linear', C = 1).fit(A_train, B_train)

svm_predictions = svm_model_linear.predict(A_test)

# Model accuracy for A_test

accuracy = svm_model_linear.score(A_test, B_test)

# Creating a confusion matrix

cm = confusion_matrix(B_test, svm_predictions)

Related questions