Forecasting Next-Day Energy Use Across Commercial Buildings
Machine LearningModel answerLast updated
Design a full forecasting pipeline for next-day electricity use across many commercial buildings, from features and validation through deployment, monitoring, privacy and an ablation study.
You are asked to design a complete machine learning system that predicts, for each commercial building in a portfolio, the total electricity consumed (in kWh) on the following day.
Data you can use
- Hourly smart-meter readings per building.
- Weather: temperature, humidity and wind.
- Calendar information, including holidays.
- Building metadata: floor area, year built, HVAC type.
- Optional external signals: day-ahead electricity price and outage alerts.
- History spans 2019 to 2025.
Walk through the following in your answer
- Define the prediction problem precisely and propose baseline models.
- Describe the features you would build for seasonality, interactions (for example temperature with HVAC type) and occupancy proxies.
- Explain how you would regularize the model, handle multicollinearity, and detect and reduce heteroscedasticity.
- Describe time-series-aware cross-validation and how you prevent leakage. Be explicit about any lag or rolling-window features and which days they may touch.
- Choose evaluation metrics (such as RMSE and MAPE) and translate them into business-facing service levels, such as billing tolerance bands.
- Explain how you handle missing or corrupted sensor data and concept drift across the years.
- Outline production training and inference pipelines, model versioning, and monitoring (data and feature drift, residual shifts, retraining triggers).
- Explain how you would make predictions understandable to non-ML stakeholders (global and per-prediction views) and how the system fails safely.
- State the security and privacy measures required for tenant data.
Finally, propose an ablation plan that measures the added value of the external features, and describe how you would backtest the whole pipeline on 2023 to 2024 while keeping 2025 untouched as a final holdout.
Hints
Hint 1
Start by fixing the forecast cutoff time. Whether yesterday's meter data is complete when you run decides the smallest legal lag and which weather inputs (forecast vs. observed) are allowed.
Hint 2
Use a simple, industry-standard baseline (seasonal naive and a per-building degree-day model) and a size-normalized, log-scaled target so one global model can serve buildings of very different sizes.
Hint 3
For validation, use rolling-origin splits with a gap at least as long as the horizon plus the longest lag, fit all transformations inside each fold, and join weather forecasts and metadata as of the forecast time. For the ablation, keep everything fixed except the feature group under test.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Model answer
1. Framing and scope
Clarify first: the forecast is day-ahead, issued each morning (say 06:00 on day D) for day D+1. Consumers are billing and budgeting, procurement and facility managers. This choice fixes which features are legal.
Assume about 5,000 buildings and 7 years of data. Hourly data is roughly 300M rows. The daily training table is roughly 13M rows. That fits on one machine with gradient boosting. Inference is a daily batch of 5,000 predictions, so latency is irrelevant; correctness and on-time delivery matter.
Output per building: median, p10 and p90 forecasts, top drivers, model version, a fallback flag and data-quality flags.
2. Target and baselines
- Target:
log(kWh / area), back-transformed with a smearing correction to avoid bias. This makes buildings comparable and stabilizes variance across sizes. - Baselines:
- Seasonal naive (same weekday last week).
- Per-building degree-day change-point regression (heating and cooling degree days with a fitted balance point). This is also the production fallback.
- Global elastic net.
- Main model: global gradient-boosted trees with quantile objectives (p10, p50, p90) and monotone constraints on cooling degree days.
3. Features
Everything is computed as of the cutoff.
- Seasonality: day of week, holiday and bridge-day flags, annual Fourier terms (k = 1 to 3), daylight hours, school-term flags.
- Weather: use the forecast issued before the cutoff, not observed values. Add HDD/CDD at several balance points, dew point or enthalpy for latent cooling, and wind-by-temperature for infiltration.
- Interactions: CDD by HVAC type, HDD by vintage, holiday by building use. Trees find many of these themselves, but explicit terms make the linear baselines competitive.
- Occupancy proxies from lagged hourly data: overnight baseload (median 01:00 to 04:00 over 28 days), peak-to-base ratio, weekday/weekend ratio, morning ramp-up hour.
- Lags and rolling windows: at 06:00 on day D, day D is incomplete, so the latest complete day is D-1 and the minimum lag for a D+1 target is 2 days. Use
lag_2,lag_7,lag_14,lag_364(weekday-aligned), and rolling means built asshift(2).rolling(w)so windows end at the last complete day.
4. Regularization, collinearity, heteroscedasticity
- Collinearity: temperature, degree days, dew point and Fourier terms overlap heavily. Diagnose with VIF and condition number. Use ridge or elastic net (tuned inside time-series CV), and drop redundant raw features. For boosted trees, collinearity hurts interpretability more than accuracy, so report grouped SHAP.
- Heteroscedasticity: variance grows with building size and at temperature extremes. Detect with residual-vs-fitted and residual-vs-temperature plots and a Breusch-Pagan test. Mitigate with the log/area target, weighted least squares for the linear baseline, and quantile models so intervals widen where they should.
5. Validation and leakage control
- Rolling-origin, expanding window with monthly origins and a gap of at least horizon plus longest lag between train end and validation start.
- Grouped-by-building split as a second scheme to measure cold-start accuracy on new sites.
- Leakage controls: fit imputers, scalers, target encodings and balance points within folds only; use point-in-time joins for weather forecasts and metadata (do not use a retrofit the business did not yet know about); no realized weather, price or outage alerts issued after the cutoff; drop corrupted days from training targets.
6. Metrics and service levels
- RMSE in kWh, reported by size tier because large sites dominate it.
- MAPE is unstable near zero load (holidays, vacancies), so also report WAPE and CV(RMSE).
- NMBE (bias) matters most for billing.
- Interval coverage: p10 to p90 should cover about 80%.
- Example SLAs: monthly totals within ±5% for 95% of sites (in line with ASHRAE Guideline 14: monthly CV(RMSE) ≤ 15%, NMBE within ±5%); daily error within ±10% for 90% of site-days; forecast published by 07:00 with at least 99.5% availability.
7. Bad data and drift
- Hourly quality rules: flatlines over 6 hours, negative values, spikes beyond about 5 robust z-scores, counter resets, duplicate or DST-shifted timestamps.
- Daily handling: interpolate gaps up to 2 hours; if more than about 4 hours are missing, the day is invalid as a target, and features fall back to longer windows with a missingness indicator.
- Drift: the 2020 to 2021 occupancy collapse gets a regime feature or down-weighting. Retrofits are caught with per-building change-point detection (CUSUM on residuals) and trigger a refit or reset of building features. Slow efficiency trends are handled with exponential time-decay weights.
8. Production
- Pipeline: ingestion with data-quality checks, then a feature store with point-in-time correctness and shared offline/online code, then weekly retraining (monthly hyperparameter refresh). A candidate is evaluated against the baselines and the current champion on the last 8 weeks, registered with data and code versions, and promoted only if it wins. Run shadow mode and canary before full rollout; keep rollback one step away.
- Monitoring: input freshness and schema, feature drift (PSI or KS), residual mean and spread, coverage, per-building error. Retraining triggers: sustained bias or drift beyond thresholds, a detected change point, or a calendar schedule.
- Explainability: globally, grouped SHAP and partial-dependence plots on temperature and occupancy; locally, "tomorrow is +4 kWh/m² because of forecast heat and a weekday" style reasons. Compare each building to its own degree-day curve in plain language.
- Safe failure: if inputs are stale or the model is out of range, serve the degree-day fallback with
fallback_used=true; widen intervals; never publish silently wrong numbers.
9. Security and privacy
Tenant-level consumption can reveal occupancy patterns. Use encryption in transit and at rest, role-based access, tenant-level isolation, pseudonymous site IDs in the feature store, audit logs, retention limits, and aggregate-only exposure to anyone outside the owning tenant. Consider noise or minimum-aggregation rules for any shared reports.
10. Ablation and backtest plan
- Backtest: run the full pipeline (feature generation, training, calibration, thresholds) in rolling-origin fashion across 2023 to 2024, retraining on the production cadence. Tune everything only on data before each origin. Touch 2025 once, at the end, with the frozen configuration.
- Ablation: hold model class, hyperparameter budget and splits fixed. Compare (a) no external features, (b) plus price, (c) plus outage alerts, (d) both. Re-tune each variant equally. Report the change in WAPE, NMBE and coverage with paired bootstrap confidence intervals over buildings and weeks, broken out by size tier and season, and in particular on extreme days where price or outages should matter. Also confirm the features would have been available at the cutoff. Keep a feature only if the gain exceeds its cost and operational risk.
Common mistakes
- Using observed instead of forecast weather, or lag-1 features that are not yet complete at the cutoff.
- Random K-fold splits on time series.
- Reporting only MAPE or only aggregate RMSE.
- Letting the COVID period distort the recent fit.
- Tuning on the final holdout.