Next Article in Journal
Influence of Main Thoracic and Thoracic Kyphosis Morphology on Gait Characteristics in Adolescents with Idiopathic Scoliosis: Gait Analysis Using an Inertial Measurement Unit
Previous Article in Journal
A Comprehensive Review of Elbow Exoskeletons: Classification by Structure, Actuation, and Sensing Technologies
Previous Article in Special Issue
A Novel Detection Scheme for Motor Bearing Structure Defects in a High-Speed Train Using Stator Current
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Toward a User-Accessible Spectroscopic Sensing Platform for Beverage Recognition Through K-Nearest Neighbors Algorithm

National Research Council (CNR), Institute for Microelectronics and Microsystems (IMM), 00133 Rome, Italy
*
Author to whom correspondence should be addressed.
Sensors 2025, 25(14), 4264; https://doi.org/10.3390/s25144264
Submission received: 28 May 2025 / Revised: 1 July 2025 / Accepted: 7 July 2025 / Published: 9 July 2025

Abstract

Proper nutrition is a fundamental aspect to maintaining overall health and well-being, influencing both physical and social aspects of human life; an unbalanced or inadequate diet can lead to various nutritional deficiencies and chronic health conditions. In today’s fast-paced world, monitoring nutritional intake has become increasingly important, particularly for those with specific dietary needs. While smartphone-based applications using image recognition have simplified food tracking, they still rely heavily on user interaction and raise concerns about practicality and privacy. To address these limitations, this paper proposes a novel, compact spectroscopic sensing platform for automatic beverage recognition. The system utilizes the AS7265x commercial sensor to capture the spectral signature of beverages, combined with a K-Nearest Neighbors (KNN) machine learning algorithm for classification. The approach is designed for integration into everyday objects, such as smart glasses or cups, offering a noninvasive and user-friendly alternative to manual tracking. Through optimization of both the sensor configuration and KNN parameters, we identified a reduced set of four wavelengths that achieves over 96% classification accuracy across a diverse range of common beverages. This demonstrates the potential for embedding accurate, low-power, and cost-efficient sensors into Internet of Things (IoT) devices for real-time nutritional monitoring, reducing the need for user input while enhancing accessibility and usability.

Graphical Abstract

1. Introduction

Food plays an essential and irreplaceable role in human life, serving not only as a source of nourishment and energy but also as a key factor in the social sphere [1]. A healthy diet can indeed positively impact our health, sleep [2,3], behavior [4], and overall well-being [5,6,7,8], leading us to experience a healthier and longer life. On the other hand, studies suggest that an unhealthy diet poses a significant risk factor for the development of chronic diseases like metabolic disorders or cardiovascular diseases [9,10].
Nowadays, the fact that highly processed and calorie-dense foods are not only widely available, but also often inexpensive, has increased concern about the food we daily consume. Indeed, the abundance and easy availability of unhealthy food options contributes significantly to the increasing rates of obesity and related health issues, such as heart diseases, diabetes, and other chronic conditions [10,11,12]. These factors, combined with modern lifestyles, are leading to the fact that obesity and related diseases are increasing globally [13,14,15].
For these reasons, carefully monitoring what we eat and drink is a crucial aspect of maintaining a healthy lifestyle, particularly for individuals adhering to specific dietary plans or managing health conditions. By being mindful of our food and beverage choices, we can ensure that we meet our nutritional needs, support overall wellness, and prevent potential health risks. Whether it is for weight management, controlling chronic illnesses, or optimizing fitness, paying close attention to our diet allows us to make informed decisions that align with our personal health goals and long-term well-being [16].
Nowadays, technological advancements are driving the development of increasingly non-invasive devices that help monitor various parameters, including fitness levels [17], vital signs [18,19], and nutritional intake. Indeed, the traditional method of recording nutrient intake involves manually tracking food consumption to monitor calories, macronutrients, and other dietary components. However, while effective, this method is often time-consuming and labor-intensive, requiring consistent effort and attention by the user [20,21]. As a result, many people find it challenging to maintain such an approach long term, highlighting the need for more efficient tools and technologies to simplify dietary monitoring. For this reason, there has been a growing surge in the development of mobile apps designed to help individuals recognize and track their food intake more easily. Many of these apps leverage the camera systems of smartphones, allowing users to simply take pictures of their meals for automated analysis. These programs exploit artificial intelligence and machine learning to identify food items, estimate portion sizes, and provide detailed nutritional information, making it easier to monitor calorie and nutrient intake. This innovation significantly reduces the time and effort required for manual tracking, offering a more convenient solution for maintaining a healthy diet [22,23,24,25].
While this approach greatly simplifies the process of gathering nutritional information, it still relies on a certain level of smartphone knowledge and requires users to take a picture of each dish and beverage consumed. This reliance on smartphone use can be challenging for two reasons. First, it can be difficult or even unfeasible for individuals who lack familiarity with or access to smartphone technology, such as older adults or people with certain disabilities. Second, even for tech-savvy users, smartphone apps may struggle to distinguish between visually similar foods or beverages. For instance, identifying subtle variations in dishes with similar ingredients can lead to inaccuracies in tracking. In addition, having these apps access smartphone cameras also raises privacy issues about the use and collection of personal data derived from the uploaded images. These limitations underscore the need for further technological advancements and alternative tracking solutions that can accommodate a broader range of users while improving the accuracy of food recognition tools. In this context, we propose a compact tool that can be implemented in a smart glass or smart cup specifically designed to distinguish among the most common beverages. This system utilizes a commercially available spectroscopy sensor, the AS7265x (AMS Osram, Premstaetten, Austria), to detect the unique spectral properties of each beverage. The classification of each beverage is enabled by a machine learning model that applies the K-nearest neighbor (KNN) algorithm. We apply the KNN algorithm to compare the spectral data of an unknown beverage with the stored data of known beverages, matching it to the closest categories based on their spectral “fingerprints”. This innovative approach opens to a reliable and easy-to-use solution for beverage recognition. In the contest of IoT technology development, these types of systems enable the design of intelligent food monitoring solutions, such as smart plates, cups or utensils equipped with spectroscopic sensors, and machine learning algorithms that can autonomously analyze the composition of food and beverages in real time, providing users with detailed nutritional information without requiring manual input.

2. Materials and Methods

2.1. Beverages Analyzed

The beverages selected for testing were chosen to represent a wide range of popular options, covering diverse categories to ensure the system’s versatility. The selected beverages reported in Table 1 included both animal and plant-based milks, still and sparkling water, various sports and energy drinks, sugary beverages, wine, as well as commonly consumed drinks like tea and coffee. By including such a broad spectrum, we aimed to capture the unique spectral profiles of each beverage type, thereby enhancing the system’s capability to accurately differentiate among them. Although different beverages can be consumed at different temperatures, in this study we decided to analyze the beverage at room temperature to ensure consistency and excluding the temperature effects on the beverage spectrum (a simple example of the temperature on the spectra is reported in Figure S1). Thirty spectral measurements were taken for each drink without any dilution, allowing us to capture a comprehensive spectral profile, reducing the influence of potential measurement noise or variability. Each beverage has been tested filling a commercial 4.5 mL cuvette (10 mm optical path) by Kartell LABWARE (Noviglio (MI), Italia). Poly(methyl methacrylate) (PMMA) was chosen as the material for the cuvette to facilitate the design, prototyping and development of an intelligent IoT cup. In fact, its suitability with precision machining or molding makes it ideal for fabricating integrated optical paths with controlled geometry. Moreover, its compatibility with embedding electronic components within the container walls supports the development of sealed and washable smart devices, where sensor alignment and measurement stability can be ensured by design. The cuvette was washed after each measurement and replaced between different beverages.

2.2. System Setup

The sample spectrum is processed by an AS7265x kit, a spectroscopic sensor with integrated interference filters deposited on CMOS silicon. The AS7265x kit from Ams integrated three sensors, each with six independent optical channels. In Figure 1a is reported the spectral response of the 18 channels of the Ams kit [26]: the three sensors thus offer a combined spectroscopic range from 410 to 940 nm with each channel providing a full width at a half maximum of 20 nm. The system uses a 4000 K white LED from Cree LED Inc. (Durham, NC, USA) as its light source. Its emission was acquired through a Photonic Multi-channel Analyzer PMA-12 detector by Hamamatsu Photonics (Hamamatsu City, Shizuoka, Japan) and is reported in Figure 1b. This LED was selected due to the Color Rendering Index (CRI) of 90, ensuring a wide spectral power distribution that provides an improved spectral illumination compared to a standard white LED. The 3 V supply power needed for the illumination source was provided through batteries, which ensured the operation of the LED during the entire data acquisition. The absorption spectra were acquired using the software Spectral Sensor Dashboard (v.5.1.0) from Ams. A 3D-printed model provided a structure to mount the components. The complete system setup is reported in Figure 2.

2.3. KNN Algorithm

One of the most simple and effective models to predict the discrete class label of an unlabeled sample is the KNN algorithm. KNN is a non-parametric supervised machine learning algorithm often used for data classification [27]. KNN algorithm operates on the principle of proximity. When presented with a new data point, the algorithm calculates the distance between the new data point and all points in the training dataset. Based on the calculated distances, it selects the K nearest data points from the training dataset. Finally, for classification task, the algorithm assigns the new data point to the majority class among its K neighbors [27,28,29,30]. An example of KNN is represented in Figure 3.
To evaluate the performance of the model, the data have been divided into two sets: training data and test data. The training data are used to teach the algorithm the unique characteristics and features of each class, enabling it to build a classification model. The test data are used to assess the model’s performance. This evaluation involves comparing the model’s predictions with the actual classifications, thereby determining its accuracy, and overall effectiveness. This approach ensures that the model is not only well trained but also capable of generalizing its classification ability to new, unseen data. This aspect is particularly relevant for this application, the number and typology of beverages being very large. In particular, we use a k-fold cross-validation, which divides the dataset into kf parts, training the model on kf—1 fold and testing on the remaining fold, repeating the process kf times. By using k-fold cross-validation, a more reliable estimation of the model can be obtained because each observation in the dataset is used for both training and testing. To have a good balance between computational efficiency and reliable model evaluation, we chose a kf = 3 [31,32,33,34,35]. In the case of smart IoT cup development, the sensor acquires the absorption spectrum of a beverage, obtaining the characteristic components of the spectrum. These are then compared with a database of labeled beverage spectra using the Euclidean distance and the KNN algorithm identifies the closest K spectra from the training set. The beverage is then classified according to the majority class among these neighbors.
The performance of the KNN algorithm depends significantly on the choice of K number of nearest neighbor. For this reason, we systematically tested all values of K ranging from 1 to 15 during the test of the sensor. This allowed us to determine the K value that maximizes the classification.
The KNN algorithm applied in this study was implemented using the open-source scikit-learn Python library (v.1.7).

3. Results and Discussion

Figure 4 shows the intensities of light absorbed by the beverages, normalized to their respective maximum values, plotted as a function of the sensor wavelengths. As can be seen from the absorption graph, most of the spectra of the beverages vary significantly in intensity at specific wavelengths. These variations form the basis for distinguishing between different drinks using the KNN algorithm. The spectra of some drinks, on the other hand, are found to have small differences between the values of absorbed light intensities, resulting in a spectral fingerprint that is not easily distinguishable. Very similar spectra, such as those found from Coca-Cola® and Coca-Cola Zero Sugar®, may therefore result in a less accurate classification.
Data analysis began with a study of the number of K nearest neighbors that would maximize the accuracy of the classification model employed. In Figure 5 is reported the accuracy of the model as a function of the number of neighbors (K) used in the K-nearest neighbors’ algorithm. The k-fold cross-validation revealed that the model achieves the highest accuracy (around 93%) when K is set to smaller values, specifically at K = 1. As K increases, the accuracy gradually declines. This suggests that a smaller neighborhood size allows the model to make more precise classifications, where the distinctions between some beverage classes are sharp.
To obtain a more detailed description of the performance of the KNN classifier, we produced a confusion matrix for K = 1 (Figure 6). Analysis of the confusion matrix reveals a good accuracy of the KNN model used. In fact, as can be seen from the diagonal of the matrix, most drinks are recognized with 100% accuracy. This suggests that the spectral profiles of most of the beverages studied are distinctive and the model correctly succeeds in classifying them.
Other beverages, however, are recognized with more difficulty by the model. In fact, beverages that have a spectrum with few differences are classified with lower accuracy.
It is worth observing how beverages such as still and sparkling water are well distinguished from the model. The presence of dissolved CO2 in sparkling water likely plays a key role in differentiating these two beverages. CO2 not only acidifies the water, potentially altering the solubility of various substances, but also generates bubbles that induce light scattering within the cuvette. This scattering is expected to modify the intensity profile detected by the sensor [36], providing distinguishable features between the still and the sparkling water, and, at the same time, creating confusion in the classification of other beverages. In particular, two beverages show noticeable confusion: Coca-Cola® being misclassified as Coca-Cola Zero Sugar® and vice versa. This is likely because their visible spectral profiles are very similar due to similar ingredients and composition.
Subsequently, we focused on optimizing the classification process while reducing the number of sensors required for measurement. In fact, using a smaller number of wavelengths can significantly reduce the costs associated with developing an IoT device while also lowering its power consumption. Additionally, analyzing fewer wavelengths decreases computational complexity, making data processing more efficient. As a result, this approach could not only minimize production and operational costs but also extends the battery life of an IoT device. Therefore, our purpose is to verify which and how many wavelengths are necessary to distinguish the drinks. In fact, as can be seen from the analysis of Figure 4, with this setup, some wavelengths show a greater difference in intensity between beverages making them ideal for classification. In contrast, at other wavelengths where intensity measurements overlap, the beverages become indistinguishable. To address this, we developed an algorithm to systematically evaluate all possible combinations of wavelengths and identify the configuration that maximizes the accuracy of the KNN model. Specifically, we utilized the itertools.combinations module to generate every possible combination of wavelengths, ranging from one wavelength configuration to those including all 18 available wavelengths. Using the same threefold cross-validation (kf = 3) employed in the previous model, we calculated the classification accuracy as a function of the number of wavelengths included in the model. This approach allowed us to identify the minimal set of wavelengths that preserved or enhanced classification accuracy while minimizing the complexity of the measurement system. In Figure 7 are reported the obtained results.
The table reveals an interesting trend regarding the impact of the number of sensors on model accuracy. Contrary to intuition, using all 18 sensors does not result in the highest accuracy for the KNN model. Instead, the accuracy improves as the number of sensors increases up to four or five sensors, after which it gradually declines. The best performance, combining high accuracy with the minimum number of optical channels, is achieved using four sensors. Specifically, selecting wavelengths at 460, 535, 610, and 810 nm yields an accuracy of 96.5% when K = 1. The fact that the best accuracy is not obtained with the maximum number of wavelengths indicates that not all channels contribute positively to the KNN model. Optical channels where the absorbed light intensity does not exhibit clear distinctions between beverage classes can introduce noise or ambiguity, leading to model confusion. This reduces classification accuracy by blurring the boundaries between different beverage categories.
After optimizing the use of sensors, we recalculated the confusion matrix, this time considering only the data corresponding to the four wavelengths (460, 535, 610, and 810 nm) that were identified as maximizing the model’s accuracy (Figure 8). By restricting the analysis to these selected wavelengths, we aimed to assess the effectiveness of the reduced dataset in maintaining high classification accuracy across all beverage classes.
A comparison with the confusion matrix generated using the full set of wavelengths (Figure 6) reveals some differences in performance when we consider only the optimized subset of wavelengths. While there is a general improvement in the model’s overall accuracy, this improvement is not evenly distributed across all the beverages tested. Specifically, the model shows enhanced ability to identify beverages such as Coca-Cola®, Coca-Cola Zero Sugar®, Schweppes®, Pepsi®, and cold peach tea, which now demonstrate clearer separation and reduced misclassification.
However, this improvement comes with certain trade-offs. Beverages such as beer and sparkling water are recognized with greater difficulty by the algorithm when using only the optimized wavelengths. This suggests that the model relies on information provided by the wavelengths excluded during optimization to distinguish these beverages.

4. Conclusions

In this paper, we introduced a novel approach for automatic beverage recognition, leveraging the combination of spectroscopic analysis and machine learning techniques. A spectrum consisting of 18 discrete wavelength points was captured using a commercial optical sensor, and the data was analyzed using a KNN machine learning model, achieving over 96% accuracy in distinguishing among a variety of commonly consumed beverages.
Moreover, this research paves the way for the development of compact, cost-effective, and automated mobile sensors capable of recognizing beverages in real time in smart cutlery tools like smart cups. Such devices could enable individuals to effortlessly monitor their nutritional drink intake, promoting healthier lifestyles and facilitating adherence to dietary plans. Future developments may extend this approach to include broader beverage categories, refine classification for challenging cases, and integrate additional sensor types or preprocessing methods to enhance robustness and reliability.

Supplementary Materials

The following supporting information can be downloaded at: https://www.mdpi.com/article/10.3390/s25144264/s1. Supplementary Figure S1. (a) Normalized beverage light absorption and (b) confusion matrix of the KNN model.

Author Contributions

Conceptualization, F.M. and L.M. (Luca Montaina); methodology, L.M. (Luca Montaina); software, L.M. (Luca Montaina); validation, L.M. (Luca Montaina) and F.M.; investigation, L.M. (Luca Montaina); resources, F.M. and L.M. (Luca Maiolo); data curation, L.M. (Luca Montaina); writing—original draft preparation, L.M. (Luca Montaina); writing—review and editing, E.P., I.L., F.M. and L.M. (Luca Maiolo); supervision, F.M.; project administration, F.M. and L.M. (Luca Maiolo); funding acquisition, F.M. All authors have read and agreed to the published version of the manuscript.

Funding

This research was partially funded by project PASTO—“Polyfunctional Assistant as Smart Tool for nutrition evaluation in Old adult” (CUP: B89J21031980005). The project was funded by National Research Council (CNR) under the call “Progetti@CNR”.

Institutional Review Board Statement

Not applicable.

Informed Consent Statement

Not applicable.

Data Availability Statement

Data presented in this study are openly available upon request.

Acknowledgments

The authors would like to thank Mattia Scagliotti for performing the measurement of the LED emission spectrum.

Conflicts of Interest

The authors declare no conflicts of interest.

Abbreviations

The following abbreviations are used in this manuscript:
IoTInternet of Things
CRIColor Rendering Index
KNNK-nearest neighbors
PMMAPoly(methyl methacrylate)

References

  1. Khot, R.A.; Mueller, F. Human-Food Interaction. Found. Trends® Hum.–Comput. Interact. 2019, 12, 238–415. [Google Scholar] [CrossRef]
  2. Peuhkuri, K.; Sihvola, N.; Korpela, R. Diet Promotes Sleep Duration and Quality. Nutr. Res. 2012, 32, 309–319. [Google Scholar] [CrossRef] [PubMed]
  3. St-Onge, M.P.; Mikic, A.; Pietrolungo, C.E. Effects of Diet on Sleep Quality. Adv. Nutr. 2016, 7, 938–949. [Google Scholar] [CrossRef]
  4. Bellisle, F. Effects of Diet on Behaviour and Cognition in Children. Br. J. Nutr. 2004, 92 (Suppl. S2), S227–S232. [Google Scholar] [CrossRef]
  5. Block, G.; Azar, K.M.J.; Romanelli, R.J.; Block, T.J.; Palaniappan, L.P.; Dolginsky, M.; Block, C.H. Improving Diet, Activity and Wellness in Adults at Risk of Diabetes: Randomized Controlled Trial. Nutr. Diabetes 2016, 6, e231. [Google Scholar] [CrossRef]
  6. Karlsson, J.; Hallgren, P.; Kral, J.; Lindroos, A.-K.; Sjöström, L.; Sullivan, M. Predictors and Effects of Long-Term Dieting on Mental Well-Being and Weight Loss in Obese Women. Appetite 1994, 23, 15–26. [Google Scholar] [CrossRef]
  7. Kontogianni, M.D.; Vijayakumar, A.; Rooney, C.; Noad, R.L.; Appleton, K.M.; McCarthy, D.; Donnelly, M.; Young, I.S.; McKinley, M.C.; McKeown, P.P.; et al. A High Polyphenol Diet Improves Psychological Well-Being: The Polyphenol Intervention Trial (PPhIT). Nutrients 2020, 12, 2445. [Google Scholar] [CrossRef]
  8. Esteban-Gonzalo, L.; Turner, A.I.; Torres, S.J.; Esteban-Cornejo, I.; Castro-Piñero, J.; Delgado-Alfonso, Á.; Marcos, A.; Gómez-Martínez, S.; Veiga, Ó.L. Diet Quality and Well-Being in Children and Adolescents: The UP&DOWN Longitudinal Study. Br. J. Nutr. 2018, 121, 221–231. [Google Scholar] [CrossRef]
  9. Katz, D.L.; Meller, S. Can We Say What Diet Is Best for Health? Annu. Rev. Public Health 2014, 35, 83–103. [Google Scholar] [CrossRef]
  10. Chapman, K. Can People Make Healthy Changes to Their Diet and Maintain Them in the Long Term? A Review of the Evidence. Appetite 2010, 54, 433–441. [Google Scholar] [CrossRef]
  11. de Ridder, D.; Kroese, F.; Evers, C.; Adriaanse, M.; Gillebaart, M. Healthy Diet: Health Impact, Prevalence, Correlates, and Interventions. Psychol. Health 2017, 32, 907–941. [Google Scholar] [CrossRef] [PubMed]
  12. Tan, M.; He, F.J.; MacGregor, G.A. Obesity and COVID-19: The Role of the Food Industry. BMJ 2020, 369, m2237. [Google Scholar] [CrossRef] [PubMed]
  13. Pahuja, V.; Sanghvi, S. Childhood Obesity in South Asian Population. Obes. Pillars 2024, 12, 100148. [Google Scholar] [CrossRef]
  14. Welsh, A.; Hammad, M.; Piña, I.L.; Kulinski, J. Obesity and Cardiovascular Health. Eur. J. Prev. Cardiol. 2024, 31, 1026–1035. [Google Scholar] [CrossRef]
  15. Agha, M.; Agha, R. The Rising Prevalence of Obesity: Part A: Impact on Public Health. Int. J. Surg. Oncol. 2017, 2, e17. [Google Scholar] [CrossRef]
  16. Burke, L.E.; Warziski, M.; Starrett, T.; Choo, J.; Music, E.; Sereika, S.; Stark, S.; Sevick, M.A. Self-Monitoring Dietary Intake: Current and Future Practices. J. Ren. Nutr. 2005, 15, 281–290. [Google Scholar] [CrossRef]
  17. Li, C.; Wang, J.; Wang, S.; Zhang, Y. A Review of IoT Applications in Healthcare. Neurocomputing 2024, 565, 127017. [Google Scholar] [CrossRef]
  18. Maiolo, L.; Maita, F.; Castiello, A.; Minotti, A.; Pecora, A. Highly Wearable Wireless Wristband for Monitoring Pilot Cardiac Activity and Muscle Fine Movements. In Proceedings of the 2017 IEEE International Workshop on Metrology for AeroSpace (MetroAeroSpace), Padua, Italy, 21–23 June 2017; pp. 271–275. [Google Scholar]
  19. Ferrone, A.; Maita, F.; Maiolo, L.; Arquilla, M.; Castiello, A.; Pecora, A.; Jiang, X.; Menon, C.; Ferrone, A.; Colace, L. Wearable Band for Hand Gesture Recognition Based on Strain Sensors. In Proceedings of the 2016 6th IEEE International Conference on Biomedical Robotics and Biomechatronics (BioRob), Singapore, 26–29 June 2016; pp. 1319–1322. [Google Scholar]
  20. Hutchesson, M.J.; Rollo, M.E.; Callister, R.; Collins, C.E. Self-Monitoring of Dietary Intake by Young Women: Online Food Records Completed on Computer or Smartphone are as Accurate as Paper-Based Food Records but More Acceptable. J. Acad. Nutr. Diet. 2015, 115, 87–94. [Google Scholar] [CrossRef]
  21. Päßler, S.; Wolff, M.; Fischer, W.-J. Food Intake Monitoring: An Acoustical Approach to Automated Food Intake Activity Detection and Classification of Consumed Food. Physiol. Meas. 2012, 33, 1073–1093. [Google Scholar] [CrossRef]
  22. Dalakleidi, K.V.; Papadelli, M.; Kapolos, I.; Papadimitriou, K. Applying Image-Based Food-Recognition Systems on Dietary Assessment: A Systematic Review. Adv. Nutr. 2022, 13, 2590–2619. [Google Scholar] [CrossRef]
  23. Rateni, G.; Dario, P.; Cavallo, F. Smartphone-Based Food Diagnostic Technologies: A Review. Sensors 2017, 17, 1453. [Google Scholar] [CrossRef] [PubMed]
  24. Ma, T.; Wang, H.; Wei, M.; Lan, T.; Wang, J.; Bao, S.; Ge, Q.; Fang, Y.; Sun, X. Application of Smart-Phone Use in Rapid Food Detection, Food Traceability Systems, and Personalized Diet Guidance, Making Our Diet More Health. Food Res. Int. 2022, 152, 110918. [Google Scholar] [CrossRef] [PubMed]
  25. Resende Silva, B.V.; Cui, J. A Survey on Automated Food Monitoring and Dietary Management Systems. J. Health Med. Inform. 2017, 8, 272. [Google Scholar] [CrossRef]
  26. Ams OSRAM. Available online: https://ams-osram.com/ (accessed on 14 March 2025).
  27. Suyal, M.; Goyal, P. A Review on Analysis of K-Nearest Neighbor Classification Machine Learning Algorithms Based on Supervised Learning. Int. J. Eng. Trends Technol. 2022, 70, 43–48. [Google Scholar] [CrossRef]
  28. Zhang, S.; Li, X.; Zong, M.; Zhu, X.; Wang, R. Efficient KNN Classification with Different Numbers of Nearest Neighbors. IEEE Trans. Neural Netw. Learn. Syst. 2018, 29, 1774–1785. [Google Scholar] [CrossRef]
  29. Shi, Y.; Yang, K.; Yang, Z.; Zhou, Y. Primer on Artificial Intelligence. In Mobile Edge Artificial Intelligence; Academic Press: Cambridge, MA, USA, 2022; pp. 7–36. [Google Scholar] [CrossRef]
  30. Guo, G.; Wang, H.; Bell, D.; Bi, Y.; Greer, K. KNN Model-Based Approach in Classification. In On the Move to Meaningful Internet Systems 2003: CoopIS, DOA, and ODBASE; Lecture Notes in Computer Science (including subseries Lecture Notes in Artificial Intelligence and Lecture Notes in Bioinformatics); Springer: Berlin/Heidelberg, Germany, 2003; Volume 2888, pp. 986–996. [Google Scholar] [CrossRef]
  31. Nti, I.K.; Nyarko-Boateng, O.; Aning, J. Performance of Machine Learning Algorithms with Different K Values in K-Fold CrossValidation. Int. J. Inf. Technol. Comput. Sci. 2021, 13, 61–71. [Google Scholar] [CrossRef]
  32. Steege, F.F.; Stephan, V.; Groß, H.M. The ‘K’ in K-Fold Cross Validation. In Proceedings of the European Symposium on Artificial Neural Networks, Computational Intelligence and Machine Learning, Bruges, Belgium, 25–27 April 2012; pp. 441–446. [Google Scholar]
  33. Wong, T.T.; Yeh, P.Y. Reliable Accuracy Estimates from K-Fold Cross Validation. IEEE Trans. Knowl. Data Eng. 2020, 32, 1586–1594. [Google Scholar] [CrossRef]
  34. Rodríguez, J.D.; Pérez, A.; Lozano, J.A. Sensitivity Analysis of K-Fold Cross Validation in Prediction Error Estimation. IEEE Trans. Pattern Anal. Mach. Intell. 2010, 32, 569–575. [Google Scholar] [CrossRef]
  35. Marcot, B.G.; Hanea, A.M. What Is an Optimal Value of k in K-Fold Cross-Validation in Discrete Bayesian Network Analysis? Comput. Stat. 2021, 36, 2009–2031. [Google Scholar] [CrossRef]
  36. Aluker, N.L.; Herrmann, M.; Suzdaltseva, J.M. Water Spectrophotometry in the UV and Visible Range as an Element of Water-Resource Ecoanalytics. Instrum. Exp. Tech. 2020, 63, 853–859. [Google Scholar] [CrossRef]
Figure 1. (a) Distribution of peak absorption for the AS7265x kit sensor [26] and (b) normalized emission spectra of the LED as measured with Photonic Multi-channel Analyzer PMA-12.
Figure 1. (a) Distribution of peak absorption for the AS7265x kit sensor [26] and (b) normalized emission spectra of the LED as measured with Photonic Multi-channel Analyzer PMA-12.
Sensors 25 04264 g001
Figure 2. (a) 3D renders and (b) photo of the system setup.
Figure 2. (a) 3D renders and (b) photo of the system setup.
Sensors 25 04264 g002
Figure 3. Two-dimensional example of KNN (K = 3) classification algorithm: (a) training dataset with two classes (labeled green and orange dots). (b) A new unclassified data is added to the graph (white dot) and compared with the 3 nearest neighbors. (c) The new data is then assigned to the category whose number of first neighbors is highest (green).
Figure 3. Two-dimensional example of KNN (K = 3) classification algorithm: (a) training dataset with two classes (labeled green and orange dots). (b) A new unclassified data is added to the graph (white dot) and compared with the 3 nearest neighbors. (c) The new data is then assigned to the category whose number of first neighbors is highest (green).
Sensors 25 04264 g003
Figure 4. Normalized beverage light absorption as a function of the wavelength.
Figure 4. Normalized beverage light absorption as a function of the wavelength.
Sensors 25 04264 g004
Figure 5. Accuracy of the KNN model as a function of the K nearest neighbors as average (red dots) respect to the several K-fold tests performed.
Figure 5. Accuracy of the KNN model as a function of the K nearest neighbors as average (red dots) respect to the several K-fold tests performed.
Sensors 25 04264 g005
Figure 6. Confusion matrix of the KNN model (K = 1), showing the classification performance across the different beverages.
Figure 6. Confusion matrix of the KNN model (K = 1), showing the classification performance across the different beverages.
Sensors 25 04264 g006
Figure 7. Accuracy of the KNN model as a function of the wavelengths combination.
Figure 7. Accuracy of the KNN model as a function of the wavelengths combination.
Sensors 25 04264 g007
Figure 8. Confusion matrix of the KNN model (K = 1), illustrating beverage classification performance using the optimized wavelengths (460, 535, 610, and 810 nm).
Figure 8. Confusion matrix of the KNN model (K = 1), illustrating beverage classification performance using the optimized wavelengths (460, 535, 610, and 810 nm).
Sensors 25 04264 g008
Table 1. List of beverages chosen to test the model.
Table 1. List of beverages chosen to test the model.
Beverage CategoryBeverage Type
WaterStill Water, Sparkling Water
Animal based MilkCow Milk
Plant based MilkOats Milk, Almond Milk
Soft DrinkCoca-Cola®, Coca-Cola Zero Sugar®, Pepsi®,
Schweppes®, Lemon Cold Tea, Peach Cold Tea
Alcoholic DrinkBeer, White Wine, Red Wine
Energy DrinkMonster Energy®, Red bull®
Sport DrinkGatorade®, Powerade®
Brewed DrinkCoffee
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Montaina, L.; Palmieri, E.; Lucarini, I.; Maiolo, L.; Maita, F. Toward a User-Accessible Spectroscopic Sensing Platform for Beverage Recognition Through K-Nearest Neighbors Algorithm. Sensors 2025, 25, 4264. https://doi.org/10.3390/s25144264

AMA Style

Montaina L, Palmieri E, Lucarini I, Maiolo L, Maita F. Toward a User-Accessible Spectroscopic Sensing Platform for Beverage Recognition Through K-Nearest Neighbors Algorithm. Sensors. 2025; 25(14):4264. https://doi.org/10.3390/s25144264

Chicago/Turabian Style

Montaina, Luca, Elena Palmieri, Ivano Lucarini, Luca Maiolo, and Francesco Maita. 2025. "Toward a User-Accessible Spectroscopic Sensing Platform for Beverage Recognition Through K-Nearest Neighbors Algorithm" Sensors 25, no. 14: 4264. https://doi.org/10.3390/s25144264

APA Style

Montaina, L., Palmieri, E., Lucarini, I., Maiolo, L., & Maita, F. (2025). Toward a User-Accessible Spectroscopic Sensing Platform for Beverage Recognition Through K-Nearest Neighbors Algorithm. Sensors, 25(14), 4264. https://doi.org/10.3390/s25144264

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop