Milk is one of the most widely used products, as well as being the raw material of all dairy products. Given this, measuring milk components has become very crucial for the dairy industry. Each dairy product requires milk with different ratios of its contents. Moreover, in order to keep track of the product quality, milk contents should be measured regularly.

Figure 1. The relation between the reference data (chemical analysis) and the predicted results from our model. Each circle represents a test sample where the x-coordinate is the reference value and the y-coordinate is the model prediction. The red line represents the ideal model and R2 (ideal value is 1) shows how far the model deviates from the ideal one.

Besides the dairy industry, milk analysis has a high impact on the supplying milk farming industry as well. The contents of the milk are closely related to the health of the animal and the quality and content of its feed. Accordingly, these measurements can provide valuable insights to enhance the quality and selection of their feed, as well as valuable insights for early diagnosis and treatment of sick animals.

Nowadays, the most accurate methods for milk analysis are chemical decomposition methods which are slow, destructive and must be done in the lab, not in the field. Practically, users normally take samples from many milk batches and get an averaged conclusion for all batches. Monitoring health and feeding quality for the animals using these methods is extremely expensive and very inefficient.

A simple tool for rapid measurement of the milk contents would be significant progress in both the dairy and the milk farming industries. This tool has to be portable, affordable and should allow users to analyze their target samples non-destructively and in the field, and preferably inline in the milking station in the case of milk farming applications. Miniaturization of near-infrared (NIR) spectrometers has advanced to the point where handheld instruments could provide a reliable and affordable means to serve this purpose.

Quantify Milk Contents

In order to demonstrate the ability of NeoSpectra spectral sensors to determine the percentage of each component - fat, protein and lactose - in a test sample of raw milk, the following procedures and test specifications were implemented:

Sample set used:

  • Samples were collected from local farms, where each sample collected was from a different animal to ensure that the sample space had a good variance;

  • Accurate destructive chemical tests were performed on the samples to accurately record their contents;

  • Total number of samples taken was 131;

  • Each sample was measured 5 times with the NeoSpectra spectral sensor.

Measurement conditions:

  • Measurements were done in diffuse reflection;

  • Spectral range: 1300 – 2600 nm;

  • Scan time: 2s;

  • Resolution: 16nm at λ=1,550 nm;

  • Spot size = 3 mm2;

  • Background: 99% Spectralon™ (a reflection standard with almost flat spectral response in NIR);

  • All measurements were performed at room temperature.

Data Evaluation

Partial least squares regression (PLS) models were built to develop a linear relation between the spectra and the milk contents measurements, which were determined using lab chemical analysis. This model is used in the prediction of milk sample contents percentages from its spectrum only.

PLS reduces spectrum data into a small number of latent variables (L.V.) to reduce the complexity of the data, since each spectrum may originally exceed 300 variables (wavelengths). Latent variables were chosen according to their correlation with the responses (milk contents in our case); variables with high correlation were chosen while others with lower correlation were discarded. After that a linear regression was fit to relate the predictors (L.V. of the spectra) to the responses (milk contents quantifications).

A cross validation technique was used to calculate the performance of the PLS model by reporting the prediction error (root mean square of the errors of all samples) and the coefficient of determination (R2) between predicted contents and the reference data (reported from chemical analysis). This technique splits the data into calibration and validation sets. The calibration set is used to train the PLS model while the validation set is used for reporting the performance of the model.

In the next iteration, the validation and calibration sets were mixed together, another portion of data was taken as the validation set, and finally, model training and validation on the new sets were repeated. The previous procedure was repeated again and again until each sample was represented once in the validation set. Results from the cross validation are shown in Figure 1.

Figure 2. The NeoSpectra Micro spectral sensor with integrated optical head and light source, BGA solderable, and SPI communication.

This investigation develops a milk analysis model by applying preprocessing methods to the spectra, then using PLS to build a regression model. In the prediction phase, the developed model is used to predict the content of the test sample.

The results clearly demonstrated that the spectra of the raw milk samples measured with NeoSpectra spectral sensors provide suitable analytical data to accurately measure the milk contents with an error less than 8% of the full range for any of the components, as opposed to an error of 9% using a commercial benchtop ultrasound-based analysis tool for the same samples set.

On the other hand, the absolute error from these investigations is slightly better in predicting protein and lactose percentages compared to numbers reported in research papers using commercially available lab benchtop spectrometers. However, absolute error for predicting fat percentages was not as good due to the small spot size used. NeoSpectra spectral sensors can support larger spot sizes to address such issues. This validates the potential of this technology to enable fast, non-destructive testing in the field and without the need for sample preparation using a low-cost technology that enables a scalable solution for milk qualification.

This article was written by Amr Wassal, VP of Systems Engineering, and Mohamed Hossam, Senior Embedded Software Engineer, Si-Ware Systems (La Canada, CA). For more information, contact the authors at This email address is being protected from spambots. You need JavaScript enabled to view it. or visit here .

Photonics & Imaging Technology Magazine

This article first appeared in the November, 2019 issue of Photonics & Imaging Technology Magazine.

Read more articles from this issue here.

Read more articles from the archives here.