End-to-end machine learning project that classifies fetal health from cardiotocography (CTG) features — from EDA and model selection through to a deployed Flask web app.
Cardiotocograms (CTGs) are a low-cost way to assess fetal well-being during pregnancy. This project trains classifiers on the well-known Fetal Health dataset (2,126 CTG records, 21 numeric features such as baseline heart rate, accelerations, decelerations, and short/long-term variability) to predict one of three classes:
- 1 — Normal
- 2 — Suspect
- 3 — Pathological
The trained model is served through a Flask web app: users enter CTG measurements in a browser form and receive an instant health classification.
- Exploratory data analysis — null/duplicate checks, class-distribution analysis (the dataset is highly imbalanced: 1,655 Normal / 295 Suspect / 176 Pathological), correlation heatmap, box plots, and scatter plots
- Train/test split — 80/20 split with
random_state=42 - Normalization —
MinMaxScalerfit on the training set only - Model selection — six classifiers compared via
GridSearchCVwith stratified k-fold cross-validation, scored on macro recall to account for class imbalance: SVM, Random Forest, Logistic Regression, KNN, Decision Tree, and AdaBoost - Feature selection — Recursive Feature Elimination (RFE) with logistic regression, selecting the 10 most predictive features (e.g. baseline value, accelerations, uterine contractions, prolonged decelerations, abnormal short-term variability, histogram statistics)
- Final model — a tuned Random Forest (
max_depth=9,n_estimators=80) trained on the 10 selected, normalized features; model and scaler serialized with pickle - Deployment — Flask app (
app.py) that loadsfetal.pklandscaling.pklto serve predictions throughindex.html
Test-set performance (from the notebook outputs):
| Model | Features | Accuracy | Precision (weighted) | Recall (weighted) | F1 (weighted) |
|---|---|---|---|---|---|
| SVM (C=100, RBF) | all 21 | 0.930 | 0.934 | 0.930 | 0.931 |
| Random Forest (final) | 10 (RFE) | 0.941 | 0.940 | 0.941 | 0.939 |
Cross-validated macro-recall scores on the 10 selected features: Random Forest 0.877, KNN 0.841, Decision Tree 0.825, SVM 0.822, AdaBoost 0.804, Logistic Regression 0.776.
├── fetal_health.ipynb # EDA, model selection, feature selection, training
├── fetal_health.csv # Dataset (2,126 CTG records)
├── app.py # Flask app serving predictions
├── index.html # Web form for entering CTG features
├── fetal.pkl # Trained Random Forest model
├── scaling.pkl # Fitted MinMaxScaler
└── projectname.pkl # Additional serialized artifact
- Python — pandas, NumPy, scikit-learn
- Visualization — Matplotlib, Seaborn
- Web — Flask, HTML/CSS
- Notebook — Jupyter
-
Clone the repository:
git clone https://github.com/techieshreya/Fetal-Health-Prediction-ML-Project.git cd Fetal-Health-Prediction-ML-Project -
Install dependencies:
pip install flask numpy pandas scikit-learn matplotlib seaborn
-
Run the web app:
python app.py
Then open
http://127.0.0.1:5000/, enter the CTG measurements, and get a prediction. -
To explore or retrain the models, open
fetal_health.ipynbin Jupyter.
This project is for educational purposes only and is not a substitute for professional medical judgment.