This project focuses on building and evaluating Artificial Neural Network (ANN) models for multiclass classification of fetal health conditions using Cardiotocography (CTG) data.
The notebook demonstrates a complete machine learning workflow including:
- Data preprocessing and cleaning
- Feature scaling
- Baseline neural network development
- Regularization using Dropout
- Hyperparameter optimization using KerasTuner
- Model evaluation and interpretation
- Confidence analysis using Softmax probabilities
The goal of the project is to classify fetal health status into:
- Normal
- Suspect
- Pathological
using neural networks implemented with TensorFlow/Keras.
Cardiotocography (CTG) is a medical monitoring technique used during pregnancy to evaluate fetal well-being.
The dataset used in this project contains numerical measurements extracted from CTG exams, including patterns related to:
- Fetal heart rate
- Accelerations and decelerations
- Uterine contractions
- Variability measurements
- Abnormal fetal behavior indicators
The main objective is to build a deep learning model capable of predicting fetal health condition based on CTG measurements.
The target variable is:
fetal_healthThe model classifies fetal condition into three categories:
| Class | Medical Meaning |
|---|---|
| Normal | Healthy fetal condition |
| Suspect | Potential abnormalities requiring monitoring |
| Pathological | High-risk condition requiring medical attention |
Accurate fetal health prediction systems can support medical professionals by:
- Assisting early detection of fetal risk
- Reducing delayed diagnosis
- Supporting clinical decision-making
- Prioritizing high-risk pregnancy cases
- Improving maternal and fetal healthcare outcomes
This makes multiclass classification especially valuable in healthcare AI applications where prediction reliability is critical.
The dataset contains CTG (Cardiotocography) measurements collected during pregnancy.
Cardiotocography is commonly used to monitor:
- Fetal heart rate
- Uterine contractions
- Overall fetal well-being
The original target column is:
fetal_healthOriginal classes:
| Original Label | Meaning |
|---|---|
| 1 | Normal |
| 2 | Suspect |
| 3 | Pathological |
For compatibility with TensorFlow multiclass classification requirements, the target was transformed into:
| Encoded Label | Meaning |
|---|---|
| 0 | Normal |
| 1 | Suspect |
| 2 | Pathological |
Transformation:
y = df['fetal_health'] - 1
- Python
- NumPy
- Pandas
- Matplotlib
- Scikit-learn
- TensorFlow
- Keras
- KerasTuner
Several preprocessing steps were applied before training the neural networks.
The following checks were performed:
- Verified missing values
- Verified feature data types
- Removed duplicate rows
StandardScaler was applied to normalize the input features.
Why scaling is important for neural networks:
- Faster convergence
- Stable gradient updates
- Improved optimization performance
- Better overall model training
Three ANN approaches were implemented and compared.
The first model was designed as a simple feedforward neural network to establish baseline performance.
- Dense layer โ 64 neurons (ReLU)
- Dense layer โ 32 neurons (ReLU)
- Output layer โ 3 neurons (Softmax)
- Optimizer: Adam
- Loss Function: Sparse Categorical Crossentropy
- Metric: Accuracy
EarlyStopping was used to reduce unnecessary training and prevent overfitting.
The second model introduced Dropout layers to improve generalization and reduce overfitting.
Dropout randomly disables neurons during training, which:
- Reduces overfitting
- Improves generalization
- Makes the model more robust
- Dense(64, ReLU)
- Dropout(0.3)
- Dense(32, ReLU)
- Dropout(0.2)
- Dense(3, Softmax)
KerasTuner with Hyperband optimization was used to automatically search for better hyperparameters.
The tuner searched for:
- Number of neurons
- Dropout rate
- Optimizer type
- Adam
- RMSprop
- Nadam
This produced the best-performing model in the project.
Multiple evaluation methods were used.
The models were evaluated using:
- Precision
- Recall
- F1-score
- Accuracy
Confusion matrices were used to visualize prediction performance across all classes.
The project also explored Softmax probability confidence.
Example:
max_probs = np.max(pred, axis=1)
This represents the confidence score of the model for each prediction.
In medical AI systems, confidence analysis is important because:
- Low-confidence predictions may require human review
- High-confidence predictions are generally more reliable
- Thresholds can improve prediction precision
Example strategy:
- High confidence โ accept prediction
- Low confidence โ send for expert verification
The Hyperparameter-Tuned ANN achieved the best overall performance.
- Better hyperparameter selection
- Improved generalization
- More balanced classification performance
- Reduced overfitting
Several important deep learning concepts were demonstrated throughout the project:
- Proper preprocessing
- Feature scaling
- Early stopping
- Dropout regularization
- Hyperparameter optimization
The project also highlighted:
- Difficulty in separating borderline classes
- Importance of confidence-based prediction
- The challenge of multiclass medical classification
This project represents an applied introduction to neural networks using TensorFlow/Keras and demonstrates a full deep learning workflow from preprocessing to model optimization and evaluation.
It also reflects iterative experimentation and practical ANN development practices commonly used in real-world machine learning projects.