Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fetal Health Prediction

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.

Python scikit-learn Flask Jupyter

Overview

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.

Approach

  1. 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
  2. Train/test split — 80/20 split with random_state=42
  3. NormalizationMinMaxScaler fit on the training set only
  4. Model selection — six classifiers compared via GridSearchCV with stratified k-fold cross-validation, scored on macro recall to account for class imbalance: SVM, Random Forest, Logistic Regression, KNN, Decision Tree, and AdaBoost
  5. 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)
  6. 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
  7. Deployment — Flask app (app.py) that loads fetal.pkl and scaling.pkl to serve predictions through index.html

Results

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.

Project Structure

├── 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

Tech Stack

  • Python — pandas, NumPy, scikit-learn
  • Visualization — Matplotlib, Seaborn
  • Web — Flask, HTML/CSS
  • Notebook — Jupyter

Getting Started

  1. Clone the repository:

    git clone https://github.com/techieshreya/Fetal-Health-Prediction-ML-Project.git
    cd Fetal-Health-Prediction-ML-Project
  2. Install dependencies:

    pip install flask numpy pandas scikit-learn matplotlib seaborn
  3. Run the web app:

    python app.py

    Then open http://127.0.0.1:5000/, enter the CTG measurements, and get a prediction.

  4. To explore or retrain the models, open fetal_health.ipynb in Jupyter.

Disclaimer

This project is for educational purposes only and is not a substitute for professional medical judgment.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages