# 059. One-hour-ahead CO forecast

**Question:** Can earlier observed CO and sensor responses improve a one-hour-ahead reference forecast?

## Result

The largest computed metric is 1.018 for Median baseline; the smallest is 0.4227 for Extra trees. Metric: mae (CO reference-unit MAE).

Origin is one observed hour before target. Lagged reference availability is assumed; production outages would change feasibility.

![One-hour-ahead CO forecast](outputs/chart.png)

| model | mae | rmse | r2 | bias |
| --- | --- | --- | --- | --- |
| Median baseline | 1.018 | 1.349 | -0.006106 | -0.1051 |
| Ridge | 0.4869 | 0.7138 | 0.7184 | 0.03062 |
| Extra trees | 0.4227 | 0.6241 | 0.7847 | 0.02036 |

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

Complete-grid lags and a chronological holdout, excluding contemporaneous target-hour observations.

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: 6,120; test observations: 1,531. Fixed configurations specified before scoring; no tuning on the holdout.

Target: `co_gt`. Features: hour, co_lag_1, co_lag_24, sensor_lag_1. Model results and row membership are recorded in [evaluation.json](outputs/evaluation.json).

## Decision and limitations

Assess latency and later-period performance before testing an operational forecast.

The -200 sentinel is treated as missing. Reference instruments have incomplete coverage; comparisons use paired observations. Sensor calibration is retrospective, not a health or regulatory compliance assessment. 

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/059-one-hour-ahead-co-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

[Air Quality](https://archive.ics.uci.edu/dataset/360/air+quality), De Vito (2008). [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). Source data are transformed and aggregated in this study. [Source provenance](../../data/provenance/air.json) and [prepared-data audit](../../data/provenance/air_prepared.json) record the downloaded files, field coverage and hashes.
