📘
Linear Decision Boundary
Classify data points using a linear decision boundary.
Given weights w and bias b, classify each point x using: f(x)=sign(w⋅x+b)
where sign(z)=+1 if z≥0, and −1 if z<0.
Return a list of predictions (+1 or −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 x in X with the weight w:
- For x=[1,2], w⋅x=(1)(1)+(1)(2)=3
- For x=[−1,−2], w⋅x=(1)(−1)+(1)(−2)=−3
- For x=[2,0], w⋅x=(1)(2)+(1)(0)=2
- We add the bias b to each result:
- For x=[1,2], w⋅x+b=3+0=3
- For x=[−1,−2], w⋅x+b=−3+0=−3
- For x=[2,0], w⋅x+b=2+0=2
- We apply the sign function to each result to get the predictions:
- For x=[1,2], sign(3)=+1
- For x=[−1,−2], sign(−3)=−1
- For x=[2,0], sign(2)=+1
- The final output is [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
Python 3.13.1
Test Results
0/0Run code to see test results.