PIXELBANKv8.2.1
Menu

Linear Decision Boundary

Classify data points using a linear decision boundary.

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

where sign(z)=+1\text{sign}(z) = +1 if z0z \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:
  • We calculate the dot product of each point xx in XX with the weight ww:
    • For x=[1,2]x = [1, 2], wx=(1)(1)+(1)(2)=3w \cdot x = (1)(1) + (1)(2) = 3
    • For x=[1,2]x = [-1, -2], wx=(1)(1)+(1)(2)=3w \cdot x = (1)(-1) + (1)(-2) = -3
    • For x=[2,0]x = [2, 0], wx=(1)(2)+(1)(0)=2w \cdot x = (1)(2) + (1)(0) = 2
  • We add the bias bb to each result:
    • For x=[1,2]x = [1, 2], wx+b=3+0=3w \cdot x + b = 3 + 0 = 3
    • For x=[1,2]x = [-1, -2], wx+b=3+0=3w \cdot x + b = -3 + 0 = -3
    • For x=[2,0]x = [2, 0], wx+b=2+0=2w \cdot x + b = 2 + 0 = 2
  • We apply the sign function to each result to get the predictions:
    • For x=[1,2]x = [1, 2], sign(3)=+1\text{sign}(3) = +1
    • For x=[1,2]x = [-1, -2], sign(3)=1\text{sign}(-3) = -1
    • For x=[2,0]x = [2, 0], sign(2)=+1\text{sign}(2) = +1
  • The final output is [1,1,1][1, -1, 1]

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
Editor

Test Results

0/0
Run code to see test results.