I'm trying to run a SVM regression on some data and I want to use ksvm from kernlab or svm from e1071. But the number and type of kernels available is too restrictive. So I'm thinking of writing my own kernel function.

Let's assume I want to write the kernel for heavy-tailed RBF for which the formula is

$$ K(x_i, x_j) = \exp\left(-\gamma * ||x_i^a - x_j^a||^b\right) $$

How do I do this?

I found several instances where people do something similar to the following code.


    diff <- xi^a - xj^a

    absValue <- abs(diff^b)

    exp(-gamma * absVal)

class(kp) <- "kernel"

model <- ksvm(xtrain, ytrain, type="eps-svr", kernel=kp, cross=10)

Is this correct or is there something else that is needed? Also how do I get the best values of a, b and $\gamma$ for my data?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.