#314Logistic regression — two-class probabilitiesEasy

Logistic regression — two-class probabilities

Background

In binary classification the model predicts P(y=1x)\mathbb{P}(y=1 \mid \mathbf{x}). Because there are only two classes, the other probability is fixed by it:

P(y=0x)=1P(y=1x)\mathbb{P}(y=0 \mid \mathbf{x}) = 1 - \mathbb{P}(y=1 \mid \mathbf{x})

The two probabilities are non-negative and sum to 1 — exactly the P=0.4P=0.4 / P=0.6P=0.6 bars in the lesson. One number determines both.

Problem statement

Implement class_probabilities(p1) that, given p1=P(y=1x)p_1 = \mathbb{P}(y=1 \mid \mathbf{x}), returns the pair (P(y=0),P(y=1))(\mathbb{P}(y=0), \mathbb{P}(y=1)).

Input

  • p1float in [0,1][0, 1], the probability of class 1.

Output

Returns a tuple of two Python floats (p0, p1) where p0 = 1 - p1. They sum to 1.

Examples

Example 1

Input:  p1 = 0.6
Output: (0.4, 0.6)

Explanation: the lesson's bars — class 1 at 0.60.6 forces class 0 at 10.6=0.41-0.6=0.4.

Example 2

Input:  p1 = 1.0
Output: (0.0, 1.0)

Explanation: full confidence in class 1 leaves zero for class 0.

Constraints

  • Return plain Python floats in the order (p0, p1).
  • Do not clamp or renormalise — assume p1 is already a valid probability in [0,1][0, 1].

Notes

  • This complement rule is why binary logistic regression needs only a single sigmoid output: predict P(y=1)\mathbb{P}(y=1) and the rest follows. The multi-class generalisation that produces a whole vector summing to 1 is the softmax.
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 lesson bars
  • Sample certain class one
  • Example low probability