LoginSignup
1
2

More than 5 years have passed since last update.

numpyを使ってRBFでカーネル回帰をやってみる

Last updated at Posted at 2017-06-18

カーネル回帰とは

カーネル関数を用いて学習・予測を行う回帰。
非線形なデータに対しての回帰に有効である。
予測時にも訓練データを使用する。

RBF

ガウスカーネルとも呼ばれる。無限次元特徴ベクトルの内積としてみなすことができる。
RBFは次式で表される。


k(x_i, x_j) = \exp(-\gamma||x_i - x_j||^2)

i行j列目の要素を $k(x_i, x_j)$ とする行列が$K$である。つまり$K$はサンプル数を次元とする正方行列である。

numpyでKを計算


def rbf(x1, x2, gamma=0.1):
    return np.exp(-1 * gamma * (np.linalg.norm(x1- x2, axis=2)))

x = np.arange(120).reshape(40,3)
K = rbf(x[:, np.newaxis, :], x[np.newaxis, :, :])
print(K.shape)

numpyのnewaxisとbroadcastを活用してx1とx2の距離を計算している。

続く...

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2