緯度と経度があるので、RBF カーネルを exp(-1/2||sophhere distrance||^2) に再定義する必要があります。つまり、カーネル関数を自分で書き直す必要があります。カーネルを次のように記述します。
round.kernel <- function(x,y){
sigma <- 1
#R <- 6371
R <- 1
a <- (sin( (x[1]-y[1])/2 ))^2+cos(x[1])*cos(y[1])*(sin((x[2]-y[2])/2))^2
c <- 2*atan2(sqrt(a),sqrt(1-a))
d <- R*c
res <- exp(-d^2/(2*sigma))
return (res)
}
class(round.kernel) <- "kernel"
関数をテストしましたが、カーネルは正しいはずです。しかし、次のトレーニング コマンドを使用すると、エラーが発生します。
fit <- ksvm(y=train[,2],x=train[,3:4],kernel=round.kernel,type='eps-svr')
Error in .local(x, ...) :
List interface supports only the stringdot kernel.
さらにトリッキーなのは、ksvm ドキュメントのサンプル コードを試したことです。
k <- function(x,y) {(sum(x*y) +1)*exp(-0.001*sum((x-y)^2))}
class(k) <- "kernel"
しかし、私は同じエラーが発生しています。
カーネル関数を正しく定義する方法を知っている人はいますか?