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.
Step 2: Import the Loan Default data set
Data set consist of Account Number of the customer, Gender, Age, Salary and Default Status.
Step 3: Install the “e1071” package using following commands
Step 4: In this analysis we would use just last three columns. So we would select last three columns using the following command
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.
Step 6: Use the following command to run the SVM algorithm
Step 7: Predicting the results using following commands
Step 8: Check the accuracy using confusion matrix.