Rapid identification method and system for food-borne pathogenic bacteria and spores based on Raman spectrum and machine learning
By optimizing Raman spectroscopy acquisition parameters and preprocessing methods, and combining the SPA-RF model and SHAP algorithm, the problem of redundant information in Raman spectroscopy data was solved, enabling efficient identification and data management of foodborne pathogens and spores, improving detection efficiency and accuracy, and constructing a convenient data management and decision support platform.
Patent Information
- Application Number
- CN202511063817.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-31
- Publication Date
- 2025-11-14
AI Technical Summary
In existing technologies, Raman spectroscopy data contains a lot of redundant information, making it difficult to automate processing and storage. This results in low detection efficiency and inaccurate results for foodborne pathogens and spores. Furthermore, Raman spectroscopy data is stored in a scattered manner and has inconsistent formats, making it difficult to share and manage.
By optimizing Raman spectroscopy acquisition parameters, using Savitzky-Golay smoothing, airPLS baseline correction, and Min-Max normalization preprocessing methods, and combining them with the continuous projection-random forest algorithm (SPA-RF) to construct a classification model, a Raman spectroscopy database system platform is established to realize cloud storage, automatic processing, and classification prediction of data.
It improves the efficiency and accuracy of microbial detection, with an identification rate of 97.43%, and enhances the interpretability of the model through the SHAP method, enabling rapid identification of high-throughput multi-class samples and building a convenient data management and decision support platform.
Smart Images

Figure CN120951040A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the technical field of machine learning and food safety detection, and in particular to a method and system for rapid identification of foodborne pathogens and spores. Background Technology
[0002] In recent years, foodborne pathogens and spores have become major factors causing food safety issues, seriously threatening public health. Foodborne pathogens secrete toxins or infect host cells, while spores, due to their strong resistance, are difficult to eradicate completely and produce toxins upon germination, posing a significant challenge to food safety control. How to achieve rapid detection and accurate identification of these pathogens has become a critical issue urgently needing resolution. Traditional methods suffer from drawbacks such as long detection cycles, cumbersome operations, and the inability to promptly confirm results, failing to meet the demands for rapid response. Raman spectroscopy, as a highly efficient molecular fingerprinting technology, has been widely used in the rapid detection of microorganisms. However, Raman spectroscopy data typically exhibits high dimensionality and significant redundant interference information. Traditional methods rely on manual experience for feature extraction and analysis, resulting in low efficiency and significant susceptibility to subjective factors. Traditional statistical methods also have obvious limitations, showing limited effectiveness when dealing with nonlinear relationships or complex sample structures, making Raman data analysis challenging. With the development of Raman spectroscopy instruments and the continuous enrichment of application scenarios, a large amount of Raman spectroscopy data is constantly being generated. Currently, Raman spectroscopy data suffers from problems such as fragmented storage, inconsistent formats, and a lack of standards, making it difficult to share data between different experiments. Furthermore, much valuable experimental data is often lost due to project completion and equipment upgrades, necessitating an effective platform for aggregation, storage, management, and sharing. The current lack of a mature automated comparison and identification platform limits its practical application in food safety testing. Summary of the Invention
[0003] To address the technical challenges of analyzing redundant information in the Raman spectra of foodborne pathogens and spores, and the difficulty in automating data storage and spectral analysis, this invention proposes a rapid identification method and system for foodborne pathogens and spores based on Raman spectroscopy and machine learning. This paper optimizes Raman spectral acquisition conditions, constructs a classification model based on the Successive Projections Algorithm-Random Forest (SPA-RF) algorithm, and finally builds a Raman spectral database system platform based on the classification model. This enables cloud storage, automatic processing, and classification prediction of Raman spectral data and models, improving the efficiency and accuracy of microbial detection and providing rapid and convenient technical support for food safety monitoring.
[0004] To achieve the above objectives, the technical solution of the present invention is implemented as follows:
[0005] A rapid identification method for foodborne pathogens and spores based on Raman spectroscopy and machine learning, comprising the following steps:
[0006] Step 1: Acquire and preprocess Raman spectroscopy data to obtain a Raman spectroscopy dataset;
[0007] Step 2: Construct a classification model based on SPA-RF: Use the continuous projection algorithm to extract features from the Raman spectral data, and use the random forest algorithm to classify the data after feature extraction;
[0008] Step 3: Train the SPA-RF-based classification model using the Raman spectroscopy dataset to obtain the best-performing model, and use the SHAP method to perform interpretability analysis on the best-performing model;
[0009] Step 4: Use the preprocessing method described in Step 1 to preprocess the unknown Raman spectral data samples to be classified, and then use the best-performing model to classify them to obtain the classification results.
[0010] Furthermore, when acquiring Raman spectral data, laser confocal laser was used. Al was selected as the substrate material, the excitation wavelength was 532 nm, the laser power was set to 50%, the integration time was 20 s, and the integration was performed once.
[0011] Furthermore, the preprocessing method is as follows: the original Raman spectral data is subjected to SG smoothing, the smoothed spectral data is baseline corrected using the adaptive iterative reweighted penalized least squares method, and the baseline corrected spectral data is normalized using maximum-minimum normalization.
[0012] Furthermore, the method for performing SG smoothing on the raw Raman spectral data is as follows: The original Raman spectral data is read from an Excel file using openpyxl; the raw data is converted into a numerical array using the NumPy or Pandas library, and key information is extracted; the savgol_filter function in the SciPy library is used to perform a smoothing operation based on the extracted key information array. At each position of the spectral data, a window of M points is expanded centered on that point, and an L-order polynomial is used to fit the data within the window. The calculated value of the fitted polynomial at the center point is taken as the smoothed value, and finally, the smoothed spectral data is output; the original spectrum and the smoothed spectral data are merged and saved into a new Excel file using the openpyxl or Pandas library.
[0013] Furthermore, the baseline correction method is as follows: The Pandas library is used to read the Excel file obtained from SG smoothing to obtain the SG-smoothed spectral intensity data; the NumPy library is used to encapsulate the airPLS algorithm into a callable function; the smoothed spectral intensity data y and data length n are input, and the smoothing parameter σ, maximum number of iterations, and convergence threshold are set; the airPLS algorithm function is called to obtain the final baseline estimate and the corrected spectrum; the smoothed spectral intensity data y, the final baseline estimate, and the corrected spectrum are merged into a table and saved as an Excel file.
[0014] Furthermore, the method for feature extraction of Raman spectral data using the continuous projection algorithm is as follows:
[0015] St1 sets the number of selected feature variables to N;
[0016] St2 randomly selects a wavelength λ from the preprocessed spectrum. i As initial feature variables, initialize the feature variable subset S1 = {λ} i};
[0017] St3 calculates the initial characteristic variables at all unselected wavelengths λ. j Projection vector on:
[0018]
[0019] in and It is the wavelength λ i The feature vector at that location, Representative eigenvector In the eigenvector The projection vector of the direction;
[0020] St4 calculates the initial characteristic variables at all unselected wavelengths λ. j The magnitude of the projection vector is used to select the wavelength with the longest projection as a new candidate feature variable and add it to the feature variable subset S. k ;
[0021] Step 5 repeats steps 2-4 until the number of selected candidate feature variables reaches the set value N;
[0022] St6 constructs a partial least squares regression model and measures the subset S of feature variables using the root mean square error of cross-validation. k Predictive ability;
[0023] St7 further uses the subset of feature variables corresponding to the smallest root mean square error as the final optimal feature set.
[0024] Furthermore, the method for interpretability analysis of the optimal model using the SHAP method is as follows: Given the constant term φ0, calculate the spectral characteristic variable λ for each variable using the Shapley value formula. i Marginal contribution to the prediction results:
[0025]
[0026] Where, φ i (λ i ) is the characteristic variable λ i The SHAP value is given by N, which is the set of all feature variables, totaling M features, and S, which does not include the feature variable λ. i Let f(S) be any subset of feature variables, and let f(S) be the predicted output of the model when using the subset of feature variables S. i}) is the characteristic variable λ i The predicted output of the model after adding a subset S of feature variables;
[0027] The constant term φ0 is added to the SHAP values of all feature variables according to the additive formula to obtain the prediction result of the SPA-RF-based classification model. The additive formula is as follows:
[0028]
[0029] β(λ) represents the prediction result of the classification model as expressed by the SHAP value.
[0030] Furthermore, it includes a browser layer, a data layer, and a service layer. The browser layer includes a multi-role login management module, a spectral data management module, a classification model management module, a data prediction function module, and a system function module that interact with the data layer and service layer through API interfaces.
[0031] Furthermore, the multi-role login management module includes an administrator module, an analyst module, and a regular user module, which are used to provide login access for administrators, analysts, and regular users, respectively, and to verify user identity information.
[0032] The spectral data management module includes a spectral data upload module, a data preprocessing module, and a data spectral display module. The spectral data upload module is used by analysts or administrators to upload Raman spectral data. The data preprocessing module is used by analysts or administrators to send Raman spectral data preprocessing requests to the server. The data spectral display module is used to display the original Raman spectral data, the preprocessed Raman spectral data, and to update and modify spectral data information.
[0033] Furthermore, the classification model management module includes a model file upload module, a model storage and management module, and a model information viewing module. The model file upload module is used to upload trained classification model files, the model storage and management module is used for classification model information management, and the model information viewing module is used to view classification model information.
[0034] The data prediction function module includes an unknown sample upload module, a prediction result output module, and a result display module. The unknown sample upload module is used by ordinary users to upload Raman spectral data of unknown classification types. The prediction result output module is used to send a request to the server to obtain the prediction result. The result display module is used to display the prediction result.
[0035] The system's functional modules include a system log module and a platform maintenance module. The system log module is used to view system operation logs, while the platform maintenance module is used to manage user permissions.
[0036] The service layer includes a service file system, a preprocessing module, and a classification module. The service file system is used to store the pre-trained classification model files and preprocessing algorithm files uploaded by users. The preprocessing module is used to execute the preprocessing algorithm files, and the classification module is used to execute the classification model files.
[0037] The beneficial effects of this invention are as follows:
[0038] To address issues such as inconsistent Raman spectral acquisition parameters and scattered preprocessing for pathogens and spores, this invention optimizes Raman spectral acquisition parameters and employs preprocessing methods such as Savitzky-Golay smoothing, airPLS baseline correction, and Min-Max normalization to process the original spectral data. The Raman peak positions of the preprocessed Raman spectra are then analyzed to provide reliable input data for subsequent modeling.
[0039] To reduce spectral redundancy and improve the recognition rate of pathogens and spores, this invention employs a combination of SPA-RF models for feature extraction and classification, reducing the number of features from 1400 to 169 while achieving the highest accuracy of 97.43%. SHAP is used to analyze the contribution of features from different bacteria, identifying important bands for model discrimination, improving model transparency, enhancing interpretability, and enabling rapid identification of high-throughput, multi-class samples.
[0040] This invention optimizes the Raman spectral acquisition parameters and data preprocessing process for foodborne pathogens and spores, deeply analyzes the Raman spectral attribution, obtains the characteristic spectra of different foodborne pathogens and spores, and constructs a classification and identification model for foodborne pathogens and spores through machine learning. Combined with interpretable algorithms, it reveals the correlation between the model's discrimination mechanism and bacterial biochemical components, laying the foundation for the accurate detection of foodborne pathogens and spores.
[0041] Based on functional requirements analysis, this invention constructs an integrated web platform that combines user login, data management, model management, and classification. The system integrates data uploading, storage, automatic preprocessing, and prediction functions through a visual interface. Testing has shown the platform to possess good practicality and stability. This platform not only provides an intelligent tool for processing and analyzing microbial Raman spectroscopy data but also offers a convenient and reliable data management and decision support platform for food safety testing and related research. Attached Figure Description
[0042] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0043] Figure 1 This is a flowchart of the identification method of the present invention.
[0044] Figure 2 This is the functional structure framework of the front-end browser layer in the recognition system of the present invention.
[0045] Figure 3 This is a schematic diagram of a B / S architecture.
[0046] Figure 4 This is a comparison of the Raman spectra of different substrate materials under different laser wavelengths according to the present invention. Figure 4 A is the SiO2 substrate material. Figure 4 B represents the Al substrate material, where the vertical axis represents intensity and the horizontal axis represents Raman shift.
[0047] Figure 5 This is a comparison of the Raman spectra of E. coli under different laser wavelengths for the substrate material Al of this invention. Figure 5 A represents the Raman spectra of E. coli at different wavelengths. Figure 5 B represents the repeatedly collected Raman spectrum of E. coli. Figure 5 C is 1681cm -1 Raman peak intensity.
[0048] Figure 6 This is a comparison of the Raman spectra of E. coli under different laser powers according to the present invention.
[0049] Figure 7 The Raman spectra of E. coli at different integration times are shown in this invention.
[0050] Figure 8This is a comparison chart of the preprocessing results of the present invention. Figure 8 A represents the original spectrum. Figure 8 B is the SG smoothing result plot. Figure 8 C represents the baseline correction result graph. Figure 8 D is the normalized result graph.
[0051] Figure 9 The Raman spectra of Gram-negative bacteria in the Raman spectroscopy comparison of foodborne pathogens in this invention are shown.
[0052] Figure 10 This is a Raman spectrum of Gram-positive bacteria in the Raman spectrum comparison of foodborne pathogens of the present invention.
[0053] Figure 11 This is the Raman spectrum of the food-derived spores of the present invention.
[0054] Figure 12 This is a characteristic wavelength extraction diagram of spectral data of foodborne pathogens and spores based on the SPA algorithm of the present invention. Figure 12 A represents the curve showing the relationship between the number of features and the root mean square error (RMSECV) of cross-validation. Figure 12 B represents the characteristic wavelength extracted by SPA, where...
[0055] Figure 13 This is a characteristic wavelength extraction diagram of spectral data of foodborne pathogens and spores based on the CARS algorithm of this invention. Figure 13 A is the curve showing the relationship between the number of Monrocat iterations and the number of variables. Figure 13 B is the curve showing the relationship between the number of Monrocat iterations and RMSECV. Figure 13 C represents the path of change in the regression coefficients. Figure 13 D represents the characteristic wavelength extracted by CARS.
[0056] Figure 14 This is a characteristic wavelength extraction diagram of spectral data of foodborne pathogens and spores based on the UVE algorithm of this invention. Figure 14 A represents the number of Monrocat iterations and the number of variables. Figure 14 B represents the Monrocat iteration number and RMSECV.
[0057] Figure 15 This is a bar chart illustrating the importance of SHAP features of Gram-negative bacteria according to the present invention, where the horizontal axis represents the mean of |SHAP value|, i.e., the average impact on the model output.
[0058] Figure 16 This is a bar chart illustrating the importance of SHAP features of Gram-positive bacteria according to the present invention, where the horizontal axis represents the mean of |SHAP value|, i.e., the average impact on the model output.
[0059] Figure 17This is a bar chart showing the importance of spore SHAP features in this invention, where the horizontal axis represents the mean of |SHAP values|, i.e., the average impact on the model output.
[0060] Figure 18 This is a summary diagram of the Gram-negative bacteria SHAP of the present invention.
[0061] Figure 19 This is a summary diagram of the Gram-positive bacteria SHAP of the present invention.
[0062] Figure 20 This is a summary diagram of the foodborne spores SHAP of the present invention. Detailed Implementation
[0063] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are within the scope of protection of the present invention. Raman spectroscopy, as a highly efficient molecular fingerprinting technology, has been widely used in the rapid detection of microorganisms. However, Raman spectroscopy itself contains a lot of redundant information, making the analysis of Raman data quite difficult.
[0064] Example 1
[0065] A rapid identification method for foodborne pathogens and spores based on Raman spectroscopy and machine learning, such as... Figure 1 As shown, the steps are as follows:
[0066] Step 1: Collect and preprocess Raman spectral data of foodborne pathogens and spores to obtain Raman spectral datasets and perform attribution analysis on the Raman spectral data.
[0067] S1.1 Material Preparation:
[0068] S1.11 Microbial strains sourced from: *Escherichia coli* ATCC 25922 (E. coli), *Staphylococcus aureus* ATCC 6538 (S. aureus), *Salmonella typhimurium* ATCC 14028 (S. typhimurium), *Listeria monocytogenes* (L. monocytogenes), *Pseudomonas aeruginosa* CICC 20576 (P. aeruginosa), *Shigella flexneri* CICC 10865 (S. flexneri), *Bacillus subtilis* CICC 10732 (B. subtilis), and *Bacillus cereus* CMCC. Clostridium perfringens (ATCC 13124, C. perfringens) and Clostridium sporogenes (CICC 22953, C. sporogenes) were all preserved in ceramic bead culture tubes at -80°C.
[0069] S1.12 Main reagents: Nutrient agar (NA) and enhanced clostridium tumefaciens medium (RCM) were purchased from Qingdao Haibo Biotechnology Co., Ltd.; LB broth, spore-forming medium, spore-promoting medium (DSM), liquid thioglycolate medium (FTG) and tryptone-sulfite-cycloserine agar (TSC) were purchased from Beijing Luqiao Technology Co., Ltd.
[0070] Quartz glass slides (SiO2 ≥ 99.99%), aluminum foil glass slides (Al ≥ 99.95%).
[0071] S1.13 The main equipment and instruments are shown in Table 1.
[0072] S1.2 Test Method:
[0073] S1.21 Methods for culturing foodborne pathogens and spores: Escherichia coli (E. coli), Staphylococcus aureus (S. aureus), Salmonella typhimurium (S. typhimurium), Listeria monocytogenes (L. monocytogenes), Pseudomonas aeruginosa (P. aeruginosa), Shigella flexneri (S. flexneri), Bacillus subtilis (B. subtilis), and Bacillus cereus (B. cereus) were streaked on NA medium overnight to obtain single colonies. Single colonies were selected and transferred to 20 mL of LB liquid medium and cultured for 8 h. 1 mL of bacterial culture was taken and washed 2-3 times with sterile water (7000 rpm, 3 min) and stored at 4 °C for later use.
[0074] Single colonies of *C. perfringens* and *C. sporogenes* were obtained by anaerobic overnight culture on TSC, FTG, and RCM plates, respectively. Single colonies were selected and transferred to 20 mL of FTG liquid medium for anaerobic culture for 8 h. 1 mL of the bacterial culture was then taken and treated in the same way.
[0075] S1.22 Cultivation method for foodborne spores: Streak B. subtilis ceramic beads on LB agar plates overnight. Select single colonies and transfer them to 20 mL of LB liquid medium for overnight incubation (200 rpm, 37℃). Then, transfer them to DSM medium at a 1:100 ratio and incubate (200 rpm, 37℃) for 24 h. Collection method A: Collect spores by centrifugation (8000 rpm, 10 min, 4℃), and wash 5-7 times with cold sterile deionized water to remove impurities such as vegetative cells from the spore suspension. After washing, examine under a microscope again. Only when ≥95% of the field of view consists of transparent spores and no visible small impurities can the spores be used.
[0076] C. perfringens ceramic beads were streaked on TSC plates overnight. Single colonies were selected and transferred to 20 mL of liquid mercaptoacetate broth (FTG) and incubated for 6 h. Then, the colonies were transferred to FTG medium at a 1:100 ratio and incubated for 24 h. The collection method was as described in Collection Method A.
[0077] Streak B. cereus on ceramic bead NA plates overnight. Select single colonies and transfer them to 20 mL of liquid nutrient broth (200 rpm, 37℃) and incubate for 6 h. Then, transfer them at a 1:100 ratio to NA plates supplemented with 10 g / L MnSO4·4H2O and incubate for 2-7 days. Collection method B involves washing colonies on the plate 3-4 times with sterile water (8000 rpm, 10 min, 4℃). After washing, examine under a microscope again. The plate can be used only when ≥95% of the field of view consists of clear spores and no visible small impurities.
[0078] Streak C. sporogenes ceramic beads on RCM plates overnight, select single colonies and transfer them to DSM plates for 2-7 days. Collect the colonies using the method described in Collection Method B.
[0079] Table 1 Main Instruments and Equipment
[0080]
[0081] S1.23 Initial parameter settings for laser confocal Raman spectroscopy acquisition: Before using the Raman spectrometer, first use a silicon wafer at a wavelength of 520.7 cm⁻¹. -1 The Raman peak at a certain point was used as a reference peak for instrument calibration. During Raman spectroscopy acquisition, 532nm, 633nm, and 785nm lasers were used as excitation sources, a 100x objective lens was selected, and the Raman spectroscopy scanning range was set to 400-1800 cm⁻¹. -1 Laser power 50%, integration time 10s, integration count 1.
[0082] S1.24 Acquisition of Raman spectra of sterile liquid substrate material: The substrate material was sampled 10 times with blank data according to the acquisition parameters described in step S1.23. Data preprocessing was performed using Python, and graphs were plotted using Origin 2024.
[0083] S1.25 Raman spectroscopy acquisition of bacterial culture substrate material: Add 1 μL of bacterial culture to the substrate material and let it air dry. Perform spectral acquisition 10 times according to the acquisition parameters described in step S1.23. Use Python for data preprocessing and Origin2024 for plotting.
[0084] The data preprocessing method is as follows: the original spectral data is smoothed using Savitzky-Golay (SG) using Python, the smoothed spectral data is baseline corrected using Adaptive Iteratively Reweighted Penalized Least Squares (airPLS), and the baseline corrected spectral data is normalized using Min-Max Normalization.
[0085] The SG smoothing method works by performing polynomial fitting on the signal within a locally sliding window, preserving the spectral morphology while reducing noise interference. The smoothing program consists of NumPy, Pandas, Matplotlib, SciPy, and the openpyxl data processing library. NumPy and Pandas are used for efficient processing of numerical and tabular data, Matplotlib is used for plotting spectral images, and openpyxl is used for reading and writing Excel files. The savgol filter function in the SciPy library implements the SG smoothing algorithm. This program sets the sliding window to 11 and the order to 3 to smooth the spectrum.
[0086] The specific steps are as follows: Use openpyxl to read the Excel file storing the raw Raman spectral data; use NumPy or Pandas to convert the read raw data into a numerical array and extract key information; use the savgol_filter function in the SciPy library to perform a smoothing operation based on the extracted key information array. At each position of the spectral data, expand a window of M=11 points centered on that point (the window will be automatically adjusted if the edge points are insufficient), fit the data within the window with an L=3rd degree polynomial, and take the calculated value of the fitted polynomial at the center point as the smoothed value. Finally, output the smoothed spectral data; use openpyxl or Pandas to merge the raw spectrum and the smoothed spectral data and save them as a new Excel file, and use Matplotlib to draw a comparison plot, displaying the raw spectrum and the smoothed spectral curves simultaneously.
[0087] Adaptive Iterative Reweighted Penalized Least Squares Method: In this embodiment, a Python script is used to construct the script, calling the NumPy and Pandas libraries for data manipulation. The airPLS optimization function is as follows:
[0088]
[0089] In the formula, y i z represents the intensity of the spectrum at the i-th wavelength. i To estimate the baseline value, w i λ represents the adaptively updated weight coefficients, and σ is the smoothing parameter. The optimal solution obtained through continuous iteration is the baseline.
[0090] Specifically, the implementation steps are as follows: Use the Pandas library to read the Excel file obtained by SG smoothing to obtain the SG smoothed spectral intensity data; use NumPy to wrap the airPLS algorithm into a callable function; input the smoothed spectral intensity data y and the data length n; set the smoothing parameter σ (1000), the maximum number of iterations (100), and the convergence threshold (1e-6); call the airPLS algorithm function to obtain the final baseline estimate and the corrected spectrum (equal to the smoothed spectral intensity data y minus the final baseline estimate); merge the smoothed spectral intensity data y, the final baseline estimate, and the corrected spectrum into a table and save it as an Excel file.
[0091] Interference from fluorescence background during bacterial and spore spectral acquisition causes baseline drift. To reduce this impact and improve the resolvability of spectral data and the accuracy of subsequent modeling, an adaptive iterative reweighted penalized least squares method was employed for baseline correction. This method does not rely on manually set reference points. It uses a constructed objective function with a penalty term to iteratively fit the spectral data, adjusting the weights during the iteration process to enhance the fitting ability.
[0092] Min-Max Normalization: The Raman spectral signal ranges of different bacteria vary between samples, necessitating standardized dimensions for comparative analysis. To improve the comparability of Raman spectra and the robustness of the model, Min-Max Normalization was employed. This method linearly scales the intensity values of each spectrum according to their maximum and minimum values, reducing them to the [0,1] interval, thus preserving the original spectral characteristics while standardizing the data magnitude. The normalization formula is:
[0093]
[0094] In the formula, x i Let x be the i-th spectral intensity value in the spectral data, and max(x) and min(x) represent the maximum and minimum values of that spectrum. i ′ represents the normalized value.
[0095] Determination of substrate material:
[0096] Comparative analysis of Raman spectra of different substrate materials (Al, SiO2) under different laser wavelengths, such as Figure 4 As shown, in order to select materials with less background interference and fewer Raman peaks as substrates for subsequent experiments, this invention compared and analyzed the Raman spectra of SiO2 and Al substrates under three laser excitation conditions of 532 nm, 633 nm, and 785 nm. Figure 4As shown in Figure A, under 532 nm laser excitation, the Raman spectrum of SiO2 exhibits clear characteristic peaks, mainly located at 580 cm⁻¹. -1 800cm -1 and 1100cm -1 At this point, the peak intensity distribution is between 1000-1500 a.u., and the baseline shows some degree of drift, but the impact is small. As the laser wavelength is adjusted to 633 nm, SiO2 exhibits more characteristic peaks, especially at 1500 cm⁻¹. -1 and 1650cm -1 Two new Raman peaks were added, resulting in a more complex spectral morphology compared to the 532 nm excitation condition. Under 785 nm laser excitation, the SiO2 Raman spectrum showed a significant baseline shift, particularly at 1400 cm⁻¹. -1 A strong Raman peak appeared nearby, but this peak was not significant under the excitation conditions of 532 nm and 633 nm, which may have some impact on the spectral analysis of the sample. Compared with SiO2, the Raman spectral intensity of the Al substrate is relatively weak. Figure 4 As shown in Figure B, under 532 nm laser excitation, the Raman intensity of Al remained generally within the range of 140–420 a.u., the Raman spectral baseline was relatively stable without significant drift, and remained above 700 cm⁻¹. -1 and 800cm -1 Al exhibits its characteristic Raman peak at 633 nm. When the excitation wavelength increases to 633 nm, the Raman signal intensity of Al increases, and it peaks at 600–800 cm⁻¹. -1 A new characteristic peak appears in the region, which may have some impact on the Raman peak position resolution of the sample. Under the excitation condition of 785 nm, the Raman spectral intensity of Al gradually decreases with increasing shift, while the baseline drift is quite obvious.
[0097] In summary, the Raman spectral intensity of Al substrate material is generally lower than that of SiO2, the number of Raman peaks at the three excitation wavelengths is relatively smaller, and the overall peak shape flatness is better than that of SiO2. Therefore, Al is selected as the substrate material in this invention.
[0098] Determining the laser wavelength:
[0099] The effect of laser wavelength on bacterial Raman spectra, such as Figure 5 As shown. To compare the effects of different laser wavelengths on the Raman spectrum of E. coli and to screen for the optimal excitation wavelength, this invention uses Al as the substrate material as a reference and, while keeping other parameters constant, compares the spectral performance and stability under three laser excitation conditions: 532 nm, 633 nm, and 785 nm. Figure 5As shown in Figure A, under 532 nm laser excitation, the Raman spectrum of *E. coli* exhibits a relatively stable baseline without significant drift. The characteristic peaks in the spectrum are clearly positioned, with minimal interference between peaks, and the signal amplitude is relatively stable, which is beneficial for subsequent spectral analysis. Under 633 nm excitation, a slight drift occurs in the Raman spectrum baseline, and this drift is observed at 850 cm⁻¹. -1 The spectrum is affected by Al characteristic peaks. Although some characteristic peaks of E. coli can still be observed, the peak shapes are not as clear as under the 532 nm excitation condition. Under 785 nm excitation, the baseline drift of E. coli is more severe, the Raman characteristic peak signal is weaker, and the overall spectral signal is poor. Therefore, the spectrum under 785 nm laser excitation is not conducive to in-depth analysis of bacterial Raman spectra.
[0100] To further screen for the optimal laser wavelength, under the same experimental parameters, the wavelength of E. coli at 1681 cm⁻¹ was compared. -1 The characteristic peak at the specified location was analyzed by relative standard deviation (RSD), and the results are as follows: Figure 5 As shown in Figure B, under 532 nm laser excitation, the differences between the various spectra are small, and the fluctuation range of peak intensity is stable. This is further demonstrated by analyzing the 1681 cm⁻¹ spectrum. -1 The characteristic peak RSD was calculated to be 7.85%. In contrast, the differences between different spectra under the 633 nm excitation condition were more obvious, the repeatability was relatively low, and the characteristic peak of the E. coli Raman spectrum was more blurred and overlapped with other interfering signals, with an RSD of 15.26% under the 633 nm excitation condition. Therefore, the Raman spectrum under the 532 nm excitation wavelength is superior in terms of repeatability and stability, so 532 nm was selected as the standard excitation wavelength for subsequent bacterial and spore Raman spectra.
[0101] Determining the laser power:
[0102] Based on the substrate material Al and laser wavelength of 532nm determined in the above experiments, and keeping other parameters unchanged, Raman spectra were collected on E. coli bacterial culture samples using six laser powers of 1%, 5%, 10%, 25%, 50%, and 100%. The data preprocessing and chart plotting methods were the same as above.
[0103] The effect of laser power on the Raman spectral signal intensity of E. coli bacterial culture is as follows: Figure 6 As shown. To investigate the effect of laser power on the Raman spectrum of E. coli, this invention analyzed the stability and clarity of the bacterial Raman signal under different laser power conditions. Figure 6As shown, the Raman spectrum of *E. coli* exhibits significant changes with varying laser power. At low powers of 1% and 5%, the Raman spectrum is severely affected by noise, and the baseline shows significant drift, greatly reducing the stability of the Raman spectrum. Under low power conditions, the Raman signal is weak, making it difficult to distinguish the bacterial characteristic peaks from the background noise, thus affecting subsequent experimental analysis. As the laser power gradually increases to 10%, 25%, and 50%, the Raman spectrum of *E. coli* gradually becomes clearer, the characteristic peaks become sharper in the spectrum, and the Raman peak intensity gradually increases. This change indicates that increasing the laser power can effectively improve the quality of the Raman spectrum, making the bacterial Raman characteristic peaks easier to resolve. When the laser power increases to 100%, the Raman spectrum shows significant distortion, possibly because the power exceeds the tolerance range of the bacteria, leading to carbonization of the cell structure, thus causing the Raman spectrum to no longer present complete bacterial biological information. Based on the above analysis, the optimal laser power should be 50%. At this power, the Raman spectrum can clearly show the characteristic peaks of bacteria, and the signal intensity is moderate, avoiding sample damage caused by high power.
[0104] Determining the integration time:
[0105] Based on the substrate material Al, laser wavelength of 532 nm, and laser power of 50% determined in the above experiments, Raman spectra were acquired on E. coli bacterial culture samples using four integration durations of 10 s, 15 s, 20 s, and 25 s while keeping other parameters unchanged. The data preprocessing and chart plotting methods were the same as above.
[0106] To investigate the effect of integration time on the Raman spectral quality of E. coli, this invention analyzes the intensity, resolution, and signal stability of bacterial Raman spectra at different integration times. For example... Figure 7 As shown, the Raman spectral intensity of *E. coli* gradually increases with increasing integration time, and the resolution of the characteristic peaks also improves accordingly. At an integration time of 10 s, the Raman spectral signal of *E. coli* is weak, and the resolution of the characteristic peaks is relatively poor. This is because the short integration time leads to weak signal stability. When the integration time increases to 15 s, the Raman spectral signal intensity strengthens, and the characteristic peaks gradually become clearer. With an integration time of 20 s, the Raman spectrum of *E. coli* significantly improves, and the signal intensity increases substantially. Under this condition, even the weak characteristic peaks gradually appear, maximizing the display of bacterial information. However, when the integration time is 30 s, the excessively long integration time causes photodegradation of biomolecules in the sample, resulting in bacterial structural damage and an inability to reflect accurate biological information.
[0107] After experimental optimization and comparative analysis, and ensuring the reliability and repeatability of the data, the optimal bacterial Raman spectroscopy acquisition parameters were determined as follows: Al was selected as the substrate material, the excitation wavelength was 532 nm, the laser power was set to 50%, the integration time was 20 s, and the integration count was 1. These parameters were then used for subsequent acquisition of foodborne pathogens and spores.
[0108] Preprocessing and attribution analysis of Raman spectral data of foodborne pathogens and spores:
[0109] Using experimentally optimized Raman spectroscopy acquisition parameters, Raman spectra were acquired for *E. coli*, *S. aureus*, *S. typhimurium*, *L. monocytogenes*, *P. aeruginosa*, *S. flexneri*, *B. subtilis*, *B. cereus*, *C. perfringens*, *C. sporogenes*, and their corresponding spores. One hundred spectra were acquired for each species, and the obtained data were subjected to SG smoothing, baseline correction, and normalization.
[0110] like Figure 8 As shown in A, there are 10 raw Raman spectra without any processing. Raw spectra usually contain noise, fluorescence, cosmic rays and other interferences, which cause large fluctuations in the signal and make it difficult to accurately analyze the raw spectra. Figure 2-5 B shows the Raman spectrum after SG smoothing. As can be seen from the figure, the noise in the spectrum has been effectively removed, and the signal is smoother, which is helpful for the subsequent analysis of characteristic peaks. Figure 8 C shows the baseline-corrected Raman spectrum. Baseline correction flattens the spectrum baseline, reduces background interference, ensures signal accuracy, avoids analytical errors caused by baseline fluctuations, and makes characteristic peaks more obvious. Figure 8 D shows the spectra after maxima-minus normalization. Spectra processed in this way can be directly compared, eliminating unavoidable influences from experimental conditions. All bacterial and spore spectral data underwent this preprocessing, and the preprocessed Raman spectra were analyzed.
[0111] from Figure 9 and Figure 10 As can be seen, the Raman spectra of Gram-negative and Gram-positive bacteria show certain similarities in overall peak shape distribution, both exhibiting multiple distinct characteristic Raman peaks covering the 400–1800 cm⁻¹ range. -1The wavenumber range reflects the common vibrational characteristics of biomolecules such as proteins, lipids, and polysaccharides in bacteria. Different strains exhibit variations in peak position and intensity, reflecting differences in cell wall composition, metabolites, and molecular structure. Analysis of the attribution of these Raman characteristic peaks can further explore the differences in biochemical composition and function among different bacterial species, providing a foundation for Raman spectroscopy-based bacterial classification and identification.
[0112] Table 2. Assignment of Raman peaks for Gram-negative bacteria
[0113]
[0114] Note: G - 1 represents E. coli, G. - 2 represents S. typhimurium, G - 3 represents P. aeruginosa, G - 4 represents S.flexneri.
[0115] Analysis of Table 2 reveals that these four bacteria share common molecular compositional characteristics while also exhibiting unique differences in each individual bacterium. All four Gram-negative bacteria have a molecular weight range of 426-437 cm⁻¹. -1 891-900cm -1 1008-1009cm -1 1240cm -1 1543-1545, 1575-1586cm -1 1663-1673cm -1 These ranges all contain corresponding Raman peaks, corresponding to SS stretching vibration, COC stretching vibration, phenylalanine cyclic respiration vibration, CH2 / CH3 bending vibration, and protein secondary structure, respectively. These shared peaks reveal the chemical commonalities of Gram-negative bacteria at the molecular level, including proteins, polysaccharides, and lipids. These four bacteria also exhibit their own unique peak positions; for example, E. coli has a peak at 1719 cm⁻¹. -1 Lipid C=O stretching exhibits unique characteristics; the polysaccharide structure of *P. aeruginosa* at 972 cm⁻¹ is significantly different from that of other bacteria; *S. flexneri* at 1673 cm⁻¹... -1 They also showed differences in protein conformation compared to the other three bacteria. In summary, the four Gram-negative bacteria exhibited common chemical characteristics in Raman spectra, but also showed differences between bacterial species at certain specific peaks.
[0116] Table 3. Assignment of Raman peaks for Gram-positive bacteria
[0117]
[0118] Note: G + 1 represents S. aureus, G + 2 represents L. monocytogenes, G + 3 represents B. subtilis, G. + 4 represents B. cereus, G + 5 represents C. perfringens, G + 6 represents C. sporogenes.
[0119] Analysis of Table 3 showed that the six Gram-positive bacteria were most abundant at 432-438 cm⁻¹. -1 527-539cm -1 815-827cm -1 1008-1010cm -1 1240-1245cm -1 1445-1463cm -1 1663-1669cm -1 Both bacteria exhibit Raman peaks, corresponding to disulfide bonds, C-C vibrations, CO-C stretching vibrations, phenylalanine cyclic respiration vibrations, protein secondary structures, and lipid CH2 / CH3 bending vibrations, respectively. Compared to Gram-negative bacteria, the shared Raman peaks also differ, primarily concentrated in the carbohydrate-specific region of 800-900 cm⁻¹, while Gram-positive bacteria show peaks of 815–827 cm⁻¹. -1 The band exhibits a shared Raman response, a peak that can be attributed to the vibration of the glycosyl backbone in the peptidoglycan structure of its cell wall. Gram-negative bacteria, on the other hand, show a response at 891–900 cm⁻¹. -1 They exhibit common characteristic peaks, corresponding to the glycosyl structure vibrations in the lipopolysaccharide molecules in their outer membrane.
[0120] Each Gram-positive bacterium also has its own unique Raman peak; for example, S. aureus has a peak at 495 cm⁻¹. -1 The peak at 911 cm⁻¹ is significant and related to its cell wall structure, while L. monocytogenes shows a peak at 911 cm⁻¹. -1 The presence of characteristic vibrational peaks in glycocyclic structures suggests that the cell surface may be rich in polysaccharides or glycopeptides with specific conformations. *B. subtilis* shows a peak at 1751 cm⁻¹. -1 A strong C=O stretching vibration peak is observed at 921 cm⁻¹, corresponding to the carbonyl structure in lipid components. B. cereus exhibits this peak at 921 cm⁻¹. -1 It also exhibits glycocycle vibration characteristics, but its glycoside conformation differs from that of L. monocytogenes, and C. perfringens has a 937 cm⁻¹. -1The characteristic peak at 1613 cm⁻¹ also belongs to the glycocycle vibration; C. sporogenes at 1613 cm⁻¹ -1 The region then displays aromatic C=C stretching vibration peaks. These subtle differences provide a basis for identifying foodborne pathogens using Raman spectroscopy.
[0121] Raman spectral analysis of foodborne spores:
[0122] from Figure 11 It can be seen that the Raman spectra of spores differ significantly from those of their corresponding bacterial states in terms of overall morphology and number of peaks. Compared with vegetative bacteria, spore Raman spectra have fewer peaks and higher separation, which may be related to factors such as dehydration and weaker metabolic activity during spore formation.
[0123] Table 3. Attribution of Raman peaks from foodborne spores
[0124]
[0125] Table 3 (continued) Assignment of Raman peaks from foodborne spores
[0126]
[0127]
[0128] Note: SP1 represents B. subtilis spore, SP2 represents B. cereus spore, SP3 represents C. perfringens spore, and SP4 represents C. sporogenes spore.
[0129] Analysis of the Raman spectra of the foodborne spores in Table 3 revealed that all spores were within the range of 10¹⁶-10¹⁷ cm⁻¹. -1 1442-1447cm -1 The presence of Raman characteristic peaks at these locations, both of which can be attributed to DPA, is the chemical basis for the high stress resistance of the spores. In addition, at 818-894 cm⁻¹... -1 1236-1240cm -1 1572-1575cm -1 These peaks also appear in the Raman spectra of all spores, corresponding to protein secondary structures and biomacromolecules such as lipids. Each spore also has its own unique Raman peak, such as the 948 cm⁻¹ peak of B. subtilis spore. -1 The polysaccharide C–O / C–C stretching vibration, 1150 cm⁻¹ of B. cereus spores -1The Raman spectra of foodborne spores exhibit not only common characteristic peaks related to DPA (dihydropyridine) but also common vibrational features of biomolecules, providing spectroscopic evidence for the overall molecular composition of spores. The Raman peaks specific to different bacterial species further demonstrate the differences in their molecular structure, providing an important theoretical basis for the rapid identification and classification of spores based on Raman spectroscopy.
[0130] By analyzing the Raman spectra, we can gain a deeper understanding of the compositional characteristics of bacteria and spores at the molecular level, identifying common and dissimilar peaks in their spectra. These spectral differences not only reflect changes in chemical composition under different physiological states but also provide theoretical support and a spectroscopic foundation for subsequent data modeling, feature extraction, and classification.
[0131] Step 2: Construct a classification model based on SPA-RF: Use the continuous projection algorithm (SPA) to extract features from the Raman spectral data, and use the random forest (RF) algorithm to classify the data after feature extraction.
[0132] The data were derived from 1400 Raman spectra obtained in step S1, covering 10 types of foodborne pathogens and 4 types of foodborne spores. All data underwent preprocessing operations such as SG smoothing, baseline correction, and normalization.
[0133] To determine the optimal classification model through experiments, this invention employs three feature selection methods: Continuous Projection Algorithm (SPA), Competitive Adaptive Reweighted Sampling (CARS), and Unrelated Variable Elimination (UVE). Three classification models—K-Nearest Neighbors (KNN), Support Vector Machine (SVC), and Random Forest (RF)—are used to model the extracted features. The combined effects of different feature extraction methods and classification models are compared using metrics such as classification accuracy (ACC) and confusion matrix to select the optimal model.
[0134] Continuous Projection (SPA) is a commonly used feature selection algorithm in spectroscopy. It filters representative features through successive projection, avoiding multicollinearity among features. Starting with a random band, in each iteration, the wavelength with the largest projection vector is selected as the candidate feature wavelength by calculating the projection vector between variables. Subsequently, it is evaluated using the RMSECV of the calibration model, and finally, the optimal feature wavelength is selected. The SPA feature extraction steps are as follows:
[0135] St1 sets the number of selected feature variables to N;
[0136] St2 randomly selects a wavelength λ from the preprocessed spectrum. iAs initial feature variables, initialize the feature variable subset S1 = {λ} i};
[0137] St3 calculates the initial characteristic variables at all unselected wavelengths λ. j Projection vector on:
[0138]
[0139] in and It is the wavelength λ i The feature vector at that location, Representative eigenvector In the eigenvector The projection vector of the direction.
[0140] St4 calculates the initial characteristic variables at all unselected wavelengths λ. j The magnitude of the projection vector is used to select the wavelength with the longest projection as a new candidate feature variable and add it to the feature variable subset S. k (k = 1, 2, ..., N) to ensure that the selected feature vectors have the greatest information contribution and to minimize collinearity among feature vectors:
[0141]
[0142] St5, repeat steps St2-St4 until the number of selected candidate feature variables reaches the set value N, thus obtaining N wavelength combinations with the most feature contribution.
[0143] St6 constructs a partial least squares regression model and measures the subset S of feature variables using the root mean square error of cross-validation (RMSECV). k Its predictive ability.
[0144] St7 uses the subset of feature variables corresponding to the smallest RMSECV as the final optimal feature set.
[0145] Before classification, the dataset was randomly divided into training and test sets in a 4:1 ratio. Three classification models, KNN, SVM and RF, were used. The classification performance of the models was measured by calculating the accuracy of the models, and the performance of the three models was compared.
[0146] Random Forest (RF): Random Forest (RF) is a machine learning algorithm based on ensemble learning. Its core idea is to improve the model's generalization ability and robustness by constructing decision trees and aggregating prediction results. Compared to a single decision tree, Random Forest improves model accuracy and reduces overfitting through data and feature randomness. Its principle is to randomly sample multiple subsets of data (the same number as the original data) using Bootstrap sampling. During each training iteration, a subset of features is used to train separate decision trees for classification, ultimately forming a decision forest. The trees are grown to retain maximum information without pruning, and the classification task is completed through majority voting.
[0147] Feature extraction result analysis:
[0148] Feature wavelength extraction from spectral data of foodborne pathogens and spores based on the SPA algorithm, such as... Figure 12 As shown. Figure 12 A shows the relationship between the number of selected features and RMSECV. As the number of features increases, RMSECV gradually decreases and reaches its lowest point when the number of features reaches 169. This indicates that the evaluation model achieves the best generalization ability when the number of features is 169, and the extracted features can effectively capture the information of the target variable. As the number of features further increases, RMSECV further increases, indicating that the introduction of redundant information reduces the model performance.
[0149] Figure 12 Figure B shows the visual annotations of the feature variables extracted by SPA (red circles) on the average spectrum (black curve). This figure intuitively shows the key Raman shifts retained by the SPA method during feature selection, with most feature points concentrated in the 1000–1800 cm⁻¹ range. -1 In this region, which is related to cell wall components and metabolic activity, the feature space was effectively compressed using the SPA algorithm, reducing the number of features from 1400 to 169.
[0150] Feature wavelength extraction from spectral data of foodborne pathogens and spores based on the CARS algorithm, such as... Figure 13 As shown. Figure 13 A illustrates the relationship between the number of Monte Carlo samplings and the number of selected features. As the number of Monte Carlo samplings increases, the number of sampled variables gradually decreases from 1400 to 165 and then plateaus. This change indicates that this process removes redundant information, compresses the feature space, and improves the efficiency and accuracy of subsequent analysis.
[0151] Figure 13B shows the relationship between RMSECV and the number of Monte Carlo samplings. In the initial stage, as the subset of key features is gradually diluted, RMSECV decreases with the increase of the number of Monte Carlo samplings, which indicates that the model's predictive ability gradually improves. RMSECV reaches its lowest point and tends to stabilize at about 19 samplings, which indicates that the core features have been sufficiently screened after 19 samplings, and further feature selection may lead to the loss of key information.
[0152] Figure 13 C shows the evolution path of the regression coefficients. The regression coefficients remained stable before the 19th sampling, indicating that the selected features made consistent contributions to the model. The coefficients began to change significantly after about the 19th sampling, further confirming that feature selection was completed at the 19th sampling.
[0153] Figure 13 D shows the distribution of the characteristic variables (green circles) screened by CARS on the average spectrum (black curve), with the characteristic range concentrated in the 400–600 cm⁻¹ region. -1 800cm -1 1100cm -1 and 1300-1600cm -1 Within these intervals, the bacteria encompass abundant biological information in the form of spores. Through the CARS feature selection process, the number of features was reduced from 1400 to 165, achieving a significant dimensionality reduction.
[0154] Feature wavelength extraction from spectral data of foodborne pathogens and spores based on the UVE algorithm, such as... Figure 14 As shown. Figure 14 As shown in Figure A, the black dot region represents the stable distribution of Raman spectral features, while the blue region represents random noise added based on the original data. The UVE algorithm filters the original features by comparing the stability of the real variables and random variables during the modeling process. The positive and negative thresholds for adding noise to the spectral data in UVE are between -166 and 166, respectively. Wavelengths outside this range are considered to be variables with modeling value and are retained, while variables within this range are considered to be irrelevant variables without discriminative information and are deleted.
[0155] Figure 14 Figure B shows the distribution of the 540 feature variables finally selected by UVE in the average Raman spectrum. Compared with other feature extraction algorithms, UVE retains more features, which helps to retain potential information to the greatest extent.
[0156] Step 3: Train the SPA-RF-based classification model using the Raman spectroscopy dataset to obtain the best-performing model, and use the SHAP method to perform interpretability analysis on the best-performing model.
[0157] In this invention, Shapley Additive Explanations (SHAP) are chosen to interpret the model's output. The core idea of SHAP is to help understand complex machine learning models by calculating the contribution of each feature to the prediction result.
[0158] The SHAP method for interpretability analysis is as follows:
[0159] The constant term φ0 is determined, representing the limiting prediction value when there are no features. The Shapley value formula is used to calculate the spectral characteristic variable λ. i Marginal contribution to the prediction results:
[0160]
[0161] Where, φ i (λ i ) is the characteristic variable λ i The SHAP value is given by N, which is the set of all feature variables, totaling M features, and S, which does not include the feature variable λ. i Let f(S) be any subset of feature variables, and let f(S) be the predicted output of the model when using the subset of feature variables S. i}) is the characteristic variable λ i The predicted output of the model after adding a subset S of feature variables. This is called using the shap library in Python.
[0162] By adding the constant term φ0 to the SHAP values of all feature variables using the additive formula, we obtain the prediction result of the classification model represented by the SHAP values:
[0163]
[0164] Each SHAP value φ i (λ i The feature variable λ was quantified. i The contribution to the prediction, thereby enabling the interpretation of the model's predictions.
[0165] Results Analysis: Raman Spectroscopy Classification Model of Foodborne Pathogens and Spores Based on KNN Algorithm: Table 3-1 shows the performance comparison of the KNN classification model against the classification models constructed by three feature selection methods. The effectiveness of the feature selection methods and the model performance are evaluated by comparing the accuracy classification index. Although the untreated group performed well (95.71%), the large number of features resulted in a high computational cost. The SPA model showed improved performance compared to the untreated group (96.02%), indicating that this method eliminated interfering features. However, compared to the CARS method, the latter's ability to extract effective information was better in the KNN model, achieving the highest test set accuracy (96.57%) in the minimum feature set, indicating that this method can effectively screen key features and improve the model's generalization ability. For UVE, although the number of features was reduced by 61%, it still contained a lot of redundant information, resulting in the weakest test set performance.
[0166] Raman spectroscopy classification models for foodborne pathogens and spores based on the SVM algorithm: Table 3-2 shows a performance comparison of the SVM classification model against classification models constructed using three feature selection methods. Compared to the unprocessed KNN, the SVM classification model shows a certain improvement in accuracy. The SPA-processed data achieved the highest test set accuracy; compared to SPA-KNN, the features extracted by SPA are more suitable for SVM. The CARS-SVM test set performance decreased significantly compared to the training set, indicating that the CARS method may have lost key feature vectors of SVM, leading to a degraded classification effect. The UVE-SVM performance is second only to SPA-SVM, but it has a larger number of features and higher computational cost.
[0167] Table 3-1 Performance of KNN classification model
[0168]
[0169] Table 3-2 Performance of SVM Classification Model
[0170]
[0171]
[0172] Raman spectroscopy classification models for foodborne pathogens and spores based on the RF algorithm: Table 3-3 shows the performance comparison of the RF classification model against classification models constructed using three feature selection methods. Compared with the two classifiers mentioned above, the RF classifier shows improved performance on the training set, achieving an accuracy of 100%. SPA-RF performs best on the training set, indicating that the combination of these two methods has the strongest generalization ability; the unprocessed model has the same accuracy as CARS, while UVE-RF performs the worst. In summary, by comparing the classification performance of KNN, SVM, and RF models under different feature selection methods, and considering computational efficiency, classification accuracy, and generalization ability, SPA-RF was ultimately selected as the optimal classification model for subsequent research and analysis.
[0173] Table 3-3 Performance of RF Classification Model
[0174]
[0175] Interpretability analysis of the SPA-RF classification model:
[0176] To gain a deeper understanding of the decision-making mechanism of the SPA-RF model, this invention employs SHAP (Shape-Based Allocation) to quantify feature contributions. All features are sorted according to the mean absolute SHAP value, and the top 10 features by SHAP contribution are selected for visual analysis. The higher-ranking features indicate that they play a more significant role in model prediction.
[0177] Analysis of the Importance of Spectral Characteristics of Gram-Negative Bacteria: From Figure 15 It can be seen that the contributions of the 10 Raman features differ significantly among Gram-negative bacteria. Among them, feature N1 (832 cm⁻¹) shows the highest contribution. -1 N2 (495cm) -1 N3 (1028cm) -1 N4 (900cm) -1 The four proteins (C, C, and D) have the highest contribution rates, corresponding to the tyrosine loop respiratory pattern, CS stretching vibration, phenylalanine loop respiratory pattern, and CC skeletal stretching vibration, respectively. This indicates that protein composition, structure, and metabolic activity play a crucial role in bacterial classification. Slight differences exist among different bacterial species in the expression of membrane proteins, cytoplasmic proteins, and specific functional proteins, providing potential classification criteria for the identification of Gram-negative bacteria.
[0178] Analysis of the Importance of Spectral Characteristics of Gram-Positive Bacteria: From Figure 16 It can be seen that the features contributing significantly to Gram-positive bacteria differ considerably from those of Gram-negative bacteria. Analysis of the top five features contributing to Gram-positive bacteria reveals that these features primarily involve the vibrational patterns of proteins, peptidoglycans, and aromatic amino acids, and are closely related to cell wall composition and metabolic characteristics. Among these, the CH3 symmetric deformation vibration (1380 cm⁻¹) is particularly significant.-1 The signal in this band is mainly derived from proteins and peptidoglycans. Because Gram-positive bacteria have a thicker peptidoglycan layer, this band has a stronger signal and can serve as an important marker for distinguishing between Gram-positive and Gram-negative bacteria. CN stretching vibration (1216 cm⁻¹) -1 The peak, primarily derived from amide bonds, reflects the structure of peptidoglycans and proteins, thus playing a role in the classification of Gram-positive bacteria; CS stretching vibration (631 cm⁻¹) -1 It is related to disulfide bonds in proteins, which are crucial for protein stability and may affect the structure and function of bacterial outer membrane proteins.
[0179] Importance analysis of spore spectral characteristics: from Figure 17 It can be seen that among the top 5 features that contribute significantly to spore classification, all except S1 are protein-related Raman shifts. S1 (1023 cm⁻¹) -1 This can be classified as DPA, a compound unique to spores and virtually absent in vegetative cells; therefore, this characteristic contributes most significantly to spore identification. Features such as S2, S3, S4, and S5 primarily reflect information related to protein structure; for example, S2 (1649 cm⁻¹) -1 The reaction protein secondary structure may be related to the characteristics of spores, so it plays a more important role in the discrimination process.
[0180] Contribution analysis of spectral features to Gram-negative bacteria classification in model decision-making: To further understand the influence of each feature on different samples, the SHAP summary plot tool was used for further analysis. The SHAP summary plot, through color gradients and point distribution, helps to understand the specific decision-making mechanism of the model. Figure 18 As shown, the SHAP summary plot illustrates the combined impact of various features of the four Gram-negative bacteria on the output results in the model. Taking E. coli as an example, the X-axis represents the SHAP value, indicating the degree and direction of each feature's influence on the model's prediction. A negative value indicates a higher probability of identifying E. coli, while a negative value indicates a reduced probability. Features are arranged from top to bottom according to importance. Here, we selected the top 10 most important features for E. coli, and each feature corresponds to its sample point. The color gradient from blue to red represents the change in feature value from low to high. By observing the E. coli SHAP summary plot, it can be found that 900 cm⁻¹, 696 cm⁻¹, and 706 cm⁻¹ play a key role in the model's prediction of E. coli. The higher the feature values at these three locations, the more likely the model is to identify E. coli.
[0181] Through analysis, the feature is 1649cm. -1The feature showed a significant effect in E. coli, S. typhimurium, and S. flexneri, primarily acting as a positive shift, suggesting it may be a potentially universal marker. However, each bacterium also has its unique key features; for example, the 900 cm⁻¹ feature in E. coli... -1 The characteristics of S. Typhimurium: 832cm -1 They play an important role in their respective classifications. 768cm -1 It plays a decisive role in *S. flexneri*, but has a smaller effect in other bacteria. In terms of the direction of influence, it affects the main characteristics of *E. coli* and *S. typhimurium* (such as characteristic 900 cm). -1 and features 832cm -1 At high eigenvalues, the model shifts towards the corresponding class; for example, P. aeruginosa has eigenvalues of 670 cm⁻¹. -1 This has a negative impact on the model at high eigenvalues; S. flexneri's eigenvalue is 768 cm⁻¹. -1 This demonstrates a strong positive driving force. In general, certain characteristics play a strong driving role in the classification of specific bacteria, providing clear evidence for rapid bacterial differentiation. These findings provide strong support for data classification based on Raman spectroscopy.
[0182] Analysis of the contribution of spectral features to the classification of Gram-positive bacteria in model decision-making: such as Figure 19 As shown, by analyzing the SHAP values of six Gram-positive bacteria (S. aureus, L. monocytogenes, B. subtilis, B. cereus, C. perfringens, C. sporogenes), we can see the influence of different characteristics on the classification of each bacterium. For example, the characteristic 1649 cm⁻¹... -1 1582cm -1 631cm -1 Features such as 1080 cm⁻¹ play a significant role in multiple bacterial categories, especially at high eigenvalues, where they have a significant positive impact on the model output, suggesting that these features may be common to Gram-positive bacteria. However, each bacterium also has its unique key features. For example, feature 1080 cm⁻¹... -1 It is crucial in the classification of C. sporogenes, and feature 1486cm is essential. -1 It played a decisive role in the classification of B. cereus. Features such as feature 670cm... -1 and features 543cm -1In the classification of L.monocytogenes, this shows a negative impact, especially at low eigenvalues, indicating that their influence on the model differs depending on the eigenvalue.
[0183] Contribution analysis of spectral features to spore classification in model decision-making: such as Figure 20 As shown, by analyzing the SHAP values of four spore-forming bacteria (Bacillus subtilis spores, Bacillus cereus spores, C. perfringens spores, and C. sporogenes spores), the key features of each bacterium and their impact on the model output can be identified. Feature 1649cm -1 It showed a significant impact across multiple spore categories, particularly at high eigenvalues, driving the model toward predictions for the corresponding category. Different bacteria exhibited differential characteristics, such as the eigenvalue 733cm. -1 It is prominent in B. cereus spores, characteristic 1308 and characteristic 1307 cm. -1 It plays an important role in the spores of *C. sporogenes*. At high eigenvalues, most key features positively influence the model output, but at low eigenvalues, certain features (such as feature 773cm) have a negative impact. -1 and features 832cm -1 This can cause deviations in model predictions.
[0184] Step 4: Use the preprocessing method described in Step 1 to preprocess the unknown Raman spectral data samples to be classified, and then use the best-performing model to classify them to obtain the classification results.
[0185] Example 2
[0186] A rapid identification system for foodborne pathogens and spores based on Raman spectroscopy and machine learning, such as Figure 2 As shown, it includes a browser layer, a data layer, and a service layer. The browser layer includes a multi-role login management module, a spectral data management module, a classification model management module, a data prediction function module, and a system function module, which interact with the data and service layers through API interfaces.
[0187] The multi-role login management module provides login access for administrators, analysts, and ordinary users, verifying user identity information. Administrators have the highest privileges, able to view all registered users and use all system functions. Analysts, as intermediate users, are primarily responsible for uploading, editing, and preprocessing Raman spectral data, as well as training classification models. Ordinary users have basic privileges, mainly used for uploading unknown sample data, calling existing models within the system for classification prediction, and viewing prediction results. The spectral data management module handles spectral data uploading, preprocessing, and displaying. The system supports uploading Raman spectral data in various formats and provides editing, modification, information supplementation, and deletion management functions to ensure data integrity and maintainability. The classification model management module supports uploading classification model files and managing model-related information. The data prediction function module receives uploaded unknown samples and displays classification prediction results. The system function module records and views system logs and manages user permissions.
[0188] The data layer includes sample tables, model tables, user tables, log tables, and temporary tables.
[0189] The sample table stores spectral data information, including raw spectral data and preprocessed results; the model table stores classification model files and file information, including model name, algorithm type, and creation time; the user table stores user accounts, passwords, roles, and permission information; the log table records system operation logs, such as user login, data operations, and model training behavior information; and the temporary table stores model classification results information.
[0190] The service layer includes a service file system, a preprocessing module, and a classification module. The service file system stores locally trained classification model files and preprocessing algorithm files uploaded by users; the preprocessing module executes the preprocessing algorithm files, and the classification module executes the classification model files.
[0191] In this embodiment, a B / S model is adopted. The browser layer is built using the Vue.js framework and requests are sent through Axios to realize API interaction with the data layer and service layer. The business logic interface of the service layer is built using Flask and the data layer is built using MySQL.
[0192] In use, in the multi-role login management module, the administrator clicks the administrator module and enters login information. The browser layer sends a POST request to the service layer interface ` / api / login` (Flask) via Axios, calling the data layer to query the user table to verify identity. If verification is successful, a JWT token is generated and returned to the browser layer. Simultaneously, login logs are recorded, connecting to a MySQL database via Node.js's `mysql` module, and then storing the data in the MySQL database's log table and user table. The front-end stores the token and dynamically renders page functions based on role permissions; for example, administrators see the classification model management entry, while ordinary users only see the data prediction function.
[0193] In the spectral data management module, for the spectral data upload and preprocessing module, the browser layer uses Axios's FormData object to receive Raman spectral data files. It then sends a POST request to the service layer interface ` / api / spectra / upload` via the FormData object. After receiving the Raman spectral data files, the service layer stores the raw spectral data in the service file system, calls the preprocessing module to process the data, and connects to a MySQL database using Node.js's mysql module. The data is then stored in the sample table of the MySQL database, and the preprocessed spectral data is returned to the browser layer. For the data spectrum display module, the browser layer uses Axios to send a GET request to the service layer interface ` / api / spectra / list` to retrieve Raman spectral data file information from the sample table of the MySQL database. When a specific sample is clicked, the browser layer requests ` / api / spectra / detail / {id}` to obtain the raw and preprocessed Raman spectral data, renders the spectral curve, and administrators or analysts can use Axios's PUT / DELETE requests through the browser layer to call the service layer interface to update or delete data in the sample table.
[0194] In the classification model management module, for the model file upload module, administrators or analysts upload trained classification model files and model information through the browser layer. The browser layer uses Axios to send a POST request to the service layer interface ` / api / models / upload`. The service layer stores the classification model file in the service file system and the model information (name, algorithm, creation time) in the `model` table of the MySQL database. For the model information viewing module, the browser layer uses Axios to send a POST request to the service layer interface ` / api / models`, carrying a JWT token. The service layer verifies the identity information using the JWT token, queries the `model` table in the MySQL database to retrieve the model information, and returns it to the browser layer for display. For the model storage and management module, the browser layer uses Axios's PUT / DELETE requests to call the service layer interface to update or delete data in the model table.
[0195] In the data prediction module, the process of uploading unknown samples is the same as that of uploading spectral data, and will not be repeated here. For the prediction result output module, the browser layer sends a POST request to the service layer interface / api / predict via Axios. The service layer calls the preprocessing algorithm and classification model to perform classification prediction on the unknown samples and stores the classification prediction in a temporary table in the MySQL database. For the result display module, the browser layer sends a GET request to the service layer interface / api / temp via Axios to retrieve the prediction results from the temporary table in the MySQL database and returns them to the browser layer for display.
[0196] In the system function settings module, the browser layer sends a GET request to / api / users via Axios to retrieve user table information and returns it to the browser layer for display. The platform maintenance module mainly manages user permissions. The browser layer sends a PUT request to / api / users / {id} / permission via Axios to modify user roles or permissions, and the service layer updates the user table.
[0197] Software development and runtime environment: The Raman spectroscopy classification web cloud platform involved is developed and run on a PC with Windows 10 installed. The web cloud platform application developer runtime environment is configured with Python, Node.js, Flask, and MySQL. The compilation and debugging process is performed in VS Code. Detailed parameters are shown in Table 4-1.
[0198] Table 4-1 Web Cloud Platform Development and Operating Environment
[0199]
[0200] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A rapid identification method for foodborne pathogens and spores based on Raman spectroscopy and machine learning, characterized in that, The steps are as follows: Step 1: Acquire and preprocess Raman spectroscopy data to obtain a Raman spectroscopy dataset; Step 2: Construct a classification model based on SPA-RF: Use the continuous projection algorithm to extract features from the Raman spectral data, and use the random forest algorithm to classify the data after feature extraction; Step 3: Train the SPA-RF-based classification model using the Raman spectroscopy dataset to obtain the best-performing model, and use the SHAP method to perform interpretability analysis on the best-performing model; Step 4: Use the preprocessing method described in Step 1 to preprocess the unknown Raman spectral data samples to be classified, and then use the best-performing model to classify them to obtain the classification results.
2. The rapid identification method for foodborne pathogens and spores based on Raman spectroscopy and machine learning according to claim 1, characterized in that, When acquiring Raman spectroscopy data, laser confocal laser was used. Al was selected as the substrate material, the excitation wavelength was 532 nm, the laser power was set to 50%, the integration time was 20 s, and the integration was performed once.
3. The rapid identification method for foodborne pathogens and spores based on Raman spectroscopy and machine learning according to claim 1, characterized in that, The preprocessing method is as follows: the original Raman spectral data is subjected to SG smoothing, the smoothed spectral data is baseline corrected using adaptive iterative reweighted penalized least squares method, and the baseline corrected spectral data is normalized using maximum-minimum normalization.
4. The rapid identification method for foodborne pathogens and spores based on Raman spectroscopy and machine learning according to claim 3, characterized in that, The method for performing SG smoothing on the raw Raman spectral data is as follows: The original Raman spectral data is read from an Excel file using openpyxl; the raw data is converted into a numerical array using the NumPy or Pandas library, and key information is extracted; the savgol_filter function in the SciPy library is used to perform a smoothing operation based on the extracted key information array. At each position of the spectral data, a window of M points is expanded centered on that point, and an L-order polynomial is used to fit the data within the window. The calculated value of the fitted polynomial at the center point is taken as the smoothed value, and finally, the smoothed spectral data is output; the original spectrum and the smoothed spectral data are merged and saved into a new Excel file using the openpyxl or Pandas library.
5. The rapid identification method for foodborne pathogens and spores based on Raman spectroscopy and machine learning according to claim 3 or 4, characterized in that, The baseline correction method is as follows: The Pandas library is used to read the SG-smoothed Excel file to obtain the SG-smoothed spectral intensity data. The NumPy library is used to encapsulate the airPLS algorithm into a callable function. The inputs are the smoothed spectral intensity data y, the data length n, the smoothing parameter σ, the maximum number of iterations, and the convergence threshold. The airPLS algorithm function is called to obtain the final baseline estimate and the corrected spectrum. The smoothed spectral intensity data y, the final baseline estimate, and the corrected spectrum are merged into a table and saved as an Excel file.
6. The rapid identification method for foodborne pathogens and spores based on Raman spectroscopy and machine learning according to any one of claims 1 to 4, characterized in that, The method for feature extraction from Raman spectral data using the successive projection algorithm is as follows: St1 sets the number of selected feature variables to N; St2 randomly selects a wavelength λ from the preprocessed spectrum. i As initial feature variables, Initialize the feature variable subset S1 = {λ i }; St3 calculates the initial characteristic variables at all unselected wavelengths λ. j Projection vector on: in and It is the wavelength λ i The feature vector at that location, Representative eigenvector In the eigenvector The projection vector of the direction; St4 calculates the initial feature variables across all unselected wavelengths λ. j The magnitude of the projection vector is used to select the wavelength with the longest projection as a new candidate feature variable and add it to the feature variable subset S. k ; Step 5 repeats steps 2-4 until the number of selected candidate feature variables reaches the set value N; St6 constructs a partial least squares regression model and measures the subset S of feature variables through cross-validation root mean square error. k Predictive ability; St7 further uses the subset of feature variables corresponding to the smallest root mean square error as the final optimal feature set.
7. The rapid identification method for foodborne pathogens and spores based on Raman spectroscopy and machine learning according to any one of claims 1 to 4, characterized in that, The method described above for interpretability analysis of the best-performing model using the SHAP method is as follows: Given a constant term φ0, calculate the spectral characteristic variable λ for each variable using the Shapley value formula. i Marginal contribution to the prediction results: Where, φ i (λ i ) is the characteristic variable λ i The SHAP value is given by N, which is the set of all feature variables, totaling M features, and S, which does not include the feature variable λ. i Let f(S) be any subset of feature variables, and let f(S) be the predicted output of the model when using the subset of feature variables S. i }) is the characteristic variable λ i The predicted output of the model after adding a subset S of feature variables; The constant term φ0 is added to the SHAP values of all feature variables according to the additive formula to obtain the prediction result of the SPA-RF-based classification model. The additive formula is as follows: β(λ) represents the prediction result of the classification model as expressed by the SHAP value.
8. A rapid identification system for foodborne pathogens and spores based on Raman spectroscopy and machine learning, characterized in that, It includes a browser layer, a data layer, and a service layer. The browser layer includes a multi-role login management module that interacts with the data layer and the service layer through API interfaces, a spectral data management module, a classification model management module, a data prediction function module, and a system function module.
9. The rapid identification method for foodborne pathogens and spores based on Raman spectroscopy and machine learning according to claim 8, characterized in that, The multi-role login management module includes an administrator module, an analyst module, and a regular user module, which are used to provide login access for administrators, analysts, and regular users, and to verify user identity information, respectively. The spectral data management module includes a spectral data upload module, a data preprocessing module, and a data spectral display module. The spectral data upload module is used by analysts or administrators to upload Raman spectral data. The data preprocessing module is used by analysts or administrators to send Raman spectral data preprocessing requests to the server. The data spectral display module is used to display the original Raman spectral data, the preprocessed Raman spectral data, and to update and modify spectral data information.
10. The rapid identification method for foodborne pathogens and spores based on Raman spectroscopy and machine learning according to claim 8 or 9, characterized in that, The classification model management module includes a model file upload module, a model storage and management module, and a model information viewing module. The model file upload module is used to upload trained classification model files, the model storage and management module is used to manage classification model information, and the model information viewing module is used to view classification model information. The data prediction function module includes an unknown sample upload module, a prediction result output module, and a result display module. The unknown sample upload module is used by ordinary users to upload Raman spectral data of unknown classification types. The prediction result output module is used to send a request to the server to obtain the prediction result. The result display module is used to display the prediction result. The system's functional modules include a system log module and a platform maintenance module. The system log module is used to view system operation logs, while the platform maintenance module is used to manage user permissions. The service layer includes a service file system, a preprocessing module, and a classification module. The service file system is used to store user-uploaded trained classification model files and preprocessing algorithm files. The preprocessing module is used to execute preprocessing algorithm files, and the classification module is used to execute classification model files.