Soft-Margin SVM Objective

~12 mincode completion

Implement svm_objective(X, y, w, b, C) returning 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

Run your code to see results

⌘↵ runs against the visible tests

Loading docs…

The AI Mentor needs an account

It reads your code and the failing tests and nudges you toward the fix without handing you the answer. Free accounts get it on every problem you're working on today.