Logistic regression — which side of the decision boundary
Background
The decision boundary of logistic regression is the set of points where . Because , that is exactly the linear equation
The sigmoid is monotonic, so . That means you can classify a point by the sign of the score alone — no sigmoid required. Points with land on the class-1 side, points with on the class-0 side.
Problem statement
Implement boundary_side(X, w, b) that labels each row of X as class 1 when , else class 0.
Input
X— array-like of shape(m, n): one feature vector per row.w— array-like weight vector of lengthn.b—float, the bias.
Output
Returns an np.ndarray of m integer labels (0 or 1).
Examples
Example 1 — the lesson's boundary
Input: X = [[2, 2], [0, 0], [1, 1]], w = [2, 3], b = -5
Output: [1 0 0]
Explanation: scores are (class 1), (class 0), and on the boundary, which is not so it falls to class 0.
Example 2 — one feature
Input: X = [[2], [-3], [0]], w = [1], b = 0
Output: [1 0 0]
Explanation: the score equals the input; positive → class 1.
Constraints
- Compute the score for every row, then label by
score > 0. - A point exactly on the boundary () is class 0 (strict
>). - Return integer labels.
Notes
- This is why a logistic-regression boundary is a straight line (2D), plane (3D), or hyperplane (n-D): it's the solution set of one linear equation. The sigmoid bends the probability, never the boundary.
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Example — lesson boundary 2x1 + 3x2 - 5 = 0
- •Reference — one feature, label matches sign of score
- •Sample — four rows with unit weights