Screen milk quality from routine product observations
This three-class model combines pH, temperature, colour and four binary quality observations to estimate whether a sample matches the dataset’s high-, medium- or low-quality patterns. The example shows how classification can support triage in a dairy quality workflow while keeping release decisions with validated laboratory and food-safety procedures.
Dairy plants need rapid, consistent ways to prioritize samples for review, but product release and food-safety decisions require validated measurement methods and traceable quality procedures. This example demonstrates a compact classifier that converts seven recorded attributes into three probabilities and a suggested quality class.
1. Industrial challenge
This is a multiclass classification problem. For each sample, the network returns probabilities for high_quality, medium_quality and low_quality; the largest probability determines the suggested class.
Potential users include dairy quality managers, food technologists, laboratory supervisors, production managers, process engineers and digital-quality teams.
2. Data set
The downloadable milkquality.csv contains 1,059 observations, seven inputs and the categorical target grade. There are no missing values in the published file.
| Variable | Meaning in the dataset | Type / unit | Observed range |
|---|---|---|---|
pH | Measured acidity/alkalinity | pH | 3.0 to 9.5 |
temperature | Sample temperature | °C | 34 to 90 |
taste | Dataset quality flag: 1 acceptable, 0 not acceptable | Binary | 0 or 1 |
odor | Dataset quality flag: 1 acceptable, 0 not acceptable | Binary | 0 or 1 |
fat | Dataset quality flag: 1 acceptable, 0 not acceptable | Binary | 0 or 1 |
turbidity | Dataset quality flag: 1 acceptable, 0 not acceptable | Binary | 0 or 1 |
colour | Colour value on the dataset scale | Numeric | 240 to 255 |
grade | Milk quality class | Target | High, medium or low |


The configured random split contains 637 training, 211 selection and 211 testing records.
3. Neural network
The baseline network scales seven inputs, uses three tanh neurons in one hidden layer and applies a softmax output for the three classes. Continuous inputs use mean-and-standard-deviation scaling, while the four binary flags use minimum–maximum scaling.

Neural Designer displays grade as one logical categorical output. The exported model evaluates three logits internally and normalizes them into probabilities that sum to one.
4. Training strategy
The classifier minimizes multiclass cross-entropy with the quasi-Newton method. Training and selection losses fall quickly during the first epochs and then stabilize, with the selection curve remaining above the training curve as expected when performance is evaluated on held-out rows.

The curve supports convergence for the configured split. Because duplicate input vectors can occur across subsets, the selection loss should not be treated as an independent estimate of performance on a new batch or plant.
5. Model selection
The growing-neurons task compares hidden layers from one to ten neurons. Most of the cross-entropy reduction occurs by three neurons, after which the selection curve changes only slightly. The final exported network contains 10 hidden neurons.


6. Testing analysis
The confusion matrix below is reproduced from the regenerated Neural Designer output. Rows are observed classes and columns are model predictions.
Confusion matrix
| Actual / predicted | High quality | Low quality | Medium quality | Total |
|---|---|---|---|---|
| High quality | 47 | 0 | 6 | 53 |
| Low quality | 0 | 84 | 1 | 85 |
| Medium quality | 0 | 0 | 73 | 73 |
| Total | 47 | 84 | 80 | 211 |
Per-class metrics
| Class | Testing support | Precision | Recall | F1 |
|---|---|---|---|---|
| High quality | 53 | 100.0% | 88.7% | 94.0% |
| Low quality | 85 | 100.0% | 98.8% | 99.4% |
| Medium quality | 73 | 91.3% | 100.0% | 95.4% |
In this split, no low-quality sample is classified as high quality. Six high-quality samples and one low-quality sample are assigned to the medium class. That error pattern is useful for triage, but it must be re-estimated on genuinely independent batches before defining operational thresholds.
7. Model deployment
A practical screening workflow should capture the sample identifier and batch, validate measurement ranges and sensor status, calculate the three probabilities, and send the result to the laboratory information or quality-management system for review.
Representative incoming-lot screening case
The following row is present in the published dataset and is evaluated with the final exported Python model. Binary values retain the dataset’s own acceptable/not-acceptable convention.
| Input | Value |
|---|---|
| pH | 6.6 |
| Temperature | 37 °C |
| Taste flag | 1 — acceptable |
| Odor flag | 0 — not acceptable |
| Fat flag | 1 — acceptable |
| Turbidity flag | 0 — not acceptable |
| Colour | 255 |
| Model output | Probability |
|---|---|
| High quality | 97.04% |
| Medium quality | 2.96% |
| Low quality | <0.01% |
Result: the model suggests high_quality with 97.04% probability. However, the two non-acceptable binary flags show why a professional implementation should preserve the raw measurements and apply documented business rules: this output can prioritize review, but it should not release the lot without the required confirmatory checks.
Integrate the exported model
The deployment package contains the exact Neural Designer Python export and a README with the input order and example call. The returned probability order is high_quality, low_quality, medium_quality.
from model import NeuralNetwork
model = NeuralNetwork()
probabilities = model.calculate_outputs([6.6, 37, 1, 0, 1, 0, 255])8. Scope and limitations
- The 1,059 records collapse to only 83 unique input combinations, so random row validation is vulnerable to duplicate leakage.
- The dataset does not identify farms, suppliers, plants, production batches, collection dates, instruments or operators; transfer across these groups is untested.
- Taste, odor, fat and turbidity are already encoded as “acceptable” or “not acceptable”, which can make the model partly reproduce prior human or rule-based judgement rather than infer quality from raw sensor measurements.
- Colour is provided on a 240–255 dataset scale without an instrument definition or calibration procedure.
- Inputs inside their individual ranges can still form combinations that were never represented among the 83 unique vectors.
- The target is a broad three-level quality label. Microbiological hazards, contaminants, adulteration, allergens and shelf-life behaviour are outside the model.
- Production use requires an independent, batch-grouped validation set, calibrated instruments, documented sampling procedures and periodic monitoring for class, data and concept drift.
- Final release, rejection and food-safety decisions must remain within the plant’s validated quality system and applicable laboratory or regulatory procedures.
References
- Kaggle. Milk Quality Prediction dataset.
- Neural Designer testing analysis: confusion matrices and classification metrics.
- Neural Designer model deployment: output calculation and Python export.




