#311Logistic regression — probability from a scoreEasyLinear RegressionLogistic RegressionActivation Functions
Logistic regression — probability from a score
Background
Logistic regression turns a linear score (the logit) into a probability with the sigmoid:
The linear part is the same you met in linear regression; the sigmoid is the only new piece, and it guarantees the output lands in so it can be read as a probability.
Problem statement
Implement predict_proba(x, w, b) that returns for a single sample.
Input
x— array-like feature vector of length .w— array-like weight vector of length .b—float, the bias.
Output
Returns a Python float in : the predicted probability of class 1.
Examples
Example 1 — a zero score is a coin flip
Input: x = [0, 0], w = [1, 1], b = 0
Output: 0.5
Explanation: , and — exactly the toss-up point.
Example 2 — a positive score leans toward class 1
Input: x = [1, 1], w = [1, 2], b = -1
Output: 0.8807970779...
Explanation: , and .
Constraints
- Compute the dot product , add
b, then apply the sigmoid. - Return a plain
float.
Notes
- This is the entire logistic-regression forward pass for one example. Stacking many samples just turns the dot product into a matrix multiply .
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 — a zero score is a coin flip
- •Reference — score z = 2 -> sigmoid(2)
- •Sample — score z = -3 -> sigmoid(-3)