Ejemplo n.º 1
0
# load ex6data1.mat

X,y = utils.load_mat('data/ex4data1.mat')

utils.plot_twoclass_data(X,y,'x1', 'x2',['neg','pos'])
plt.savefig('fig1.pdf')


############################################################################
#  Part 1: Hinge loss function and gradient                                #
############################################################################

C = 1
theta = np.zeros((X.shape[1],))
J,grad = linear_svm.svm_loss_twoclass(theta,X,y,C)

print "J = ", J, " grad = ", grad

############################################################################
# Scale the data and set up the SVM training                               #
############################################################################

# scale the data

scaler = preprocessing.StandardScaler().fit(X)
scaleX = scaler.transform(X)

# add an intercept term and convert y values from [0,1] to [-1,1]

XX = np.array([(1,x1,x2) for (x1,x2) in scaleX])
Ejemplo n.º 2
0
############################################################################

# load ex6data1.mat

X, y = utils.load_mat('data/ex4data1.mat')

utils.plot_twoclass_data(X, y, 'x1', 'x2', ['neg', 'pos'])
plt.savefig('fig1.pdf')

############################################################################
#  Part 1: Hinge loss function and gradient                                #
############################################################################

C = 1
theta = np.zeros((X.shape[1], ))
J, grad = linear_svm.svm_loss_twoclass(theta, X, y, C)

print "J = ", J, " grad = ", grad

############################################################################
# Scale the data and set up the SVM training                               #
############################################################################

# scale the data

scaler = preprocessing.StandardScaler().fit(X)
scaleX = scaler.transform(X)

# add an intercept term and convert y values from [0,1] to [-1,1]

XX = np.array([(1, x1, x2) for (x1, x2) in scaleX])
Ejemplo n.º 3
0
 def loss(self, X, y, C):
   return svm_loss_twoclass(self.theta, X, y, C)