Convert a Logistic Regression Coefficient to Percent Change in Odds
Quick Overview
Write a Python function that turns a logistic regression coefficient into the percent change in the odds of the positive class for a one-unit increase in a feature. Tests reading log-odds coefficients, the sign and zero cases, and the gap between changes in odds and changes in probability.
Convert a Logistic Regression Coefficient to Percent Change in Odds
Role: Data Scientist
Category: Machine Learning
Difficulty: easy
Interview Round: Other
Write `percent_change_in_odds(coef: float) -> float` that converts a logistic-regression coefficient (log-odds scale) into the percent change in the odds of the positive class for a one-unit increase in that feature, with all other features held fixed.
Requirements:
- A negative coefficient yields a negative percent, and `coef=0.0` returns exactly `0.0`.
- Return a plain Python `float`, not a NumPy scalar.
Examples (fixed inputs are checked to a relative tolerance of `1e-9`):
```python
percent_change_in_odds(0.156) # about 16.88
percent_change_in_odds(0.0) # 0.0
percent_change_in_odds(-0.6931471805599453) # about -50.0, the odds halve
percent_change_in_odds(0.6931471805599453) # about 100.0, the odds double
```
```hint From coefficient to factor
First find the factor by which a one-unit increase multiplies the odds. A percent change is a statement about how far that factor is from 1.
```
### What a Strong Answer Covers
- How a log-odds coefficient becomes a multiplicative factor on the odds.
- The conversion from that factor to a percent change, including the sign and the zero case.
- Why equal and opposite coefficients give percent changes of different sizes.
- The difference between a change in the odds and a change in the probability.
### Follow-up Questions
- How does this change for a coefficient interpreted per standard deviation instead of per unit?
- How would you report a confidence interval for the percent change?
- When is the percent change in odds close to the percent change in probability?
Overview: Write a Python function that turns a logistic regression coefficient into the percent change in the odds of the positive class for a one-unit increase in a feature. Tests reading log-odds coefficients, the sign and zero cases, and the gap between changes in odds and changes in probability.
Convert a Logistic Regression Coefficient to Percent Change in Odds
General
Nov 25, 2026
easyData ScientistOtherMachine Learning
0
0
Write percent_change_in_odds(coef: float) -> float that converts a logistic-regression coefficient (log-odds scale) into the percent change in the odds of the positive class for a one-unit increase in that feature, with all other features held fixed.
Requirements:
A negative coefficient yields a negative percent, and
coef=0.0
returns exactly
0.0
.
Return a plain Python
float
, not a NumPy scalar.
Examples (fixed inputs are checked to a relative tolerance of 1e-9):
percent_change_in_odds(0.156) # about 16.88
percent_change_in_odds(0.0) # 0.0
percent_change_in_odds(-0.6931471805599453) # about -50.0, the odds halve
percent_change_in_odds(0.6931471805599453) # about 100.0, the odds double
What a Strong Answer Covers Guidance
How a log-odds coefficient becomes a multiplicative factor on the odds.
The conversion from that factor to a percent change, including the sign and the zero case.
Why equal and opposite coefficients give percent changes of different sizes.
The difference between a change in the odds and a change in the probability.
Follow-up Questions Guidance
How does this change for a coefficient interpreted per standard deviation instead of per unit?
How would you report a confidence interval for the percent change?
When is the percent change in odds close to the percent change in probability?