How to do multi class classification using Support Vector Machines (SVM)

后端 未结 8 1966
孤独总比滥情好
孤独总比滥情好 2021-01-30 16:08

In every book and example always they show only binary classification (two classes) and new vector can belong to any one class.

Here the problem is I have 4 classes(c1,

相关标签:
8条回答
  • 2021-01-30 16:53

    Nothing special compared with binary prediction. see the following example for 3-class prediction based on SVM.

    install.packages("e1071")
    library("e1071")
    data(iris)
    attach(iris)
    ## classification mode
    # default with factor response:
    model <- svm(Species ~ ., data = iris)
    # alternatively the traditional interface:
    x <- subset(iris, select = -Species)
    y <- Species
    model <- svm(x, y) 
    print(model)
    summary(model)
    # test with train data
    pred <- predict(model, x)
    # (same as:)
    pred <- fitted(model)
    # Check accuracy:
    table(pred, y)
    # compute decision values and probabilities:
    pred <- predict(model, x, decision.values = TRUE)
    attr(pred, "decision.values")[1:4,]
    # visualize (classes by color, SV by crosses):
    plot(cmdscale(dist(iris[,-5])),
         col = as.integer(iris[,5]),
         pch = c("o","+")[1:150 %in% model$index + 1])
    
    0 讨论(0)
  • 2021-01-30 16:59

    For multi class classification using SVM; It is NOT (one vs one) and NOT (one vs REST).

    Instead learn a two-class classifier where the feature vector is (x, y) where x is data and y is the correct label associated with the data.

    The training gap is the Difference between the value for the correct class and the value of the nearest other class.

    At Inference choose the "y" that has the maximum value of (x,y).

    y = arg_max(y') W.(x,y') [W is the weight vector and (x,y) is the feature Vector]

    Please Visit link: https://nlp.stanford.edu/IR-book/html/htmledition/multiclass-svms-1.html#:~:text=It%20is%20also%20a%20simple,the%20label%20of%20structural%20SVMs%20.

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