Example #1
0
# transform y from [0,1] to [-1,1]

yy = np.ones(y.shape)
yy[y == 0] = -1

# set up the SVM and learn the parameters

svm = LinearSVM_twoclass()
svm.theta = np.zeros((KK.shape[1], ))
C = 1
svm.train(KK, yy, learning_rate=1e-4, C=C, num_iters=20000, verbose=True)

# visualize the boundary

utils.plot_decision_kernel_boundary(X, y, scaler, sigma, svm, '', '',
                                    ['neg', 'pos'])
plt.savefig("fig4.pdf")

############################################################################
#  Part  4: Training SVM with a kernel                                     #
#  Select hyperparameters C and sigma                                      #
############################################################################

# load ex4data3.mat

X, y, Xval, yval = utils.loadval_mat('data/ex4data3.mat')

# transform y and yval from [0,1] to [-1,1]

yy = np.ones(y.shape)
yy[y == 0] = -1
Example #2
0
# transform y from [0,1] to [-1,1]

yy = np.ones(y.shape)
yy[y == 0] = -1

# set up the SVM and learn the parameters

svm = LinearSVM_twoclass()
svm.theta = np.zeros((KK.shape[1],))
C = 1
svm.train(KK,yy,learning_rate=1e-4,C=C,num_iters=20000,verbose=True)

# visualize the boundary

utils.plot_decision_kernel_boundary(X,y,scaler,sigma,svm,'','',['neg','pos'])
plt.savefig("fig4.pdf")

############################################################################
#  Part  4: Training SVM with a kernel                                     #
#  Select hyperparameters C and sigma                                      #
############################################################################

# load ex4data3.mat

X,y,Xval,yval = utils.loadval_mat('data/ex4data3.mat')

# transform y and yval from [0,1] to [-1,1]

yy = np.ones(y.shape)
yy[y == 0] = -1