#161Binary output head — probability and decisionEasyLogistic RegressionNeural NetworksActivation Functions
Binary output head — probability and decision
Background
For binary classification the network sets o = 1, so the single sigmoid output reads directly as . From that one number you get everything the head needs:
Problem statement
Implement binary_head(a2) returning the tuple (p0, p1, label) for a single scalar output activation.
Input
a2—floatin , 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 (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