Odds Ratio for a k-Unit Change in a Logistic Regression Feature
Quick Overview
Write a Python function that turns a logistic regression coefficient into the odds ratio for a change of k units in the feature. Tests how log-odds coefficients map to multiplicative effects on the odds, negative and zero changes, and the interval and interpretation questions that follow.
Odds Ratio for a k-Unit Change in a Logistic Regression Feature
Role: Data Scientist
Category: Machine Learning
Difficulty: easy
Interview Round: Other
A logistic regression model has log-odds coefficient `coef` for a numeric feature. Implement `odds_ratio_for_k_units(coef: float, k: float) -> float`, which returns the odds ratio for a change of `k` units in that feature: the odds after the change divided by the odds before it, with every other feature held fixed.
Requirements:
- Return a plain Python float.
- Handle negative `k`: the result for `-k` is the reciprocal of the result for `k`.
- Return exactly `1.0` when `k == 0`.
Examples (results should match to a relative tolerance of `1e-9`):
```python
odds_ratio_for_k_units(0.156, 10.0) # 4.7588...
odds_ratio_for_k_units(0.156, 1.0) # 1.1688...
odds_ratio_for_k_units(0.5, -2.0) # 0.3678...
odds_ratio_for_k_units(0.9, 0.0) # 1.0
```
```hint Pick the scale first
The model is linear on one scale and multiplicative on another. Work out what a `k`-unit change does on the linear scale before you move to the odds.
```
### What a Strong Answer Covers
- The change in log-odds produced by a `k`-unit shift and how it turns into a factor on the odds.
- Why `k = 0` and negative `k` behave as required.
- The common mistake of scaling the one-unit odds ratio linearly, and why it is wrong.
- The assumption behind a single number: the feature enters the model linearly, with no interactions.
### Follow-up Questions
- How would you convert this odds ratio into a confidence interval for the `k`-unit change?
- Why is the odds ratio for `k` units the same regardless of the feature's starting value, when the change in probability is not?
- If the feature was standardized before fitting, how do you get the odds ratio for `k` units on the original scale?
Overview: Write a Python function that turns a logistic regression coefficient into the odds ratio for a change of k units in the feature. Tests how log-odds coefficients map to multiplicative effects on the odds, negative and zero changes, and the interval and interpretation questions that follow.
Odds Ratio for a k-Unit Change in a Logistic Regression Feature
General
Nov 25, 2026
easyData ScientistOtherMachine Learning
0
0
A logistic regression model has log-odds coefficient coef for a numeric feature. Implement odds_ratio_for_k_units(coef: float, k: float) -> float, which returns the odds ratio for a change of k units in that feature: the odds after the change divided by the odds before it, with every other feature held fixed.
Requirements:
Return a plain Python float.
Handle negative
k
: the result for
-k
is the reciprocal of the result for
k
.
Return exactly
1.0
when
k == 0
.
Examples (results should match to a relative tolerance of 1e-9):