Logistic regression — when a linear score isn't a probability
Background
A linear model outputs a raw score that can be any real number — , , or . That is fine for "dollars", but a class probability must live in . This mismatch is the core reason plain linear regression fails at classification, and the whole motivation for the sigmoid that follows.
Problem statement
Implement valid_probabilities(scores) that returns a boolean mask flagging which raw scores are already in the valid probability range (inclusive).
Input
scores— array-like of real-valued linear-model outputs.
Output
Returns a boolean np.ndarray the same length as scores: True where , else False.
Examples
Example 1
Input: scores = [5, -0.3, 0.6, 0.4, 1.0, 3.14159]
Output: [False False True True True False]
Explanation: only , , and are usable as probabilities; , , and escape — exactly the failure the lesson highlights.
Example 2
Input: scores = [0.0, 1.0]
Output: [ True True]
Explanation: the endpoints and are valid probabilities (the check is inclusive).
Constraints
- Treat the range as inclusive on both ends: and count as valid.
- Convert
scoresto a NumPy array and build the mask with a single vectorised comparison — no Python loop.
Notes
- This is the diagnostic that motivates logistic regression: a linear score is unbounded, so we need a squashing function (the sigmoid) to guarantee every output lands in .
▶ 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 scores
- •Sample with a large value
- •Example endpoints and beyond