【问题标题】:Is there a direct implementation of multiclass SVM in R(e1071)R(e1071) 中是否有直接实现多类 SVM
【发布时间】:2016-09-21 03:42:47
【问题描述】:

我有五个类,我想使用 SVM(e1071 包)进行分类。我可以看到一些使用 SVM 进行二进制分类的好例子,但是,对于多类支持,一些成员建议使用 One_Vs_Rest 或 One_vs_One 二进制分类器,然后将它们组合起来以获得最终预测。是否有 Multiclass 的直接实现(任何一种方法都适合我)?

【问题讨论】:

    标签: svm


    【解决方案1】:

    是的,现在,我找到了解决方案。我使用了 R 中的基本帮助文件,并使用 e1071 实现了 One_vs_One 多类,它非常简短,并且带有清晰的 cmets。

    library(xlsx)
    library(gdata)
    data(iris)
    library(e1071)
    library(caTools)
    
    ##---------- Split the overall dataset into two parts:70% for training and 30% for testing-----------
    index_iris<-sample.split(iris$Species,SplitRatio=.7) 
    trainset_iris<-iris[index_iris==TRUE,] 
    testset_iris<-iris[index_iris==FALSE,] 
    y <- testset_iris$Species
    
    ##---------- Now Create an SVM Model with the training dataset--------------------
    model <- svm(Species ~ ., data = trainset_iris)
    # print(model)
    # summary (model)
    
    ##-------------Use the model to predict the test dataset so that we can find the accuracy of the model-----
    pred <- predict(model,testset_iris)
    table(pred, y)
    
    ##-------------- Compute decision values and probabilities--------------
    pred <- predict(model, testset_iris, decision.values = TRUE)
    attr(pred, "decision.values")
    

    【讨论】:

      猜你喜欢
      • 2013-01-02
      • 2023-03-18
      • 2012-06-16
      • 2018-02-10
      • 2014-03-27
      • 2011-11-15
      • 2016-08-13
      • 2019-01-21
      • 2014-11-23
      相关资源
      最近更新 更多