Use a Fitted Line to Predict a Future Data Point
Company: Amazon
Role: Software Engineer
Category: Machine Learning
Difficulty: hard
Interview Round: Technical Screen
# Use a Fitted Line to Predict a Future Data Point
You receive observed points `(x_i, y_i)` and need to predict `y` for a future input `x_future`. Assume a provided helper fits ordinary least squares and returns a slope `m` and intercept `b`; you do not need to implement the fitting routine.
Explain how you would use the returned parameters, validate that the result is meaningful, and handle cases where a straight-line extrapolation is unsafe. Include how you would evaluate predictions without leaking future information.
### Constraints & Assumptions
- Inputs and fitted parameters are finite numeric values.
- `x_future` may lie outside the observed range.
- The points may be ordered in time, but time dependence is not guaranteed; clarify it.
- The helper's fitting behavior for degenerate inputs must be defined or checked.
### Clarifying Questions to Ask
- Is `x` time, and are observations equally spaced?
- Is the goal one-step prediction, long-horizon extrapolation, or both?
- Are there trends, seasonality, outliers, or regime changes?
- What error metric and uncertainty information does the consumer need?
### What a Strong Answer Covers
- The prediction formula and unit interpretation
- Residual checks and a time-appropriate evaluation split
- Extrapolation risk and degenerate data
- Uncertainty and communication of model limitations
- A decision rule for when a richer model is justified
### Follow-up Questions
- What if every observed `x` value is identical?
- Why is a random train-test split risky for time-ordered data?
- How would one extreme point affect the fitted line?
- What evidence would support adding seasonal or nonlinear terms?
Quick Answer: Use a fitted line's slope and intercept to predict a future value, then assess whether that extrapolation is meaningful. The question covers units, degenerate inputs, residuals, time-aware evaluation without future leakage, uncertainty, outliers, regime changes, and signals that call for a richer model.