JuliaML / LIBSVM.jl

LIBSVM bindings for Julia
Other
88 stars 35 forks source link

Allow callable as kernel argument #86

Closed till-m closed 2 years ago

till-m commented 2 years ago

For the built-in kernels you supply the data and the kernel you want to use, i.e.

model = svmtrain(Xtrain, ytrain, kernel=Kernel.Polynomial)

svmpredict(model, Xtest)

For a custom kernel you need to calculate the gram matrix manually:

K = make_gram(Xtrain, my_kernel)
model = svmtrain(K, ytrain, kernel=Kernel.Precomputed)

KK = make_gram(Xtrain, Xtest, my_kernel)
svmpredict(model, KK)

I think a more desirable way to do this would be to allow a callable as kernel argument (and calculate the gram matrix internally), i.e.

model = svmtrain(Xtrain, ytrain, kernel=my_kernel)

svmpredict(model, Xtest)

which is more syntactically consistent with the way the built-in kernels are used. Scikit-learn, for example, allows this in addition to precomputed gram matrices.