rsvmlibsvm

SVM packages that support data instances weighting in R


I am looking for a SVM package in R that accepts specifying a weight for each instance of the data. I have found e1071 package, it provides a class weighting option with class.weights parameter, but it does not provide any option for instance weighting. I also found wsvm package, but neither it provides that functionality. I am looking for something like libsvm-weights-3.17 in R.


Solution

  • Try this package: https://CRAN.R-project.org/package=WeightSVM

    It uses a modified version of 'libsvm' and is able to deal with instance weighting.

    For example. You have simulated data (x,y)

    x <- seq(0.1, 5, by = 0.05)
    y <- log(x) + rnorm(x, sd = 0.2)
    

    This is an unweighted SVM:

    model1 <- wsvm(x, y, weight = rep(1,99))
    

    Blue dots is the unweighted SVM and do not fit the first instance well. We want to put more weights on the first several instances.

    So we can use a weighted SVM:

    model2 <- wsvm(x, y, weight = seq(99,1,length.out = 99))
    

    Green dots is the weighted SVM and fit the first instance better.