Convert a Logistic Regression Intercept to Baseline Odds and Probability
Quick Overview
Convert a logistic regression intercept into the baseline odds and baseline probability with a small Python function. It tests reading the intercept as a log-odds, the link between odds and probability, and numerically stable sigmoid code.
Convert a Logistic Regression Intercept to Baseline Odds and Probability
Role: Data Scientist
Category: Machine Learning
Difficulty: easy
Interview Round: Other
Write `intercept_baseline(intercept: float) -> tuple[float, float]` that converts a logistic-regression intercept (the log-odds when all predictors are 0) into the baseline odds and the baseline probability.
- The odds are `exp(intercept)`, and the probability is `exp(intercept) / (1 + exp(intercept))` (the sigmoid of the intercept).
- Return the tuple in exactly the order `(odds, probability)`.
- Return plain Python `float` values, not NumPy scalars.
Examples:
```python
intercept_baseline(-1.12546) # -> (0.32450..., 0.245) odds 49/151, probability 49/200
intercept_baseline(0.0) # -> (1.0, 0.5)
intercept_baseline(2.0) # -> (7.38905..., 0.88079...)
```
```hint Watch types and overflow
Check what type `np.exp` returns for a Python float, and what `exp(x) / (1 + exp(x))` evaluates to when x is a large positive number.
```
### Constraints & Assumptions
- `intercept` is a finite float.
- Each returned value is compared with the expected one at a relative tolerance of 1e-5.
### What a Strong Answer Covers
- Why the intercept is the log-odds of the positive class when every predictor is 0.
- Both conversions, and how odds and probability relate to each other.
- Plain Python floats returned in the required order.
- How the computation behaves for large positive or negative intercepts.
### Follow-up Questions
- How would you convert a slope coefficient into an odds ratio, and how would you read it?
- Why compute the probability with a numerically stable sigmoid, and what does a stable version look like?
- If the predictors were standardized before fitting, what would the baseline odds and probability describe?
Overview: Convert a logistic regression intercept into the baseline odds and baseline probability with a small Python function. It tests reading the intercept as a log-odds, the link between odds and probability, and numerically stable sigmoid code.
Convert a Logistic Regression Intercept to Baseline Odds and Probability
General
Nov 24, 2026
easyData ScientistOtherMachine Learning
0
0
Write intercept_baseline(intercept: float) -> tuple[float, float] that converts a logistic-regression intercept (the log-odds when all predictors are 0) into the baseline odds and the baseline probability.
The odds are
exp(intercept)
, and the probability is
exp(intercept) / (1 + exp(intercept))
(the sigmoid of the intercept).
Return the tuple in exactly the order
(odds, probability)
.
Return plain Python
float
values, not NumPy scalars.