learntodriveai.dev/Machine Learning/Data Leakage and PyTorch Training
Machine LearningProject 045 unitsVerified on 16 October 2026

Data Leakage and PyTorch Training

Marianne VelasquezHead of Building Analytics · Commercial real estate services · Chicago, Illinois, USA
Email · from Marianne
Last year we over-hedged on two buildings and under-hedged on three others, and the net was a seven-figure line-item our CFO asked me to explain.
Chat with Marianne

What you hand back

  • Per-building quarterly load predictions in kWh
  • A list of buildings outside the hedge band
  • A feature pipeline with documented reasoning
  • A PyTorch model compared against a baseline
  • Documented outlier and split decisions
  • A README for rerunning next quarter

5 units

  1. Unit 1: Marianne's Data

    Read Marianne's email, question her about the data, then profile the daily telemetry and quarterly load records.

    Open unit 1
  2. Unit 2: Feature Engineering and the Leakage Trap

    Fill in the evaluation template, build quarterly features from daily readings, and check the split for leakage.

    Open unit 2
  3. Unit 3: Outlier Handling and Feature Documentation

    Sort outliers into retrofit effects to keep and telemetry gaps to flag, then document each feature.

    Open unit 3
  4. Unit 4: PyTorch Training Loop

    Write a PyTorch training loop, add early stopping, and compare the run against a scikit-learn baseline in MLflow.

    Open unit 4
  5. Unit 5: Predictions for Marianne

    Send Marianne per-building predictions in hedge terms, handle her follow-up request, and document the project decisions.

    Open unit 5
Read the full brief

You're building an electrical-load prediction model from daily Building Management System (BMS) readings across twelve class-A office buildings in Chicago -- supply-air and return-air temperatures, chilled-water flow, outside-air conditions, occupancy -- plus quarterly load totals, delivering per-building predictions the client can commit quarterly electricity hedges against.

The discipline skills: engineering features from temporal sensor data, handling outliers as domain judgments rather than statistical noise, constructing a PyTorch training loop from scratch (forward pass, loss, backward pass, gradient update), configuring early stopping, and tracking neural network experiments in MLflow.

The AI-direction lesson: this project contains AI's most dangerous ML-specific failure mode -- a class of error that produces excellent-looking metrics on the data you have while the model predicts nothing useful in production. The specific mechanism isn't named here for a reason: you're going to encounter it directly in Unit 2 and decide what's going on. AI generates code that has this failure baked in by default. The errors are invisible without understanding what the code should do. The jump to PyTorch widens the surface — training loops that look correct can be subtly wrong in ways that only show up if you understand what each line is supposed to accomplish.

Your Role

You direct Claude Code through the data pipeline and model training. This time you make more decisions on your own: which features to construct, how to evaluate the model, how to handle data that doesn't fit the pattern. An evaluation design template gives you structure, but you fill it with judgment.

What's New

Last time you built infrastructure around an existing model — input validation, health checks, versioning, experiment tracking. The data and training were familiar territory from P1-P2.

This time the terrain shifts back to data and training, but harder. The data has temporal ordering that creates a trap: if the model accidentally sees future information during training, the metrics look excellent and the predictions are worthless. You'll also make the jump from scikit-learn's one-line .fit() to a PyTorch training loop where you control every step — forward pass, loss computation, gradient updates. AI generates code for both that looks correct. The errors are invisible without understanding what the code should do.

Tools

  • Python / pandas — data processing and feature engineering
  • scikit-learn — preprocessing and Pipelines (familiar, new depth)
  • PyTorch — neural network training (new)
  • Jupyter notebooks — exploration and training
  • MLflow — experiment tracking (familiar, deepened)
  • Claude Code — AI direction
  • Git / GitHub — version control

Materials

You receive:

  • Marianne's email describing the prediction problem and her hedge-commitment timeline
  • Two datasets: daily BMS telemetry from twelve buildings and quarterly electrical-load totals per building
  • An evaluation design template (you fill it with your metric choices and rationale)
  • A ticket breakdown covering the data pipeline, model training, and delivery
  • A project governance file (CLAUDE.md)
Materials · 6 files
Start Project 4

You work at a computer with a terminal. Signed in, your place is saved.