• No products in the cart.

How to Train a Machine Learning Model to Forecast Electric Load: A Hands-On Guide with Free Colab Lab

Every morning, someone at your utility answers the same question: how much power will this system need tomorrow, hour by hour? Unit commitment, power purchases, battery dispatch, switching plans and demand response all start from that number. At a 40 MW substation, a 3% forecast error is 1.2 MW. A 7.5% error is 3 MW, about the size of a large commercial customer you did not plan for.

In this article you will learn how a machine learning load forecast works, from the physics of why load follows temperature to the way a gradient-boosted model learns it. Then you will train one yourself. Our free hands-on kit contains a Google Colab notebook, two years of hourly substation data and an Excel lab, with the expected output at every step so you can check your work.

What you will get

  • A clear picture of the four drivers of electric load and how to turn them into model inputs
  • Three models compared on a full year they have never seen: 7.5% → 5.7% → 3.2% error
  • The mistakes that make a forecast look great in testing and fail in operation
  • A free download: Colab notebook, CSV data, Excel workbook and expected results

Jump to the free lab kit

1. Forecast horizons: which forecast are we building?

“Load forecasting” covers very different jobs. The inputs, the methods and the acceptable error all change with the horizon.

Horizon Lead time Typical uses Main inputs
Very short-term Minutes to 1 hour Real-time dispatch, regulation, battery control Latest measured load, trend
Short-term (day-ahead) 1 to 7 days Unit commitment, energy purchases, switching and outage plans, demand response Weather forecast, calendar, recent load
Medium-term Weeks to 1 year Maintenance scheduling, fuel and contract planning Seasonal weather, economic activity
Long-term 1 to 20 years Substation and feeder capacity, DER hosting, IRP studies Customer growth, electrification, DER and EV adoption

This article builds the most common one in operations: an hourly, day-ahead forecast for one substation.

2. What drives electric load

Before any algorithm, an engineer should know what the model needs to learn. Four drivers explain most of the load on a typical distribution substation:

  1. Weather. Temperature above all, then humidity, cloud cover and wind. Heating and cooling equipment respond to it.
  2. Calendar. Hour of day, day of week, holidays. People wake up, go to work and come home on a schedule.
  3. Thermal memory. Buildings heat up and cool down slowly. The third day of a heat wave draws more than the first day at the same temperature.
  4. Growth and structural change. New customers, electrification, rooftop PV, EV charging. Our example substation grows about 2.5% per year.

Plot two years of hourly load against temperature and the first driver appears immediately: the classic hockey-stick curve.

Scatter plot of hourly substation load versus air temperature showing a hockey-stick shape: load rises slowly below 15 deg C and steeply above 18 deg C
Figure 1. Hourly load vs temperature for the lab substation (2024 and 2025). The flat zone between about 15 and 18 °C is the balance point where neither heating nor cooling runs.

Engineers turn this curve into two simple inputs:

Cooling degree-hours: CDH = max(T − Tcool, 0)

Heating degree-hours: HDH = max(Theat − T, 0)

With Tcool = 18 °C and T = 32 °C: CDH = max(32 − 18, 0) = 14. With Theat = 15 °C and T = −3 °C: HDH = max(15 − (−3), 0) = 18. On a mild 16 °C hour both are zero.

3. How a model “learns” a load forecast

Machine learning for forecasting is supervised learning: we show the model many examples of inputs (the features: hour, temperature, day type and so on) together with the answer (the target: the load that actually happened). Training means adjusting the model’s internal parameters until its predictions on those examples are as close as possible to the answers.

The simplest learner is a regression line, and it already gives you engineering numbers you can check. Our Excel lab fits the daily peak of the example substation on 2024 data:

General form: Peak = a + b × CDD + c × HDD + d × OffDay

Fitted on 2024: Peak = 17.78 + 1.128 × CDD + 0.398 × HDD − 1.45 × OffDay  (MW, R² = 0.961)

Worked example 1, summer Thursday, Tmax = 31 °C (cooling base 18 °C):

CDD = 31 − 18 = 13  →  Peak = 17.78 + 1.128 × 13 = 17.78 + 14.66 = 32.4 MW

Worked example 2, winter Monday, Tmean = −3 °C (heating base 15 °C):

HDD = 15 − (−3) = 18  →  Peak = 17.78 + 0.398 × 18 = 17.78 + 7.16 = 24.9 MW

Reading the coefficients: each degree of daily maximum above 18 °C adds about 1.13 MW of air-conditioning peak. Each degree of cold adds only 0.40 MW, which suggests most buildings on this substation heat with gas or oil. Weekends and holidays peak 1.45 MW lower.

A regression line is transparent but rigid: you must tell it every shape and interaction. Modern machine learning models such as XGBoost discover them from the data.

Gradient boosting in four numbers

XGBoost (eXtreme Gradient Boosting) builds hundreds of small decision trees, one after another. Each new tree does not predict the load directly: it predicts the error that the trees before it still make. A tiny example with four hours of actual load: 14, 18, 30 and 34 MW.

Step Hour 1 (cool) Hour 2 (cool) Hour 3 (hot) Hour 4 (hot)
Actual load 14 18 30 34
Start: predict the average 24 24 24 24
Error left (actual − prediction) −10 −6 +6 +10
Tree 1 splits on “temperature > 20 °C”, predicts the error: −8 / +8 −8 −8 +8 +8
New prediction = 24 + 0.5 × tree 1 (learning rate 0.5) 20 20 28 28
Error left −6 −2 +2 +6

The total absolute error fell from 32 MW to 16 MW after one tree. Tree 2 would split on another feature (perhaps hour of day) to attack the remaining −6 and +6, and so on for 600 trees. The small learning rate makes each tree correct only part of the error, which keeps the model from memorizing noise.

4. The workflow, step by step

Six-step machine learning load forecasting workflow: define the question, collect data, engineer features, split by time, train and compare with a baseline, evaluate MAPE and peak error
Figure 2. The six steps you will follow in the lab.
  1. Define the question. Hourly load for each hour of tomorrow, issued the day before.
  2. Collect the data. Hourly load (SCADA or AMI aggregate), hourly temperature from the nearest weather station, a holiday calendar.
  3. Engineer the features. Hour, day of week, month, weekend/holiday flag, temperature, temperature 3 hours earlier, 24-hour average temperature, load at the same hour last week.
  4. Split by time. Train on 2024, test on 2025. Never shuffle a time series: the model must be graded on a future it has not seen.
  5. Train and compare with a baseline. A model that cannot beat “same hour last week” adds nothing.
  6. Evaluate. Average error (MAPE, MAE) and, separately, the error at the peak hours.

Watch out: data leakage

If you give a day-ahead model the load from one hour earlier, it will score a spectacular error in testing. But at 10 AM today you do not know tomorrow’s 4 PM minus one hour. Only use inputs that exist at the moment the forecast is issued. In our lab the most recent load the model sees is the same hour last week.

5. How we measure accuracy

MAPE (mean absolute percentage error) = (100% / n) × Σ |At − Ft| / At

MAE (mean absolute error) = (1 / n) × Σ |At − Ft|  (in MW)

Example for one hour: actual A = 30.0 MW, forecast F = 28.8 MW → |30.0 − 28.8| / 30.0 = 1.2 / 30.0 = 4.0%. MAPE is this value averaged over all 8,760 hours of the test year.

6. The results: three models, one unseen year

All three models were trained on 2024 and tested on the full year 2025 (8,760 hours). The example substation peaks at about 41 MW.

Model What it does MAPE 2025 MAE 2025
Baseline Load at the same hour last week 7.51% 1.45 MW
Linear regression Daily shape + cooling and heating slopes for each hour (73 inputs) 5.70% 1.04 MW
XGBoost 600 boosted trees on 8 features 3.22% 0.63 MW
Bar charts comparing MAPE of baseline 7.5 percent, linear regression 5.7 percent and XGBoost 3.2 percent, and their bias on the highest-load hours
Figure 3. Left: XGBoost cuts the average error by more than half compared with the baseline. Right: on the 88 highest-load hours of 2025 every model runs low, the baseline by almost 3 MW.

The heat-wave week shows why. “Same hour last week” repeats last week’s milder weather and misses the heat. Both temperature-aware models follow it closely.

Line chart of a summer heat-wave week showing actual load and three forecasts; XGBoost follows the actual curve most closely
Figure 4. The week of the 2025 peak. The 37.1 MW peak on Friday August 1 at 5 PM was forecast at 34.3 MW by XGBoost.

A 3% average does not mean a 3% peak error

Look closely at Figure 4. XGBoost missed the single highest hour of the year by 2.7 MW, about 7%. Averages are dominated by thousands of ordinary hours, but transformers, feeders and demand response programs are sized and called for the few extreme ones. Always report the peak-hour error separately from MAPE.

There is a second caution for real projects. Decision trees cannot predict outside the range they saw in training. If next summer is hotter than anything in your history, or load grows fast because of new data centers or EV fleets, a tree model flattens out while a regression keeps its slope. This is why many utilities blend a tree model with a regression model for peak planning.

7. What the model relies on

Horizontal bar chart of XGBoost feature importance: load same hour last week 34 percent, temperature now 33 percent, temperature 3 hours ago 16 percent, hour of day 9 percent
Figure 5. Weather inputs (orange) together carry about half of the model’s decisions. Thermal memory (temperature 3 hours earlier) ranks third.

Feature importance is a sanity check. If a model relied mostly on “month” or “day of week”, it would be memorizing the calendar of 2024 instead of learning physics. Here it relies on temperature, thermal memory, last week’s load and the hour of day, exactly what an engineer would expect.

8. Five lessons for utility forecasters

  1. Beat a baseline first. If your model cannot beat “same hour last week”, the problem is the data or the features, not the algorithm.
  2. Your forecast is only as good as your weather forecast. In the lab, adding a typical 2 °C temperature forecast error raises the XGBoost MAPE from 3.2% to about 5.0%.
  3. Split by time, never randomly. Random splits let the model peek at tomorrow’s neighbors and overstate accuracy.
  4. Measure the peak separately. Planning decisions live in the top 1% of hours.
  5. Retrain when the system changes. New large loads, PV and EV adoption shift the load shape. A model trained on last year’s customers slowly drifts out of date.

9. Free hands-on lab kit

GIEE Load Forecasting Lab Kit

GIEE_Load_Forecasting_Lab.ipynb Google Colab notebook, 10 numbered steps, expected output after each step, error table and Try It Yourself challenges
giee_substation_load_2024_2025.csv 17,544 hourly rows: load (MW), temperature (°C and °F), holiday flag
GIEE_Load_Forecasting_Excel_Lab.xlsx Daily peak model with LINEST, live MAPE and charts. No coding needed
README.txt How to start and the full table of expected results

Download the free lab kit (ZIP)

Python track (about 30 minutes):

  1. Unzip the kit. Open colab.research.google.com and choose File > Upload notebook.
  2. Optional: upload the CSV with the folder icon on the left. If you skip it, the notebook rebuilds the identical dataset.
  3. Run each cell with Shift + Enter and compare with the Expected output box below it. The full run takes under a minute on a free Colab CPU.

Excel track (about 15 minutes): open the workbook, read the “Read me” sheet, then change the orange base-temperature cells on the “Model” sheet and watch the 2025 MAPE change.

Check your result Expected
Colab: baseline MAPE 7.51%
Colab: linear regression MAPE 5.70%
Colab: XGBoost MAPE 3.22%
Colab: 2025 peak, actual vs XGBoost 37.1 MW vs 34.3 MW
Excel: daily peak model MAPE (bases 18 / 15 °C) 4.15%
Excel: with a cooling base of 22 °C 2.98%

Try it yourself

  • Weather forecast error: add a 2 °C random error to the test temperatures (code in the notebook). How much accuracy do you lose?
  • Remove last week’s load from the features. Does XGBoost still beat the regression? (Spoiler: on this weather-driven substation, yes, at about 3.1%.)
  • Find the balance point in Excel: which cooling base temperature gives the lowest MAPE?
  • Use your own data: any hourly CSV with a timestamp, a load column and a temperature column works after renaming the columns.

Share your MAPE on LinkedIn with #GIEElab and tag the Global Institute of Electrical Engineering. We feature good results in the GIEE newsletter.

Where to go next

Load forecasting is one of many places where AI is already changing utility work, alongside asset health, DER integration and grid operations. To build a structured, practical understanding of AI tools, data and use cases in the power sector, continue with EE399: AI for Energy & Utility Professionals, the accessible entry point to GIEE’s AI in Energy curriculum. Earn PDHs upon completion.

This article and lab use synthetic data generated by GIEE for education. The data describes no real utility. Validate any operational forecast against your own utility data, procedures and engineering review.

GIEE NEWSLETTER

Engineering insight for the modern grid, once a month

Free engineering tools, worked examples with real numbers, new GIEE publications and free webinar dates.

One email a month. Confirm by email, unsubscribe anytime. We never share your address.

GIEE is a global education platform for the engineers building the future of energy.

Renewable Energy · Power Systems · Energy Storage · Data Analytics · AI

Professional courses, certifications, live training, and events.

Newsletter

One email a month. Confirm by email, unsubscribe anytime. We never share your address.

top
© 2026 GIEE | All rights reserved.