# 033. Higher-rated wine screening

**Question:** Can chemistry rank samples with an observed quality score of at least seven?

## Result

The largest computed metric is 0.6233 for Random forest; the smallest is 0.2019 for Prior baseline. Metric: average_precision (Average precision).

Seven is an analytical threshold, not a universal commercial standard. Quality itself is excluded from predictors.

![Higher-rated wine screening](outputs/chart.png)

| model | accuracy | balanced_accuracy | macro_f1 | roc_auc | average_precision | brier |
| --- | --- | --- | --- | --- | --- | --- |
| Prior baseline | 0.7981 | 0.5 | 0.4439 | 0.5 | 0.2019 | 0.1612 |
| Logistic regression | 0.8168 | 0.6108 | 0.6309 | 0.7849 | 0.5158 | 0.1303 |
| Random forest | 0.8393 | 0.6666 | 0.6955 | 0.8542 | 0.6233 | 0.1141 |

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

Binary target specified before analysis; grouped-input classification against prior prevalence.

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 models; default decision threshold; no holdout tuning.

Target: `higher_rated`. 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

Evaluate a prospective screening workflow with external batches before using the ranking.

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/033-higher-rated-wine-screening/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.
