A linear support vector machine finds the separating line with the widest margin. Train it with (sub)gradient descent on the regularised hinge loss, for labels :
Subgradient: examples with margin contribute (and for ), averaged over ; the regulariser contributes (not to ).
Implement hinge_loss(X, y, w, b, lam), train_svm(X, y, lam=0.01, lr=0.1, epochs=500) (full-batch, starting from zeros, returning (w, b)), predict_svm(X, w, b) (±1, with 0 mapping to +1) and support_vectors(X, y, w, b, tol=1e-3): the indices with margin ≤ 1 + tol.