v9.1.1
Menu

Linear Decision Boundary

easyFREESupport Vector MachinesMachine Learning 1

Classify data points using a linear decision boundary.

Given weights ww and bias bb, classify each point xx using: f(x)=sign(w⋅x+b)f(x) = \text{sign}(w \cdot x + b)

where sign(z)=+1\text{sign}(z) = +1 if z≥0z \geq 0, and −1-1 if z<0z < 0.

Return a list of predictions (+1+1 or −1-1).

Example

Input
X = [[1, 2], [-1, -2], [2, 0]]
w = [1, 1]
b = 0
Output
[1, -1, 1]
Reasoning
  • Inputs: X holds three 2-D points, one per row; w =(1,1)= (1, 1) is the weight vector (one weight per feature) and b =0= 0 is the bias. Together they define the boundary line w⋅x+b=0w \cdot x + b = 0, here x1+x2=0x_1 + x_2 = 0.
  • Score each point with z=w1x1+w2x2+bz = w_1 x_1 + w_2 x_2 + b:
    • (1,2)(1, 2): z=1+2+0=3z = 1 + 2 + 0 = 3
    • (−1,−2)(-1, -2): z=−1−2+0=−3z = -1 - 2 + 0 = -3
    • (2,0)(2, 0): z=2+0+0=2z = 2 + 0 + 0 = 2
  • Apply the sign: sign(3)=+1\text{sign}(3) = +1, sign(−3)=−1\text{sign}(-3) = -1, sign(2)=+1\text{sign}(2) = +1, giving [1, -1, 1], one label per row of X, in order.
  • Geometric view: zz says which side of the line a point falls on. (1,2)(1, 2) and (2,0)(2, 0) lie above x1+x2=0x_1 + x_2 = 0; (−1,−2)(-1, -2) lies below it.
  • Notice: a point exactly on the line has z=0z = 0 and is labelled +1+1 because sign(0)=+1\text{sign}(0) = +1, so the output never contains 00.

Constraints

  • X: 2D list (n_samples x n_features)
  • w: list of weights (same length as features)
  • b: scalar bias
  • Return list of +1 or -1 predictions
  • sign(0) = +1

Learn this in

More from Machine Learning 1

solution.py

Test results

Sign in to run your code against the test cases.