Application of a neural network for classifying antibiotic resistance using MALDI-TOF mass spectrometry

Rapid and precise diagnosis of antibiotic resistance is crucial for optimal therapy in clinical settings. Conventional microbiological cultivation, however, often requires several days of valuable time. We help to close this gap: by applying advanced methods of machine learning and artificial intelligence (AI), we use rapidly available MALDI-TOF mass spectrometry data directly for resistance prediction. From modular data preprocessing (including noise reduction and signal calibration) and dimensionality reduction via principal component analysis (PCA) through to training tailored neural networks in Keras/TensorFlow – we transform complex, non-linear spectral data into reliable classification models with high predictive accuracy.

(Status: August 2025)

Background

In 2019, the World Health Organization (WHO) declared antimicrobial resistance (AMR) to be one of the ten greatest global threats to public health. Early detection of a pathogen’s resistance profile is essential for effective treatment, saving lives and reducing costs.

Current methods for species identification using MALDI-TOF mass spectrometry allow a result on the day of sampling. Determination of antibiotic resistance, however, typically requires multi-day cultivation of the pathogen. Using the faster mass spectrometry data directly for resistance prediction therefore offers a substantial advantage. Machine learning and AI methods are already well established for classifying large data sets and have also been applied successfully to MALDI-TOF data to classify pathogens and their antimicrobial resistance profiles.

This application example serves as a proof of concept to demonstrate the general suitability of the method for classifying MALDI-TOF data. The approach is flexible and can be extended to other species or antibiotics.

Application

Data

For this application example, we used a subset of a publicly available dataset on antibiotic resistance of human pathogenic bacteria. This dataset is published and available online.

The primary goal was to detect antibiotic resistance of a human-pathogenic bacterial strain from a clinical setting based on MALDI-TOF data. To this end, we extracted those samples from the full dataset for which corresponding resistance information was available in the metadata. The resulting subset comprises nearly 4,900 samples and is therefore sufficiently large for training a neural network (NN).

Analysis of the data distribution showed that, both overall and for the individual sampling sites (DRIAMS-A, DRIAMS-B, DRIAMS-C), there were clearly more susceptible (S) than resistant (R) samples. DRIAMS stands for “Database of Resistant Isolate Archives for MALDI-TOF Spectra”. The sampling sites DRIAMS-B and DRIAMS-C were recorded exclusively in 2018, whereas DRIAMS-A also includes samples from 2015 to 2017, which explains the higher number of samples from this site. The number of resistant samples remained roughly constant between 2016 and 2018, while the number of susceptible samples increased.

Sample distribution by source and resistance classes in the DRIAMS database

Preprocessing

To prepare the raw data for input into the neural network, we applied a specific sequence of preprocessing steps. These steps are based on the methodology described in the original dataset publication, but were adapted with respect to algorithms and the number of bins. The preprocessing is implemented as a modular pipeline that allows different algorithms to be selected for each step in order to achieve optimal feature extraction.

The preprocessing comprised the following steps:

  1. Transformation: The intensity values were normalized using a square root transform to stabilize variance and make the data more amenable for subsequent steps.
  2. Smoothing: A Savitzky–Golay filter was applied for noise reduction. This algorithm is particularly suitable for spectral smoothing as it preserves the shape of the peaks.
  3. Baseline correction: Baseline correction using the SNIP algorithm was performed to remove unspecific background signals that overlay the spectral peaks.
  4. Calibration: Intensities were calibrated by division by the total ion current (TIC) to ensure comparability of spectra recorded at different overall intensities.
  5. Trimming: The m/z range of the spectra was trimmed to 2,000–20,000 m/z, as this range contains the most relevant signals.
  6. Binning: The preprocessed m/z and intensity values were grouped into 6,000 bins of 2 Da each. Intensities within each bin were summed, which reduces data volume while preserving the essential spectral information for the NN.

Principal component analysis (PCA)

To assess the suitability of the preprocessed spectra for neural network training, we performed a principal component analysis (PCA). PCA is a statistical method for dimensionality reduction and visualization that projects complex spectra onto a small number of principal components capturing the largest variance in the dataset.

PCA scatter plot of MALDI-TOF spectra by resistance classes

In this dataset, the first six principal components explain 53.6% of the total variance, which is a relatively low value. Samples were plotted in a scatter plot of the first principal components and colored by metadata (resistance class, sampling site and year). The analysis shows no clear separation between resistant (1) and non-resistant (0) samples. Likewise, no clear separation by sampling site or year can be observed.

PCA scatter plot grouped by sampling site and year

This result indicates that the main sources of variability in the dataset are not directly correlated with the biological classification labels. As a linear method, PCA was not able to capture the complex non-linear relationships in the data. This justifies the use of a more powerful model such as a neural network, which can learn such non-linear patterns.

Neural network (NN)

In this application example, the neural network was implemented in Keras/TensorFlow. For the classification task at hand, we chose a relatively simple neural network. The input layer reflects the 6,000 bins of the dataset. The subsequent hidden layers are fully connected (dense) and consistently use the ReLU activation function. Finally, a binary output layer decides whether antibiotic resistance is present or not, using the softmax activation function.

Schematic structure of the implemented neural network

The network was trained using the Adam optimizer. As loss function, categorical cross-entropy was used, as it measures the discrepancy between predicted probabilities and true labels and is well suited for binary classification problems. The metric to be maximized was accuracy, defined as the percentage of correctly predicted samples. The dataset was split into 60% training data and 20% each for validation and test data. To ensure representativeness, we used a stratified split that preserves the distribution of resistance classes, sampling sites and years in all three subsets.

Training was typically stopped after about 30 epochs when the validation loss had not improved for 10 consecutive epochs. This early stopping criterion helps to prevent overfitting of the NN to the dataset and thereby improves generalization.

Accuracy during training and validation

After successful training, inference was performed to classify antibiotic resistance of the samples. The raw numerical outputs of the model were converted to interpretable labels: a prediction of 0 corresponds to the susceptible class (S) and 1 to the resistant class (R).

After evaluation, the accuracy values were as follows:

With this simple neural network, approximately 92% of the test samples were correctly classified. Such a high probability of correct classification underlines the potential of MALDI-TOF data to be used for resistance prediction in practice. This could significantly improve the treatment of infections in both clinical and veterinary settings.

Conclusion and outlook

This application example demonstrates the feasibility and potential of machine learning for rapid and precise classification of antibiotic resistance based on MALDI-TOF mass spectrometry data. Integrating these technologies into routine diagnostics could enable faster and more targeted therapy and thus make an important contribution in the fight against antimicrobial resistance.

References

  • [1] K. Asakura et al.: Rapid and easy detection of low-level resistance to vancomycin in methicillin-resistant Staphylococcus aureus by matrix-assisted laser desorption ionization time-of-flight mass spectrometry. In: PLoS ONE, 13(3):e0194212, 2018. doi: 10.1371/journal.pone.0194212
  • [2] H.-Y. Wang et al.: Efficiently Predicting Vancomycin Resistance of Enterococcus faecium From MALDI-TOF MS Spectra Using a Deep Learning-Based Approach. In: Front. Microbiol., 13:821233, 2022. doi: 10.3389/fmicb.2022.821233
  • [3] C. Weis et al.: Direct antimicrobial resistance prediction from clinical MALDI-TOF mass spectra using machine learning. In: Nat. Med., 28:164–174, 2022. doi: 10.1038/s41591-021-01619-9

Interested in this application area?

Let us discuss how we can tailor our mathematical models and AI workflows to your specific question and your laboratory or clinical setup.

Request a non-binding consultation