#313Logistic regression — when a linear score isn't a probabilityEasy

Logistic regression — when a linear score isn't a probability

Background

A linear model outputs a raw score y^=wx+b\hat{y} = \mathbf{w}^\top \mathbf{x} + b that can be any real number — 55, 0.3-0.3, or π\pi. That is fine for "dollars", but a class probability must live in [0,1][0, 1]. 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 [0,1][0, 1] (inclusive).

Input

  • scores — array-like of real-valued linear-model outputs.

Output

Returns a boolean np.ndarray the same length as scores: True where 0score10 \le \text{score} \le 1, 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 0.60.6, 0.40.4, and 1.01.0 are usable as probabilities; 55, 0.3-0.3, and π\pi escape [0,1][0, 1] — exactly the failure the lesson highlights.

Example 2

Input:  scores = [0.0, 1.0]
Output: [ True  True]

Explanation: the endpoints 00 and 11 are valid probabilities (the check is inclusive).

Constraints

  • Treat the range as inclusive on both ends: 00 and 11 count as valid.
  • Convert scores to 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 [0,1][0, 1].
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 scores
  • Sample with a large value
  • Example endpoints and beyond