In the previous blog post we saw till the steps of collecting data from the CSV file to segregate the 30% of data for test and remaining 70% of the data for training. Now in this blog we will continue to build the SVM model and arrive at the confusion matrix which will end this series on SVM.
- Let use the SVM model using the model<-svm(SalesRating ~ .,data=dataset)
The above statement will be working correctly only if you have loaded e1701 library. We are specifying SalesRating because it’s the class which will be used by SVM for learning.
- Now you can see that the model has printed with SVM Type as C-Classification and Kernel used is Radial basis function with a cost 1 and Gamma of 0.5. The support vectors is 40
The summary function will provide you the classification and Levels information also as given in the below picture
Now we will plot the Model against the data so that we can understand the relationship on the sales vs temperature in the city as given below using the command plot(model,dataset):
- Now the next step is to really do the prediction, for the purpose predicting we need to classify the data Training Data Set and Test Data Set, which we have already done in our previous blog.
Now using the SVM we will train the system using SVM using the commands given in the screen
The plot output looks like this on the trainingset data:
- Now we will move on to prediction using the model which has been trained using the trainingset of data. We will use the prediction<-predict(model,testset[,-1]) for prediction with testset excluding the class column SalesRating.
- We would like generate the confusion matrix using the table statement with the following command tab<-table(pred=prediction,true=testset[,1])
When you print the tab you will get the confusion matrix like the following:
The confusion matrix looks like the below :
Now we will find the accuracy of the our prediction the Formula for Accuracy is
- Applying the above formula the accuracy is 89.79%
In the future post we will try to explore the scenario of multi-class classification.