# 050. One-hour-ahead appliance forecast

**Question:** Can lagged energy and known calendar features estimate appliance use an hour ahead?

## Result

The largest computed metric is 41.74 for Median baseline; the smallest is 40.4 for Ridge. Metric: mae (Wh MAE).

Forecast origin is one hour before each target interval, assuming the latest lagged interval has finalized. Later test predictions can use already observed earlier actuals.

![One-hour-ahead appliance forecast](outputs/chart.png)

| model | mae | rmse | r2 | bias |
| --- | --- | --- | --- | --- |
| Median baseline | 41.74 | 94.46 | -0.1569 | -34.79 |
| Ridge | 40.4 | 78.34 | 0.2044 | 1.574 |
| Extra trees | 41.23 | 76.52 | 0.2408 | 7.269 |

The chart shows 3 of 3 result rows; the table previews the first 3 in the analysis-defined order. [Download the full result table](outputs/results.csv). Numerical values are computed from the source; missing results stay unavailable.

## Method

Chronological regression with clock-time lags at 1, 2 and 24 hours.

The study uses shared source preparation and reusable statistical routines. Its specific transformations are in [analysis.py](analysis.py), and common model/evaluation code is in [portfolio/methods.py](../../portfolio/methods.py). The [notebook](analysis.ipynb) executes the study and displays the saved results.

## Evaluation

First 80% of ordered observations train; final 20% test. Training observations: 15,672; test observations: 3,919. Fixed configurations specified before scoring; no tuning on the holdout.

Target: `appliances`. Features: hour, weekday, lag_6, lag_12, lag_144, prior_hour_mean. Model results and row membership are recorded in [evaluation.json](outputs/evaluation.json).

## Decision and limitations

Measure reporting latency and test on a later season before using the forecast operationally.

Measurements come from one home over a limited period. Energy is Wh per recorded 10-minute interval. This is not a representative household sample; tariffs and occupancy labels are unavailable. 

Related studies may share observations or holdouts. These are focused analytical studies, not independent replications or deployed business systems. Any model refinements informed by these results need new untouched evaluation data. No commercial impact is inferred from an association or backtest.

## Reproduce

From the repository root, after installing `requirements.txt`:

```powershell
python projects/050-one-hour-ahead-appliance-forecast/analysis.py
```

Source data are downloaded automatically if absent. Original archives are retained unchanged and checked by SHA-256. The cleaned cache normalizes column names; field-specific changes are visible in [data preparation](../../portfolio/data.py). Runtime evidence is in [receipt.json](outputs/receipt.json).

## Source

[Appliances Energy Prediction](https://archive.ics.uci.edu/dataset/374/appliances+energy+prediction), Candanedo (2017). [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). Source data are transformed and aggregated in this study. [Source provenance](../../data/provenance/energy.json) and [prepared-data audit](../../data/provenance/energy_prepared.json) record the downloaded files, field coverage and hashes.
