SVM Geometric Margin

Easy
~10 min
code completion

SVM Margin

An SVM finds the hyperplane that maximizes the margin between classes. The margin is the distance between the two support hyperplanes:

where is the normal vector of the decision boundary. Maximizing the margin is equivalent to minimizing .

The signed distance from a point to the decision boundary is:

Positive for one class, negative for the other.

Your task:

Implement svm_margin(w) that returns the geometric margin given the weight vector.

Example Tests

Unit vector: margin = 2

Input: {"w":[1,0]}

Expected: 2

||w||=2: margin = 1

Input: {"w":[2,0]}

Expected: 1

3-4-5 right triangle: ||w||=5, margin=0.4

Input: {"w":[3,4]}

Expected: 0.4

Sign in to solve this problem

You can read the full problem statement above. Create a free account to run code in the browser, submit solutions, and track your progress.