Soft-Margin SVM Objective
~12 mincode completion
Implement svm_objective(X, y, w, b, C) returning J as a float.
Where this shows up
~12 min
••••••••••••••
7 employers weight this skill
2 health and bio companies, 2 quant funds, 2 enterprise vendors, 1 AI product company. Top match scores 87.
Python
import numpy as np
def svm_objective(X, y, w, b, C):
"""
Soft-margin SVM objective with the hinge loss.
Args:
X: array of shape (n, d)
y: array of shape (n,), labels -1 or +1
w: array of shape (d,)
b: float bias
C: penalty on margin violations
Returns:
float: 0.5 * ||w||^2 + C * sum(max(0, 1 - y * (X @ w + b)))
"""
# YOUR CODE HERE
pass