πŸŽ‰ 75% of content is free forever β€” Unlock Premium from $10/mo β†’
CW
Search courses…
πŸ’Ό Servicesℹ️ Aboutβœ‰οΈ ContactView Pricing Plansfrom $10

Time Series: ARIMA, LSTM, Prophet & Stationarity

Machine LearningTime Series⭐ Premium

Advertisement

Amazon & Uber Interview

Time Series: ARIMA, LSTM, Prophet & Stationarity

Forecasting the future from the past

Interview Question

"Explain the concept of stationarity in time series. What is ARIMA and how does it handle non-stationary data? Compare ARIMA with LSTM for time series forecasting."

Difficulty: Hard | Frequently asked at Amazon, Uber, Google


Theoretical Foundation

Stationarity

A time series is stationary if its statistical properties don't change over time:

  • Constant mean: E[Xt]=ΞΌE[X_t] = \mu
  • Constant variance: Var(Xt)=Οƒ2\text{Var}(X_t) = \sigma^2
  • Constant autocovariance: Cov(Xt,Xt+k)=Ξ³(k)\text{Cov}(X_t, X_{t+k}) = \gamma(k)

Why stationarity matters: Most time series models assume stationarity.

Making Non-Stationary Data Stationary

  1. Differencing: Yt=Xtβˆ’Xtβˆ’1Y_t = X_t - X_{t-1} (first order)
  2. Log transform: Stabilizes variance
  3. Seasonal differencing: Yt=Xtβˆ’Xtβˆ’sY_t = X_t - X_{t-s}

ARIMA (AutoRegressive Integrated Moving Average)

Components:

  • AR(p): AutoRegressive - depends on past values
  • I(d): Integrated - differencing order
  • MA(q): Moving Average - depends on past errors

Model:

Xt=c+βˆ‘i=1pΟ•iXtβˆ’i+βˆ‘j=1qΞΈjΟ΅tβˆ’j+Ο΅tX_t = c + \sum_{i=1}^{p} \phi_i X_{t-i} + \sum_{j=1}^{q} \theta_j \epsilon_{t-j} + \epsilon_t

Parameters:

  • pp: Number of AR terms
  • dd: Number of differences
  • qq: Number of MA terms

ARIMA vs LSTM Comparison

AspectARIMALSTM
AssumptionsLinear, stationaryNone (learns patterns)
FeaturesUnivariate onlyMultivariate
Non-linearNoYes
Data RequiredLessMore
InterpretabilityHighLow
ComputationFastSlow
Long-term DependenciesLimitedCaptures well

Facebook Prophet

Model: Additive decomposition:

y(t)=g(t)+s(t)+h(t)+Ο΅ty(t) = g(t) + s(t) + h(t) + \epsilon_t
  • g(t)g(t): Trend (piecewise linear or logistic)
  • s(t)s(t): Seasonality (Fourier series)
  • h(t)h(t): Holidays and events

Properties:

  • Handles missing data
  • Robust to outliers
  • Interpretable components
  • Automatic changepoint detection

ℹ️

Key Insight: ARIMA works well for short-term forecasts of stationary linear processes. LSTM excels when there are complex non-linear patterns and sufficient data. Prophet is great for business time series with known seasonal patterns.


Code Implementation


Real-World Applications

Amazon: Demand Forecasting

  • Inventory Management: Predicting product demand
  • Supply Chain: Forecasting logistics requirements
  • Pricing: Dynamic pricing based on demand patterns

Uber: Ride Demand Prediction

  • ETA Prediction: Forecasting arrival times
  • Surge Pricing: Predicting demand spikes
  • Driver Allocation: Matching supply with demand

πŸ’‘

Amazon Interview Tip: Be prepared to discuss handling multiple seasonalities (daily, weekly, yearly) and the importance of feature engineering in time series.


Common Follow-Up Questions

Q1: How do you choose p, d, q for ARIMA? Use ACF/PACF plots, information criteria (AIC/BIC), or auto-ARIMA. d is determined by differencing until stationary.

Q2: When does LSTM outperform ARIMA? When there are complex non-linear patterns, multiple input features, or long-term dependencies that ARIMA cannot capture.

Q3: How do you handle missing values in time series? Forward fill, interpolation, or model-based imputation. Some models (Prophet) handle missing data natively.

Q4: What is the difference between time series regression and forecasting? Forecasting predicts future values using only past values. Time series regression uses external features (weather, events) to predict the target.


Related Topics

Advertisement