#161Binary output head — probability and decisionEasy

Binary output head — probability and decision

Background

For binary classification the network sets o = 1, so the single sigmoid output a2(0,1)a_2 \in (0,1) reads directly as P(class 1)\mathbb{P}(\text{class }1). From that one number you get everything the head needs:

P(1)=a2,P(0)=1a2,y^={1a2>0.50a20.5\mathbb{P}(1) = a_2, \qquad \mathbb{P}(0) = 1 - a_2, \qquad \hat{y} = \begin{cases}1 & a_2 > 0.5\\ 0 & a_2 \le 0.5\end{cases}

Problem statement

Implement binary_head(a2) returning the tuple (p0, p1, label) for a single scalar output activation.

Input

  • a2float in (0,1)(0, 1), the sigmoid output (probability of class 1).

Output

Returns (p0, p1, label): p0 = 1 - a2 (float), p1 = a2 (float), label = 1 if a2 > 0.5 else 0 (int).

Examples

Example 1

Input:  a2 = 0.7
Output: (0.3, 0.7, 1)

Example 2 — exactly 0.5 decides class 0

Input:  a2 = 0.5
Output: (0.5, 0.5, 0)

Explanation: the rule is a2>0.5a_2 > 0.5 (strict), so a tie goes to class 0.

Constraints

  • p0 = 1 - a2, p1 = a2, both floats.
  • label = int(a2 > 0.5).
  • Return them in the order (p0, p1, label).

Notes

  • The 0.5 threshold is the neutral default; shifting it trades precision against recall without retraining the network.
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 a2=0.7 -> confident class 1
  • Reference tie a2=0.5 decides class 0
  • Sample a2=0.1 -> class 0 with p0=0.9