All problems
SVM Dual Objective Value
Problem
The dual objective of a hard-margin SVM is sum_i alpha_i - 0.5 * sum_ij alpha_i alpha_j y_i y_j (x_i dot x_j).
Given the feature vectors, the labels, and the dual coefficients, return the objective value.
Hint
Sum the coefficients, then subtract half the quadratic form.
Test cases
case 1
in: [[[1,0],[0,1]],[1,-1],[1,1]]
expected: 1
case 2
in: [[[1,1],[2,2]],[1,1],[0.5,0.5]]
expected: -1.25
case 3
in: [[[1,0],[-1,0]],[1,-1],[1,1]]
expected: 0
Starter codePython
def svm_dual_objective_value(xs, ys, alpha):
# Your code here
pass3 test cases · run your code against them in the editor