# 027. Wine quality label balance

**Question:** How strongly are sensory labels concentrated in the middle of the rating scale?

## Result

The largest computed metric is 0.4488 for white / 6; the smallest is 0.001021 for white / 9. Metric: within_type_share (Within-type sample share).

The table reports observed score support; absent ratings do not imply impossible products.

![Wine quality label balance](outputs/chart.png)

| wine_type | quality | samples | within_type_share | label |
| --- | --- | --- | --- | --- |
| red | 3 | 10 | 0.006254 | red / 3 |
| red | 4 | 53 | 0.03315 | red / 4 |
| red | 5 | 681 | 0.4259 | red / 5 |
| red | 6 | 638 | 0.399 | red / 6 |
| red | 7 | 199 | 0.1245 | red / 7 |
| red | 8 | 18 | 0.01126 | red / 8 |
| white | 3 | 20 | 0.004083 | white / 3 |
| white | 4 | 163 | 0.03328 | white / 4 |
| white | 5 | 1457 | 0.2975 | white / 5 |
| white | 6 | 2198 | 0.4488 | white / 6 |
| white | 7 | 880 | 0.1797 | white / 7 |
| white | 8 | 175 | 0.03573 | white / 8 |
| white | 9 | 5 | 0.001021 | white / 9 |

The chart shows 13 of 13 result rows; the table previews the first 13 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

Counts and proportions by wine type and observed quality score.

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.

## Decision and limitations

Use label prevalence to choose evaluation metrics before training a quality model.

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/027-wine-quality-label-balance/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.
