#309Logistic regression — which side of the decision boundaryEasy

Logistic regression — which side of the decision boundary

Background

The decision boundary of logistic regression is the set of points where P(y=1)=0.5\mathbb{P}(y=1)=0.5. Because σ(0)=0.5\sigma(0)=0.5, that is exactly the linear equation

wx+b=0.\mathbf{w}^\top \mathbf{x} + b = 0.

The sigmoid is monotonic, so σ(z)>0.5    z>0\sigma(z) > 0.5 \iff z > 0. That means you can classify a point by the sign of the score alone — no sigmoid required. Points with z>0z > 0 land on the class-1 side, points with z<0z < 0 on the class-0 side.

Problem statement

Implement boundary_side(X, w, b) that labels each row of X as class 1 when wx+b>0\mathbf{w}^\top\mathbf{x} + b > 0, else class 0.

Input

  • X — array-like of shape (m, n): one feature vector per row.
  • w — array-like weight vector of length n.
  • bfloat, the bias.

Output

Returns an np.ndarray of m integer labels (0 or 1).

Examples

Example 1 — the lesson's boundary 2x1+3x25=02x_1 + 3x_2 - 5 = 0

Input:  X = [[2, 2], [0, 0], [1, 1]], w = [2, 3], b = -5
Output: [1 0 0]

Explanation: scores are 22+325=5>02\cdot2+3\cdot2-5=5>0 (class 1), 5<0-5<0 (class 0), and 00 on the boundary, which is not >0>0 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 Xw+bX\mathbf{w} + b for every row, then label by score > 0.
  • A point exactly on the boundary (z=0z = 0) 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.
Python
Loading...

▶ 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