Introduction
Did you know that timely diagnosis of fetal health conditions can significantly reduce complications during pregnancy? With technological advancements, machine learning (ML) has emerged as a powerful tool to assist healthcare professionals in making accurate predictions and decisions.
In this blog, I’ll walk you through my project where I built an ML pipeline to classify fetal health based on Cardiotocogram (CTG) data. The goal was to predict the health status of a fetus as:
Normal
Suspect
Pathological
By leveraging a dataset of fetal health readings, I developed and evaluated models to improve prediction accuracy, gaining insights into the most critical factors influencing fetal health.
Dataset Overview
The dataset for this project was sourced from the Fetal Health Classification Dataset on Kaggle. It contains:
2,126 records with 22 features extracted from CTG readings.
A target variable
fetal_health
with three classes:1: Normal
2: Suspect
3: Pathological
Key Features
Some important features include:
Baseline value: Fetal heart rate (FHR) baseline (beats per minute).
Accelerations: Number of FHR accelerations per second.
Fetal movement: Number of fetal movements per second.
Uterine contractions: Number of uterine contractions per second.
Histogram properties: Statistical metrics from FHR histograms.
I identified key patterns and trends that informed my machine-learning approach by exploring and visualising this dataset.
Project Workflow
This project followed a structured pipeline:
Data Loading and Exploration
Load the dataset and explore its structure.
Visualize class distributions and feature relationships.
Data Preprocessing
Handle missing or infinite values.
Scale numerical features using
StandardScaler
.
Model Training and Evaluation
Train a baseline Random Forest model.
Evaluate its performance using accuracy, confusion matrix, and ROC-AUC metrics.
Hyperparameter Tuning
- Optimize the Random Forest model using GridSearchCV to improve performance.
Optimized Model Evaluation
- Train the model with the best hyperparameters and evaluate its performance.
Feature Importance Analysis
- Analyze the importance of features contributing to the predictions.
Exploratory Data Analysis (EDA)
Class Distribution
To start, I visualized the distribution of the target variable (fetal_health
) and found that the dataset is slightly imbalanced, with most records belonging to the Normal class.
Feature Correlation
I generated a correlation heatmap to understand feature relationships. It revealed:
Strong correlations between histogram-related features.
Features like
baseline value
andaccelerations
showed significant potential as predictors.
Model Training and Results
Baseline Model
I began with a baseline Random Forest Classifier, which achieved:
Accuracy: 92.4%
ROC-AUC Score: 0.95
However, there was room for improvement in classifying the minority classes (Suspect and Pathological).
Hyperparameter Tuning
Using GridSearchCV
, I optimized the following parameters:
n_estimators
: Number of trees in the forest.max_depth
: Maximum depth of the trees.
The best parameters were:
{'n_estimators': 200, 'max_depth': None}
Optimized Model
The optimized Random Forest model achieved:
Accuracy: 95.3%
ROC-AUC Score: 0.97
This improvement highlighted the importance of hyperparameter tuning for better generalization.
Feature Importance
Analyzing feature importance provided key insights:
Baseline value, accelerations, and histogram mean were the most significant predictors of fetal health.
Visualizing these helped interpret the model’s behaviour and ensured that the predictions aligned with domain knowledge.
Challenges and Solutions
Class Imbalance
Challenge: Fewer records in the Suspect and Pathological classes.
Solution: Experimented with class weights in the model to address this imbalance.
Outliers
Challenge: Outliers in features like
severe decelerations
.Solution: Applied boxplots and carefully handled outliers to reduce noise.
Future Improvements
While this project achieved strong results, there’s always room for improvement. Future steps could include:
Exploring advanced models like XGBoost or LightGBM.
Implementing cross-validation for more robust performance metrics.
Deploying the model using Flask, FastAPI, or Streamlit for real-world applications.
Conclusion
This project demonstrates the potential of machine learning in healthcare, particularly for assisting in early diagnosis and decision-making. By leveraging CTG data, we can build accurate, interpretable models to predict fetal health and support healthcare professionals.
Interested in exploring the project? Check out:
Feel free to share your thoughts or suggestions in the comments!