How to build multiclass SVM in R?

后端 未结 2 999
南笙
南笙 2020-12-16 07:02

I am working on the project handwritten pattern recognition(Alphabets) using Support Vector Machines. I have 26 classes in total but I am not able to classi

相关标签:
2条回答
  • 2020-12-16 07:46

    There is no direct equivalent of Multiclass SVM in e1071. Besides, all approaches to use SVM for multiclass classification use techniques like 'one vs rest' or encoding, amongst others. Here is a reference detailing most common approaches... http://arxiv.org/ftp/arxiv/papers/0802/0802.2411.pdf

    If you want to use e1071 for multiclass SVM, you best can create 26 svm models, one for each class, and use the probability score to predict. This approach should be good enough for handwritten pattern recognition.

    0 讨论(0)
  • 2020-12-16 07:57

    For a multi class classifier, you can get probabilities for each class. You can set 'probability = TRUE' while training the model & in 'predict' api. This will give you the probabilities of each class. Below is the sample code for iris data set:

    data(iris)
    attach(iris)
    x <- subset(iris, select = -Species) 
    y <- Species
    model <- svm(x, y, probability = TRUE)
    pred_prob <- predict(model, x, decision.values = TRUE, probability = TRUE)
    

    With above code, 'pred_prob' will have probabilities among other data. You can access only probabilities in the object with below statement:

    attr(pred_prob, "probabilities")
    
             setosa  versicolor   virginica
    1   0.979989881 0.011347796 0.008662323
    2   0.972567961 0.018145783 0.009286256
    3   0.978668604 0.011973933 0.009357463
    ...
    

    Hope this helps.

    NOTE: I believe when you give 'probability' internally svm performs one vs rest classifier because, it takes lot more time with 'probability' param set against the model with 'probability' param not being set.

    0 讨论(0)
提交回复
热议问题