# 032. Sensory quality regression

**Question:** Can chemical measurements estimate sensory quality better than a median baseline?

## Result

The largest computed metric is 0.6421 for Median baseline; the smallest is 0.5199 for Extra trees. Metric: mae (Sensory-score MAE).

Identical input signatures stay in one split. Scores are ordinal, while this benchmark treats score differences numerically.

![Sensory quality regression](outputs/chart.png)

| model | mae | rmse | r2 | bias |
| --- | --- | --- | --- | --- |
| Median baseline | 0.6421 | 0.8921 | -0.04212 | 0.1793 |
| Ridge | 0.5622 | 0.7325 | 0.2974 | -0.01169 |
| Extra trees | 0.5199 | 0.6718 | 0.409 | -0.00178 |

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

Fixed grouped-input regression with original score MAE and RMSE.

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

Fixed 80/20 split of unique input groups (seed 42); exact input duplicates stay together. Training observations: 5,209; test observations: 1,288. Fixed configurations specified before scoring; no tuning on the holdout.

Target: `quality`. Features: fixed_acidity, volatile_acidity, citric_acid, residual_sugar, chlorides, free_sulfur_dioxide, total_sulfur_dioxide, density, ph, sulphates, alcohol, wine_type. Model results and row membership are recorded in [evaluation.json](outputs/evaluation.json).

## Decision and limitations

Use error magnitude to judge whether laboratory features support an additional quality-screening study.

Sensory scores are ordinal and concentrated in the middle. Producer and batch IDs are unavailable. Associations are not recipes for changing quality or evidence of market price. 

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/032-sensory-quality-regression/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

[Wine Quality](https://archive.ics.uci.edu/dataset/186/wine+quality), Cortez et al. (2009). [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). Source data are transformed and aggregated in this study. [Source provenance](../../data/provenance/wine.json) and [prepared-data audit](../../data/provenance/wine_prepared.json) record the downloaded files, field coverage and hashes.
