Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def svm_subgradient_solver(x, y, C, tol=1e-6, max_iter=100, verbose=False):
- Dict={}
- w=np.zeros(x.shape[1])
- g=np.zeros(x.shape[1])
- a = 1
- b = 10000
- for iteration in range(max_iter):
- g=np.copy(w)
- for n in range(y.shape[0]):
- if 1>y[n]*np.sum(w*x[n]):
- g-=C*y[n]*x[n]
- w=w-g * a / b
- Sum=0
- for i in range(y.shape[0]):
- Sum+=max(0,1-y[i]*np.sum(w*x[i]))
- print( 1/2*(np.sum(w*w)+C*Sum))
- return Dict
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement