# 035. Quality model errors by wine type

**Question:** Does a pooled quality model have different error or bias for red and white samples?

## Result

The largest computed metric is 0.5465 for white; the smallest is 0.444 for red. Metric: mae (Sensory-score MAE).

This is a subgroup diagnostic of the shared holdout, not a separate independent validation.

![Quality model errors by wine type](outputs/chart.png)

| wine_type | test_samples | mae | bias |
| --- | --- | --- | --- |
| red | 334 | 0.444 | 0.03391 |
| white | 954 | 0.5465 | -0.01428 |

The chart shows 2 of 2 result rows; the table previews the first 2 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

Held-out residual summaries stratified by wine type for a fixed Extra Trees model.

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

Investigate subgroup calibration and obtain external batch-level validation before specialization.

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/035-quality-model-errors-by-wine-type/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.
