#312Logistic regression — the sigmoid reflection identityEasy

Logistic regression — the sigmoid reflection identity

Background

The sigmoid is point-symmetric about (0,0.5)(0,\,0.5). Reflecting the score flips the probability to its complement:

σ(z)=1σ(z),σ(0)=0.5\sigma(-z) = 1 - \sigma(z), \qquad \sigma(0) = 0.5

This is exactly why P(y=0x)=1σ(z)=σ(z)\mathbb{P}(y=0\mid\mathbf{x}) = 1 - \sigma(z) = \sigma(-z): negating the logit gives you the other class's probability. The curve's centre at z=0z=0 is the 0.5 decision threshold.

Problem statement

Implement sigmoid_reflection(z) that returns σ(z)\sigma(-z) for each value in z.

Input

  • z — array-like of real-valued scores (logits).

Output

Returns an np.ndarray the same length as z, where element ii is σ(zi)=11+ezi\sigma(-z_i) = \dfrac{1}{1 + e^{z_i}}.

Examples

Example 1

Input:  z = [0, 2, -3]
Output: [0.5        0.11920292 0.95257413]

Explanation: σ(0)=0.5\sigma(-0)=0.5; σ(2)=1σ(2)0.1192\sigma(-2)=1-\sigma(2)\approx0.1192; σ(3)=1σ(3)0.9526\sigma(3)=1-\sigma(-3)\approx0.9526.

Example 2

Input:  z = [0]
Output: [0.5]

Explanation: the symmetry centre — σ(0)=0.5\sigma(0)=0.5 and σ(0)=0.5\sigma(-0)=0.5 agree.

Constraints

  • Return σ(z)\sigma(-z), which must equal 1σ(z)1 - \sigma(z) elementwise.
  • Vectorise over z; no Python loop.

Notes

  • Reading σ(z)\sigma(-z) as P(y=0)\mathbb{P}(y=0) is the bridge from last lesson's complement rule to this lesson's sigmoid — one identity ties them together.
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.

  • Reference values
  • Sample mixed scores
  • Worked example single positive