Learning

Improve wine quality using machine learning

Estimate red-wine sensory quality from routine laboratory measurements

This regression example maps ten physicochemical measurements from Portuguese red Vinho Verde to the panel’s sensory-quality score. On 319 held-out rows, the final 10–10–1 model obtains a Neural Designer goodness-of-fit determination of 0.366, RMSE 0.619 points and 90.9% of estimates within one score point. It supports laboratory pre-screening and lot triage; it does not replace sensory assessment or prove how to improve a formulation.

0.366testing GOF determination
0.619testing RMSE (score points)
90.9%testing estimates within ±1 point
319held-out testing rows

1. Scientific objective

The objective is to estimate the sensory quality assigned to a red Vinho Verde sample from analytical measurements available during laboratory quality control. The output can help oenologists and quality teams prioritize tasting, investigate atypical lots and compare represented samples consistently. It is a predictive screening model: associations with alcohol, acidity or sulphur dioxide do not establish that changing one variable will cause the score to improve.

Laboratory pre-screening

Flag lots whose analytical profile merits earlier sensory or process review.

Consistency monitoring

Compare an estimated score with panel results and investigate persistent disagreement.

Reproducible benchmarking

Evaluate a compact nonlinear regressor on a widely used oenology data set.

OenologistsWinery quality teamsLaboratory managersProcess engineersFood data scientists
Scope. The model represents one red Vinho Verde data collection from northern Portugal. It estimates the recorded panel score from end-product analytical measurements; it does not model vineyards, fermentation history, aroma chemistry, consumer preference or causal recipe changes.

2. Data and provenance

The UCI Wine Quality data set contains physicochemical and sensory results for Portuguese Vinho Verde. This project uses the 1,599 red-wine rows. The target quality is an ordered panel score on a 0–10 scale, although the observed rows cover only scores 3–8.

SubsetRowsPurpose
Training961Estimate network parameters
Selection319Monitor training and select hidden-layer size
Testing319Final internal evaluation
Distribution of observed red-wine quality scores
Scores 5 and 6 account for 82.5% of all rows; scores 3 and 8 are very rare.
Correlations between analytical inputs and quality
Alcohol has the largest displayed positive association and volatile acidity the largest negative association. These are univariate associations, not intervention effects.

Analytical fields and model contract

FieldUnit or scaleUse in this project
fixed_acidityg tartaric acid/dm³Present in CSV; imported as the sample-ID field and therefore excluded from the model
volatile_acidityg acetic acid/dm³Input
citric_acidg/dm³Input
residual_sugarg/dm³Input
chloridesg sodium chloride/dm³Input
free_sulfur_dioxidemg/dm³Input
total_sulfur_dioxidemg/dm³Input
densityg/cm³Input
pHDimensionlessInput
sulphatesg potassium sulphate/dm³Input
alcohol% volInput
qualityPanel score, 0–10Target; observed range 3–8

winequality.csv is the exact 1,599-row table used by the stored project. Its local and published copies have matching SHA-256 hashes.

Validation caveat. The table contains 240 duplicate rows. In the stored random split, 124 duplicate groups cross subset boundaries and 76 of 319 testing rows have an identical row in training or selection. The reported metrics reproduce the project, but a production study should keep identical profiles—and preferably complete lots or harvest batches—in one subset.

3. Model

The baseline network standardizes ten inputs, applies one dense layer with three tanh neurons and returns one continuous quality estimate through an identity neuron, output unscaling and bounds of 3–8. The initial 10–3–1 architecture contains 37 trainable parameters.

Output contract. The output is a continuous estimate of an ordered, subjective panel score. Decimal values are expected; rounding them does not turn the task into independently validated classification.
Initial ten-input, three-hidden-neuron wine-quality regression network
Initial 10–3–1 approximation network used for the baseline training run.

4. Training strategy

The baseline minimizes normalized squared error with L2 regularization using the Quasi-Newton method. Across 81 epochs, training error falls from 0.9987 to 0.5547 and selection error from 0.3696 to 0.2208.

Wine-quality training and selection error history
Training history for the initial three-neuron network before architecture selection.

5. Model selection and baseline

The growing-neurons task evaluates one to 20 hidden neurons. The lowest stored selection error is 0.2182 at ten neurons, only slightly below neighbouring candidates. Because the curve is nearly flat and the search reaches its configured maximum, ten neurons should be read as the selected run—not as proof of a uniquely optimal architecture.

Neuron-selection errors from one to twenty hidden neurons
Selection error changes little beyond the first few neurons; the stored minimum occurs at ten.

Selected architecture

The final model expands the hidden layer from three to ten tanh neurons. The 10–10–1 network contains 121 trainable parameters and is the model used for testing, the browser calculation and the downloadable Python export.

Selected ten-input, ten-hidden-neuron wine-quality regression network
Final 10–10–1 architecture obtained after neuron selection.
ReferenceTesting RMSEReading
Training-mean baseline0.771One constant estimate for every test row
Final neural network0.61919.7% lower RMSE than the null baseline

6. Scientific validation

The final model is evaluated on the 319 testing rows after neuron selection. Neural Designer’s linear goodness-of-fit analysis reports a determination coefficient of 0.366. Directly recomputing residual metrics from the same exported model gives RMSE 0.619, MAE 0.486 and mean signed error −0.053 score points.

Testing measureResultProfessional reading
GOF determination0.366Moderate association between observed and predicted scores
RMSE0.619Penalizes the larger misses
MAE0.486Typical absolute miss is about half a score point
Mean signed error−0.053Small aggregate bias can hide strong score-dependent bias
Within ±1 point90.9%290 of 319 testing estimates

Error by observed score

Observed scoreTesting rowsMAEMean signed error
312.105+2.105
461.259+1.259
51320.360+0.318
61350.455−0.238
7420.789−0.788
831.110−1.110
Observed and predicted wine-quality scores on the testing subset
Goodness-of-fit analysis exported from Neural Designer for the final 10–10–1 model and 319 testing rows.
Quality-control interpretation. Observed testing values span 3–8, while predictions span only 4.57–7.21. The model pulls rare low and high scores toward the centre: it can support central-range triage, but it is weakest exactly where exceptional or defective lots may matter most.

7. Inference and reproducibility

A professional workflow starts with a traceable lot and validated laboratory results, reproduces the ten-field schema, calculates an estimate, compares it with historical and sensory-panel evidence, and records the model version and any warning.

Lot and laboratory record
Schema and range checks
Quality-score estimate
Panel or process review
Traceable disposition

Try the exported red-wine quality estimator

The defaults reproduce a held-out record with an observed sensory score of 6. The exact exported model estimates 6.01.

Research demonstration. The calculation runs locally with the exact exported weights and preprocessing. Values outside the validated domain are rejected. The result is not a certified sensory score or a causal recommendation for changing the wine.

Reproduce the calculation

The Python package contains the exact final export, ordered input schema, representative testing row and example call.

from model import NeuralNetwork

inputs = [0.34, 0.42, 2.0, 0.086, 8.0, 19.0, 0.99546, 3.35, 0.6, 11.4]
estimated_quality = NeuralNetwork().calculate_outputs(inputs)[0]
print(estimated_quality)  # 6.0070449704

8. Validity, uncertainty and limitations

  • Internal random split only. No independent winery, harvest, geography or later-vintage validation is shown.
  • Duplicate leakage. Seventy-six testing rows have an exact duplicate in another subset, so the stored split can overstate transfer to new lots.
  • One data collection. Results cannot be assumed to transfer to white wine, other appellations, grape varieties, laboratories or analytical protocols.
  • Sensory labels are subjective and discrete. Panel composition, repeatability and disagreement are not available, and an ordinary regressor does not explicitly model the target’s ordinal structure.
  • Rare-score performance is weak. Only ten score-3 and eighteen score-8 records exist in the full table; the test set contains one and three respectively.
  • Current import excludes fixed acidity. The stored project treats the first CSV field as a sample identifier. A full 11-feature experiment requires re-importing the file without that setting and regenerating every dependent artifact.
  • No causal optimization. Directional outputs or response optimization would describe the fitted associations only; proposed process changes need designed experiments and oenological review.
Decision boundary. Use the estimate for research, quality-control triage and model benchmarking. Do not release, reject or reformulate a lot from this score alone.

References