LoginSignup
1
1

More than 3 years have passed since last update.

オンライン support vector regression (SVR)

Last updated at Posted at 2019-06-16

こんにちは。
"awerries/online-svr" (GitHub) というものを見つけたので動かしてみました。なお sklearn.svm.SVR (オフライン)の結果と差がある原因は不明です。

plot.jpg

svr.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import numpy as np
import random
import matplotlib.pyplot as plt
from sklearn import svm

import online_svr

N = 100
X = np.linspace(0, 8, N)
y = np.sin(X*np.pi/4) + [random.gauss(0, 0.1) for _ in range(N)]
X = X[:, np.newaxis]

OSVR = online_svr.OnlineSVR(numFeatures=1, C=1, eps=0.1, kernelParam=1, bias=0, debug=False)
for i in range(N):
    OSVR.learn(X[i], y[i])
plt.plot(X, OSVR.predict(X), color='red', label='on-line')

svr = svm.SVR(kernel='rbf', gamma=1, C=1.0, epsilon=0.1, shrinking=False, verbose=True)
svr.fit(X, y)
plt.plot(X, svr.predict(X), color='purple', label='off-line')

plt.scatter(X, y, s=5)
plt.legend()
plt.grid()
plt.show()
1
1
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
1