HyMLRaman: Hybrid Machine Learning for Raman Spectroscopy-Based Drug Residue Identification

HyMLRaman converts Raman spectra to images, encodes them with EfficientNet-B3, and achieves 96%+ drug identification accuracy using hybrid classifiers.
HyMLRaman is a hybrid machine learning framework for rapid pharmaceutical screening. It converts 1D Raman spectra into images, extracts 1536-dimensional embeddings via pretrained EfficientNet-B3, and feeds them into classical classifiers (SVM, KNN, random forest, etc.). Tests on six drug compounds show EfficientNet-B3 + SVM achieves 96.31% accuracy and 96.36% macro-F1, outperforming end-to-end CNN baselines. DDPM-based latent-space data augmentation is explored for small-sample scenarios, though ablation results show gains are classifier-specific and not universal. An interactive Raman Pharmaceutical Analyzer prototype further validates the approach's engineering feasibility.
Background: Why Rapid Drug Identification Matters
Rapid and reliable identification of drug residues has real-world implications for public health protection and food safety. Traditional laboratory testing workflows are often time-consuming and dependent on specialized equipment. Raman Spectroscopy, with its non-destructive nature, speed, and strong molecular fingerprint specificity, is emerging as an ideal candidate technology for on-site screening.
The challenge is that raw Raman spectral signals are susceptible to noise and fluorescence background interference, making it difficult for manual interpretation or simple classification models to maintain stable accuracy in complex scenarios. A newly published study on arXiv proposes the HyMLRaman framework, which aims to address this problem through a combination of deep feature extraction, generative modeling, and classical machine learning classifiers.

Technical Architecture of HyMLRaman
From Spectra to Images
The core idea of this framework is to convert one-dimensional Raman spectra into spectral images, which are then encoded using a deep neural network backbone. The research team tested several mainstream backbones and ultimately found that EfficientNet-B3 produced the most effective feature representations, generating 1536-dimensional embedding vectors.
This "spectra-to-image + deep encoding" approach is not entirely novel, but its value lies in transferring the mature convolutional network capabilities from computer vision to spectral analysis — enabling the model to capture subtle spectral band differences that are difficult to describe through manual feature engineering.
EfficientNet-B3 is one of the models in the EfficientNet series proposed by Google in 2019. Its core innovation is a "Compound Scaling" strategy — simultaneously scaling the network's depth, width, and input resolution proportionally, rather than adjusting any single dimension independently. Compared to traditional convolutional networks of equivalent accuracy, the EfficientNet series is more compact in terms of parameter count and computational cost. B3 is the third tier in this series, with an input resolution of 300×300 and a Top-1 accuracy of approximately 81.6% on ImageNet. In this study, EfficientNet-B3 is used as a pretrained backbone network, with the feature layer before the final fully connected layer outputting a 1536-dimensional vector — essentially a highly compressed and abstracted "semantic encoding" of the input spectral image. Choosing B3 over larger-scale B5/B7 variants also reflects an engineering trade-off between feature expressiveness and computational overhead.
Hybrid Classifier Design
After obtaining high-dimensional embeddings, the research does not directly output results end-to-end through a neural network. Instead, these features are fed into a series of classical machine learning classifiers — including SVM, KNN, logistic regression, random forest, XGBoost, and ANN — with stratified 10-fold cross-validation used to evaluate performance.
This "deep encoder + classical classifier" hybrid paradigm balances the representational power of deep learning with the interpretability and data efficiency of traditional models, and is the key design philosophy of this research.
Stratified 10-fold Cross-Validation is one of the standard methods for evaluating model generalization in machine learning. The approach involves randomly splitting the dataset into 10 subsets, iteratively training on 9 subsets and validating on 1, repeating this 10 times and averaging the metrics. "Stratified" means that the proportion of each class in every subset matches that of the overall dataset — this is particularly important for class-imbalanced scenarios. In drug identification tasks, if samples of a certain drug are scarce, stratified sampling prevents a particular class from being completely absent from a validation fold, ensuring the stability and reliability of evaluation results. Compared to a single random train/test split, 10-fold cross-validation makes fuller use of limited data and significantly reduces the variance introduced by random partitioning.
Experimental Results: Over 96% Identification Accuracy
The study conducted identification tests on six pharmaceutical compounds: amoxicillin, chloramphenicol, ciprofloxacin, tetracycline, ibuprofen, and paracetamol.
Experiments showed that the combination of EfficientNet-B3 and SVM achieved the strongest baseline performance: an accuracy of 96.31% and a macro-F1 score of 96.36%, significantly outperforming the standalone CNN baseline. This result validates the advantage of the hybrid architecture over purely end-to-end deep models — on small-to-medium-scale spectral datasets, classical classifiers tend to be less prone to overfitting.
Addressing Small Sample Sizes: DDPM Generative Feature Augmentation
Real-world pharmaceutical spectral data is costly to collect and limited in volume, which is a common bottleneck constraining model deployment. To address this, the research introduces generative feature augmentation based on DDPM (Denoising Diffusion Probabilistic Models), generating synthetic features within the PCA-reduced latent space of EfficientNet-B3.
Notably, the conclusions from the ablation experiments are quite measured and candid: DDPM augmentation only provides benefits under specific conditions — particularly for KNN classifiers at lower training data ratios — and the overall gains depend on the specific classifier, making it far from a universally applicable performance booster. This honest presentation of limitations actually enhances the study's credibility.
DDPM (Denoising Diffusion Probabilistic Models) is a generative model framework proposed by Ho et al. in 2020, belonging to the diffusion model family. Its core principle involves two processes: a forward process that progressively adds Gaussian noise to data until it becomes pure noise, and a reverse process that trains a neural network to learn how to gradually "denoise" and recover the data distribution from noise, thereby generating new samples. Compared to GANs (Generative Adversarial Networks), DDPM offers more stable training and greater generation diversity, though at the cost of slower inference. In this study, DDPM does not directly generate raw spectra — instead, it generates synthetic feature vectors within the low-dimensional latent space after PCA dimensionality reduction. These synthetic features are then mixed with real features for classifier training, alleviating data scarcity in small-sample scenarios. This strategy of "augmenting in latent space" is computationally cheaper than augmenting in the original data space and makes it easier to control the distributional boundaries of generated samples.
From Model to Application: The Raman Pharmaceutical Analyzer
Another highlight of this research is its engineering deployment mindset. The team built an application-level Raman Pharmaceutical Analyzer, embedding the trained model into an interactive Raman analysis workflow to validate the feasibility of the approach in real-world usage scenarios.
This means HyMLRaman goes beyond laboratory metrics — it takes a step toward a deployable, interactive screening tool, which has direct reference value for on-site applications such as food safety regulation and pharmaceutical quality control.
Conclusions and Outlook
HyMLRaman demonstrates a practical and interpretable pathway for rapid Raman-based pharmaceutical screening. Its core contributions can be summarized in three points: high-quality spectral feature encoding via EfficientNet-B3, over 96% identification accuracy through a hybrid classification architecture, and exploration of small-sample solutions using DDPM generative augmentation.
Of course, this study currently covers only six pharmaceutical compounds, and the effectiveness of DDPM augmentation remains inconsistent. There is still some distance from large-scale, multi-class real-world deployment. Nevertheless, as a work that organically integrates deep learning, generative models, and classical machine learning, it provides a methodological framework worth referencing for the spectral analysis field.
Related articles

AI-Powered SRC Vulnerability Hunting: A Hands-On Guide to Building the Hermes Agent Workbench
Based on a hands-on Bilibili video: how to build an AI-powered SRC vulnerability hunting workbench—three-step method, four report elements, Agent mode vs web chat, and tool selection.

CLI-Anything Complete Beginner's Guide: How AI Operates Software — Principles and Practice
A complete beginner's guide to CLI-Anything: how AI Agents operate professional software via the command line, covering the three-layer architecture, CLI Hub installation, DrawIO practice, generator principles, and limits.

Carbon-X: A 14.8B Open-Source Model That Handles DNA and Text Simultaneously
Carbon-X is a 14.8B open-source multimodal model on Hugging Face where DNA and text share a token stream. 6-mer tokenization, 302B token mid-training, deployable on a single 80GB GPU, 66.7% average on five DNA benchmarks, Apache 2.0 license.