SVM Implementation Step by Step with R: Ice-cream sales prediction

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.

  1. Let use the SVM model using the model<-svm(SalesRating ~ .,data=dataset)
  2. 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.

  3. 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
  4. The summary function will provide you the classification and Levels information also as given in the below picture

  5. 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):

  6. 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.
  7. Now using the SVM we will train the system using SVM using the commands given in the screen

  8. The plot output looks like this on the trainingset data:

  9. 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.
  10. We would like generate the confusion matrix using the table statement with the following command tab<-table(pred=prediction,true=testset[,1])
  11. When you print the tab you will get the confusion matrix like the following:

  12. The confusion matrix looks like the below :

  13. Now we will find the accuracy of the our prediction the Formula for Accuracy is

  14. Applying the above formula the accuracy is 89.79%

In the future post we will try to explore the scenario of multi-class classification.

Additional References:

http://www2.cs.uregina.ca/~dbd/cs831/notes/confusion_matrix/confusion_matrix.html

http://en.wikipedia.org/wiki/Confusion_matrix

http://en.wikibooks.org/wiki/Data_Mining_Algorithms_In_R/Classification/SVM

Advertisements

One thought on “SVM Implementation Step by Step with R: Ice-cream sales prediction

  1. Pingback: SVM Implementation Step by Step with R: Ice-cream sales prediction | இனிது இனிது எனது தமிழ் மொழி இனிது..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s