(C) PLOS One This story was originally published by PLOS One and is unaltered. . . . . . . . . . . Using genomic data and machine learning to predict antibiotic resistance: A tutorial paper [1] ['Faye Orcales', 'Department Of Biology', 'San Francisco State University', 'San Francisco', 'California', 'United States Of America', 'University Of California San Francisco', 'Lucy Moctezuma Tan', 'Department Of Statistics', 'California State University East Bay'] Date: 2025-07 Antibiotic resistance is a global public health concern. Bacteria have evolved resistance to most antibiotics, which means that for any given bacterial infection, the bacteria may be resistant to one or several antibiotics. It has been suggested that genomic sequencing and machine learning (ML) could make resistance testing more accurate and cost-effective. Given that ML is likely to become an ever more important tool in medicine, we believe that it is important for pre-health students and others in the life sciences to learn to use ML tools. This paper provides a step-by-step tutorial to train 4 different ML models (logistic regression, random forests, extreme gradient-boosted trees, and neural networks) to predict drug resistance for Escherichia coli isolates and to evaluate their performance using different metrics and cross-validation techniques. We also guide the user in how to load and prepare the data used for the ML models. The tutorial is accessible to beginners and does not require any software to be installed as it is based on Google Colab notebooks and provides a basic understanding of the different ML models. The tutorial can be used in undergraduate and graduate classes for students in Biology, Public Health, Computer Science, or related fields. Funding: PP was awarded NSF grant 1655212. FTO was supported by an NSF REPS Supplement under NSF grant 1655212. MJH was supported by Bristol-Myers Squibb Black Excellence in STEM Scholars and Genentech Foundation Scholars G-7874540. JMS was supported by NIH MARC T34-GM008574. JA was supported by NIH MS to Bridges Doctorate T32-GM142515. KR was supported by Genentech Foundation Scholars G-7874540. PG was supported by NIH MARC T34-GM008574. The funders had no role in study design, data collection and analysis, decision to publish, or preparation of the manuscript. Copyright: © 2024 Orcales et al. This is an open access article distributed under the terms of the Creative Commons Attribution License , which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited. We used data and approaches from Moradigaravand and colleagues [ 11 ] with a few changes and simplifications. We chose this paper as the basis for this tutorial because it uses a large E. coli data set to predict resistance to 11 drugs and applies 4 common ML models. Their paper focused on predicting E. coli resistance in bacteremia patients from the United Kingdom. The models included in this tutorial are: extreme gradient-boosted tree, random forest, logistic regression, and neural network. For each of these models, we created a Google Colab Notebook and there are 2 additional notebooks for data preparation and to visualize the results. The benefit of coding in Google Colab Notebooks is that users can work in a browser with no need to install software on their own computer. Our goal was to create an easily understandable tutorial for anyone who wishes to learn more about ML and its applications in predicting antibiotic resistance. With this paper, we aim to make ML more accessible for those who would like to learn it and who have an interest in biology or public health. The authors of this paper were a group of students (undergraduate, post-bacc, and master’s) at San Francisco State University that were excited to learn more about machine learning and its potential in antibiotic resistance research. At the start of this project, the authors were new to machine learning. As we developed the project, we gained experience in Python, genomic data, and creating ML models. This tutorial is a culmination of our efforts, learning journeys, and aims to serve those in a similar learning phase. The goal of this tutorial is to introduce the user to ML applied to genomic data to predict drug resistance, so they may potentially use it in their own future research. Note that we focus on the practical and intuitive side of ML rather than the bioinformatics part of a project (we start with an existing gene presence-absence table) or the mathematical details of machine learning. For an overview of useful bioinformatics tools, see [ 16 ]. There is a lot of interest in using ML in combination with genomic data to predict antibiotic resistance [ 8 – 15 ]. Genomic data, including information on gene presence and absence, single-nucleotide polymorphisms (SNPs), indels (insertions and deletions), and k-mer frequencies, contain a lot of information that can be leveraged to predict phenotypes such as drug resistance. For example, Moradigaravand and colleagues used gene presence-absence information and population structure data to train various ML models to predict Escherichia coli resistance against 11 antibiotics [ 11 ]. Ren and colleagues led a similar study using SNP data and focused on 4 antibiotics [ 10 ]. Nsubuga and colleagues used SNP data to train ML models on data from England and then tested the models on data from several African countries [ 13 ]. In another study, Khaledi and colleagues used SNPs, gene presence-absence, and gene expression data to predict Pseudomonas aeruginosa resistance to 4 antimicrobial drugs [ 12 ]. A recent study by Hu and colleagues compared how a variety of ML methods were able to predict resistance phenotypes for 78 bacterial species-drug pairs [ 14 ]. Machine learning (ML) involves using large data sets to create models capable of making predictions [ 4 ]. Its applications in medicine are extensive from supporting roles such as handling medical health records, increasing the speed and accuracy of diagnosis of various diseases and in genetic engineering and genomics [ 5 , 6 ]. Studies have suggested that ML methods can identify tumors from medical images that may be overlooked by radiologists [ 7 ]. In recent years, many research groups have used ML to predict whether infections are caused by drug-resistant strains or not. Penicillin was one of the first antibiotics that helped cure bacterial infections such as strep throat, gonorrhea, and meningitis [ 1 ]. Prior to the discovery of antibiotics, the average lifespan in the United States was merely 56 years, whereas in contemporary times, it has risen to approximately 80 years [ 2 ]. However, over the years, resistant strains of bacteria have evolved and become quite common, reducing the usefulness of antibiotics. As drug resistance has become more common, determining drug resistance phenotypes for pathogens is important for successful treatment of patients. Ideally, a doctor would know quickly which antibiotics they should prescribe to successfully treat their patient. Currently, this is usually done using phenotypic antimicrobial susceptibility tests that require significant time and resources in the laboratory. Genomic sequencing in combination with machine learning has been proposed as a way to accelerate this process [ 3 ]. Data, machine learning models, cross-validation, and evaluation Data preparation In this tutorial, we mostly use data and follow the approaches taken by Dr. Moradigaravand and colleagues [11] with some modifications for simplicity. While their approach is not the only way to use genomic data for ML purposes, it is a good place to start learning. We will work with a data set that was collected over many years in the UK [11]. For 1,936 patients who suffered from E. coli bloodstream infections, bacteria were isolated and tested against 12 antibiotics in the lab. Note that the Moradigaravand paper only reports results for 11 antibiotics, we will look at all 12 in the data set. An example of the phenotypic data can be seen in Table 1. Our goal here is to try and predict these antibiotic phenotypes using the genomic data from the same isolates. PPT PowerPoint slide PNG larger image TIFF original image Download: Table 1. Example of antibiotic phenotypic data from the Moradigaravand dataset. https://doi.org/10.1371/journal.pcbi.1012579.t001 Bacterial genomes are usually sequenced using next-generation sequencing techniques. Starting from the raw sequencing reads, different bioinformatics tools are used for quality control, such as the removal of low quality sequences, to align reads to reference genomes and to create gene presence-absence tables and SNP tables. To build an ML model to predict drug resistance, we need to choose what information from each isolate to use for the model to learn from. Moradigaravand and colleagues used 2 types of genomic data, but we will only be using one: the gene presence-absence table. We will not use the population structure data used by Moradigaravand. In addition to genomic data, Moradigaravand and colleagues used the year of isolation, which we will use here as well [11]. The gene presence-absence table summarizes for each bacterial isolate which genes are present or absent. Bacteria like E. coli can gain and lose genes through horizontal gene transfer, leading to different gene content in each isolate. Genes that confer resistance are among the ones being lost and gained, which is why a gene presence-absence table is expected to be relevant for predicting drug resistance, see Table 2. PPT PowerPoint slide PNG larger image TIFF original image Download: Table 2. Example of gene presence-absence table. https://doi.org/10.1371/journal.pcbi.1012579.t002 While not used by Moradigaravand and colleagues [11], we decided to include the Multi-Locus Sequence Type (“MLST”) for each sample. Note however that we will not directly use MLST as a predictive feature to build the ML models. Instead, we will use it as an optional method to group the samples for our cross-validation step. Other aspects of genomic data that are often used as features for machine learning but that we do not use here are SNP tables [10] and nucleotide or amino acid k-mer frequencies [17,18]. There are different reasons why researchers decide to use one type of genomic data or another. For example, to predict resistance that is caused by mutations, one may want to use SNP tables instead of a gene presence-absence table. This is particularly relevant for resistance to fluoroquinolones, such as ciprofloxacin, which is usually caused by mutations (SNPs) in E. coli. The benefit of k-mer frequencies on the other hand is that they can be calculated without aligning the sequences first. The variables that are used as predictors in an ML model are usually referred to as features. We use 2 groups of features in this tutorial: gene presence-absence (G) and year of isolation (Y). Basic machine learning concepts Common types of ML models include supervised learning, unsupervised learning, and reinforcement learning. In supervised learning, the model learns by recognizing patterns from a labeled data set. “Labeled” here means that the data set has an “answer key.” In our case, this means that we work with isolates for which we already know whether they are resistant or susceptible to different drugs thanks to tests done in a laboratory (see Table 1). These labels are used to train the ML model, and also, afterwards to test how well the model works. Before training an ML model, the entire data set is split into a training data set and a testing data set. Usually, around 70% to 80% of the data are used as the training data set and the rest is used for testing. In our notebooks, we used 80% training data and 20% testing. The training data set is used for the model to learn the patterns associated with resistance (or susceptibility). After that, the testing data set is used to determine how well the model can predict the label. Features and labels Features in ML can come in different formats, depending on the type of data used, such as pixel arrangements from an image or a set of words in a sentence, but it ultimately ends up coded numerically. For this tutorial, the features are already organized as tabular data, where each row is an observation (here a bacterial isolate) and each column is a feature. Each gene becomes a feature that is coded with 1 or 0, and the year of isolation is also a numeric feature that ranges from 1970 to 2017. The training data contains features that the model will attempt to learn patterns from and the labels it learns to predict. Here, the features are a list of genes for each isolate with indicators of whether a particular gene is present (1) or absent (0), and the year the isolate was collected. For each drug, we create a separate model where the label we are trying to predict is whether the isolate is resistant or susceptible to that drug. Isolates listed as “intermediate” are considered resistant. After the ML model is trained using the training data (features and labels), the features of the testing data will be used for the ML model to make label predictions. The predictions will then be compared with the known labels for the testing data set. We can then determine how often the model gets it right and how often it gets it wrong. Cross validation Cross validation is a commonly used method in machine learning. It has several purposes such as making sure the model generalizes (is able to predict well on data it has never seen before). Here, we will use cross validation to do hyperparameter tuning. Cross validation works by taking out a subset of the training data to use as a validation set, while the remaining subsets are used for training the model. This process is then repeated with different validation sets. This will allow us to monitor the model’s performance on a diverse set of validation subsets. There are different strategies for choosing the subsets for cross validation. We will discuss 2 methods: regular k-fold cross validation and stratified blocked cross validation. The k-fold cross validation method works by splitting your data into equal groups or “folds.” For example, if we use 4 folds the data is divided equally into 4 subsets. One of them is held out and used as the validation data set while the rest are all used for training. This is repeated until each unique fold has been used as the validation data set once (Fig 5A). It is up to the user how many folds you decide to use. The higher the number of folds you set, the longer the computational time. The stratified blocked cross validation method also splits the data into folds; however, it differs in how each fold is assigned a validation and training chunk. “Stratified” here means that the different folds try to maintain similar label proportions, for example, if the training folds contain about 70% Susceptible and 30% Resistant isolates, then the validation fold tries to maintain this proportion as well. “Blocked” here means that isolates are grouped into different MLST groups, where the MLST groups present training folds are not present in the validation folds. This is one of the methods used to ensure generalizability when training our model (Fig 5B). PPT PowerPoint slide PNG larger image TIFF original image Download: Fig 5. Cross Validation. (A) k-fold cross validation (here shown is 4-fold). (B) Stratified blocked cross validation. Code is provided for both options: regular random k-fold and for stratified blocked cross validation based on MLST. For both options, the initial training and testing data split is stratified based on labels (R, S). https://doi.org/10.1371/journal.pcbi.1012579.g005 [END] --- [1] Url: https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1012579 Published and (C) by PLOS One Content appears here under this condition or license: Creative Commons - Attribution BY 4.0. via Magical.Fish Gopher News Feeds: gopher://magical.fish/1/feeds/news/plosone/