Support Vector Machine(Classification)-R

0
123

We have already understood conceptually, how Support Vector Machine algorithm works. Let’s try to implement a SVM logic using R commands.

We would use Loan Default data to implement SVM- Classification.

Let us look into codes step by step.

Step 1: First setup the working library for the R-Studio or whichever interface you are using. We set a working library as it becomes easier to importing the stored dataset or even while saving final codes.

SVM_C1

Step 2: Import the Loan Default data set

 

SVM_C2

Data set consist of Account Number of the customer, Gender, Age, Salary and Default Status.

Step 3: Install the “e1071” package using following commands

SVM_C3

Step 4: In this analysis we would use just last three columns. So we would select last three columns using the following command

SVM_C4

Step 5: Since range of two of our predictor variables is very different, while Age varies from 18-60 whereas salary varies from 1127-142293. We need to do feature scaling so that both of the variables have same proportional impact on the target variable. In the following command we are excluding the target variable from feature scaling which is at position 3.

 

SVM_C5

Step 6: Use the following command to run the SVM algorithm

SVM_C6

Step 7: Predicting the results using following commands

SVM_C7

Step 8: Check the accuracy using confusion matrix.

SVM_C8

 

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here