#314Logistic regression — two-class probabilitiesEasyLinear RegressionLogistic Regression
Logistic regression — two-class probabilities
Background
In binary classification the model predicts . Because there are only two classes, the other probability is fixed by it:
The two probabilities are non-negative and sum to 1 — exactly the / bars in the lesson. One number determines both.
Problem statement
Implement class_probabilities(p1) that, given , returns the pair .
Input
p1—floatin , 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 forces class 0 at .
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
p1is already a valid probability in .
Notes
- This complement rule is why binary logistic regression needs only a single sigmoid output: predict 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