Skip to content

Instantly share code, notes, and snippets.

@kyu999
Created August 23, 2015 11:31
Show Gist options
  • Save kyu999/67404e7a1ebb3dcd8b4a to your computer and use it in GitHub Desktop.
Save kyu999/67404e7a1ebb3dcd8b4a to your computer and use it in GitHub Desktop.
monday todo
Monday todo:
Get support vectors and cul the minimum margin of them. Margin larger => better border
```
from sklearn import svm
X = [[0, 0], [1, 1]]
y = [0, 1]
clf = svm.SVC(kernel='linear')
clf.fit(X, y)
clf.support_vectors_
```
サポートベクター群の、境界関数を通した出力値を算出しその絶対値の最小値を取得。
@kyu999
Copy link
Author

kyu999 commented Aug 23, 2015

import numpy as np
from matplotlib import lines
from matplotlib import mlab
from matplotlib import pyplot as plt
from scipy import stats

def defomation(w, b, x):
return (-(b[0] + w[0][0] * x) / w[0][1])[0]

def getfig(aminos, data1, data2):
fig = plt.figure()
# プロット領域(1x1分割の1番目に領域を配置せよという意味)
ax = fig.add_subplot(111)
# 散布図
sc = ax.scatter(data1, data2, s=25, marker='x', color='b')
# 単回帰直線
func = lambda x: defomation(w, b, x)
line = lines.Line2D([0, 1], [func(0), func(1)], color='r')
ax.add_line(line)
# X, Y方向の表示範囲
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
# タイトル
ax.set_title('Protein Separation by Aminos', size=16)
ax.set_xlabel(aminos[0], size=14)
ax.set_ylabel(aminos[1], size=14)
# 凡例
ax.legend((sc,), ('2nd Test',), scatterpoints=1, loc='upper left', fontsize=10)
# グリッド表示
ax.grid(True)
return plt
#plt.show()

data1 = [0.3, 0.2, 0.3, 0.4, .5]
data2 = [.1, .2, .4, .8, .16]
w = np.array([[1, 1]])
b = np.array([[-0.3]])

plt = getfig("AE", data1, data2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment