Beispiel #1
0
[1],
[1],
[1],
[1],
[1],
[1]]
X=np.array(X).transpose()
print X.shape


y=np.array(y).flatten(1)
y[y==0]=-1
print y.shape
def Gauss_kernel(x,z,sigma=1):
		return np.exp(-np.sum((x-z)**2)/(2*sigma**2))
svms=SVMC(X,y,kernel=Gauss_kernel)
svms.train()
print len(svms.supportVec),"SupportVectors:"

for i in range(len(svms.supportVec)):
	t=svms.supportVec[i]
	print svms.X[:,t]
svms.error(X,y)
for i in range(svms.M):
			if  svms.y[i]==-1:
				plt.plot(svms.X[0,i],svms.X[1,i],'or')
			elif  svms.y[i]==1:
				plt.plot(svms.X[0,i],svms.X[1,i],'ob')
for i in svms.supportVec:
			plt.plot(svms.X[0,i],svms.X[1,i],'oy')
plt.show()
Beispiel #2
0
y = [[0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [1], [1], [1], [1],
     [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1],
     [1], [1], [1], [1], [1], [1], [1]]
X = np.array(X).transpose()
print X.shape

y = np.array(y).flatten(1)
y[y == 0] = -1
print y.shape


def Gauss_kernel(x, z, sigma=1):
    return np.exp(-np.sum((x - z)**2) / (2 * sigma**2))


svms = SVMC(X, y, C=12, kernel=Gauss_kernel)
svms.train()
print len(svms.supportVec), "SupportVectors:"

for i in range(len(svms.supportVec)):
    t = svms.supportVec[i]
    print svms.X[:, t]
svms.error(X, y)
for i in range(svms.M):
    if svms.y[i] == -1:
        plt.plot(svms.X[0, i], svms.X[1, i], 'or')
    elif svms.y[i] == 1:
        plt.plot(svms.X[0, i], svms.X[1, i], 'ob')
for i in svms.supportVec:
    plt.plot(svms.X[0, i], svms.X[1, i], 'oy')
plt.show()
Beispiel #3
0
[1],
[1],
[1],
[1],
[1],
[1],
[1],
[1],
[1],
[1],
[1],
[1],
[1],
[1],
[1]]
X=np.array(X).transpose()
print X.shape


y=np.array(y).flatten(1)
y[y==0]=-1
print y.shape

svms=SVMC(X,y)
svms.train()
print len(svms.supportVec)
for i in range(len(svms.supportVec)):
	t=svms.supportVec[i]
	print svms.X[:,t]
svms.prints_test_linear()
Beispiel #4
0
import numpy as np
import scipy as sp
from dml.SVM import SVMC
X = [[6.6, 9.5], [7.6, 11.5], [9.95, 12.85], [13.25, 13.6], [12.5, 11.75],
     [10, 10.6], [7.85, 10.45], [9.8, 11.3], [11.8, 13.35], [7.25, 13.5],
     [5.4, 10.55], [8.45, 10.1], [11.25, 13], [13, 16.55], [6.35, 6.1],
     [7.85, 4.35], [11.05, 4.1], [13.3, 6.3], [12.8, 8.5], [11.05, 7.9],
     [8.65, 5.9], [8.3, 4.65], [13.05, 6.35], [10.8, 6.95], [9.4, 5.9],
     [8.7, 6.2], [7.75, 5.85], [9.3, 5.1], [11.65, 5.65], [12.35, 6.25],
     [9.2, 6.8], [9.85, 6.25]]

y = [[0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [1],
     [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1],
     [1], [1]]
X = np.array(X).transpose()
print X.shape

y = np.array(y).flatten(1)
y[y == 0] = -1
print y.shape

svms = SVMC(X, y)
svms.train()
print len(svms.supportVec)
for i in range(len(svms.supportVec)):
    t = svms.supportVec[i]
    print svms.X[:, t]
svms.prints_test_linear()