Categories

Jan 18 in Machine Learning
Q:

What is SVM (Support Vector Machines)?

1 Answer

Jan 18
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)
Click here to read more about Loan/Mortgage
Click here to read more about Insurance

Related questions

Madanswer
Dec 27, 2019 in Data Science
Feb 17 in Azure
Jul 24, 2019 in Azure
...