# 057. Carbon monoxide sensor calibration

**Question:** Can contemporaneous sensor responses estimate an available reference CO concentration?

## Result

The largest computed metric is 1.018 for Median baseline; the smallest is 0.379 for Extra trees. Metric: mae (CO reference-unit MAE).

This estimates a simultaneous reference reading, not a future concentration. Test dates follow training among observed target rows.

![Carbon monoxide sensor calibration](outputs/chart.png)

| model | mae | rmse | r2 | bias |
| --- | --- | --- | --- | --- |
| Median baseline | 1.018 | 1.348 | -0.005772 | -0.1021 |
| Ridge | 0.3842 | 0.6417 | 0.7722 | -0.1292 |
| Extra trees | 0.379 | 0.6204 | 0.7871 | -0.04536 |

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 benchmark using sensors and environmental measurements, excluding other gas references.

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,139; test observations: 1,535. Fixed configurations specified before scoring; no tuning on the holdout.

Target: `co_gt`. Features: pt08_s1_co, pt08_s2_nmhc, pt08_s3_nox, pt08_s4_no2, pt08_s5_o3, t, rh, ah. Model results and row membership are recorded in [evaluation.json](outputs/evaluation.json).

## Decision and limitations

Validate on a later instrument period before filling reference gaps.

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/057-carbon-monoxide-sensor-calibration/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.
