Analysing X-rays for pneumonia in children aged 0–5 using machine learning
An educational project from Saturdays.AI La Paz explores neural networks for classifying paediatric chest X-rays with and without pneumonia.
A learning project shared by the community. The article documents its team, methods and results; it does not establish that the prototype is ready for real-world use.

Editorial note: this article documents an educational project and its results on the data used. It does not establish clinical validation or authorisation to diagnose or treat patients. Proposed healthcare applications are retained as the team’s goals, not demonstrated capabilities.
La Paz. Machine Learning. 2021
(La Paz, 2021) High demand for medical care can overwhelm hospitals and delay urgent treatment. Pneumonia in children aged 0–5 is one condition that requires prompt assessment. This project explores how machine learning could support X-ray analysis without replacing a medical diagnosis.
Childhood pneumonia is a major public health concern. The UNICEF article cited by the team, published on 20 January 2020, estimated more than 800,000 deaths among children under five each year, roughly one every 39 seconds, and stated that almost all were preventable. These figures reflect the project’s historical context. Transmission of the pathogens that cause pneumonia is only one factor involved; it does not, by itself, explain that mortality.
Problem:
Taking into account the enormous number of cases of pneumonia in children under 5 years of age, how can we implement Artificial Intelligence to make the diagnosis of childhood pneumonia more efficient?
Objective:
The project aims to develop a prototype that analyses X-rays of children aged three or younger to identify patterns associated with pneumonia. The team proposes that, with appropriate validation, such a tool could help prioritise cases. This project’s results do not establish that it can diagnose patients or replace medical assessment.
Datasets:
We used the “Chest X-Ray Images (Pneumonia)” dataset available on Kaggle. The team worked with 5,863 images and reports a split into training (89.4%) and testing (10.6%) data. Each group contains two classes: “NORMAL”, for X-rays without pneumonia, and “PNEUMONIA”, for X-rays labelled as pneumonia.

The second part is called: “PNEUMONIA” and is where the x-rays of infants who have pneumonia are found:


Pneumonia identification process:
To prepare the X-rays, we used grayscale conversion from the cv2 library. This simplifies the image representation for the model. Conversion alone does not remove noise or guarantee better accuracy: preprocessing choices must be evaluated using validation data.

The image above shows the lungs after grayscale conversion.
We then normalised each image’s pixel values to a range of 0 to 1.
We also used Keras to augment the training data with rotations, zooming, and horizontal and vertical shifts. The aim was to add variety to the training data and improve the model’s ability to generalise.
The model analyses the processed images to learn patterns that distinguish the two classes. Lung opacities were among the features the team aimed to study; their clinical interpretation requires qualified professionals.
Models:
We implemented a convolutional neural network (CNN), a type of neural network that can learn visual patterns from labelled images.
Convolutions apply a kernel, or small matrix, to different regions of an image. This produces feature maps that help the network learn visual patterns.
Results
- Training, validation and test accuracy, and loss

- Confusion matrix

We attempted to calculate a confusion matrix, but a version compatibility issue prevented us from obtaining it.
- Accuracy:

- Image tests:

Under the labelling scheme used, an output close to 1 corresponds to healthy lungs and an output close to 0 to pneumonia. The examples shown match their labels. This limited check does not replace a full evaluation of the model.
Conclusions and Recommendations
Based on this work, we suggest the following:
- Evaluate whether grayscale conversion improves model performance.
- When working in Google Colab, resize the images to limit memory use and allow the dataset to be processed.
- Evaluate data augmentation techniques to improve generalisation.
- Apply normalisation consistently during training and prediction.
References:
https://www.kaggle.com/paultimothymooney/chest-xray-pneumonia
http://acodigo.blogspot.com/2013/05/procesamiento-de-imagenes-en-opencv.htmlHow to Configure Image Data Augmentation in Keras. A Machine Learning Mastery guide to expanding a training dataset through image transformations.
SyDoJa

Pneumonia
“Analysing X-rays for pneumonia in children aged 0–5 using machine learning”
MEMBERS:
Dylan Chambi Frontanilla
Joseph Anthony Meneses Salguero
Samuel Matias Escobar Bejarano
COURSE:
Machine Learning
LA PAZ 10/09 — BOLIVIA-2021
More artificial intelligence!
Saturdays.AI makes AI more accessible through shared learning and projects with a social purpose. Our motto is AI4ALL IS AI4GOOD.
A story from the Saturdays.AI community. Originally published on Nov 11, 2021.
← More community stories


