Preparing the Dataset for Machine Learning
Building a practical health risk prediction tool starts with clean data. The project used a public dataset of 158,355 health records across 22 columns, covering 21 demographic, clinical, and lifestyle indicators with a binary heart_attack target. Categorical features were encoded, and numerical values were normalized with MinMaxScaler so that all features carried balanced weight during training.
To prevent data leakage, the dataset was split 80:20 (126,684 training rows and 31,671 test rows) using stratified sampling. SMOTE was applied only to the training set to handle class imbalance, balancing it to 151,766 samples while keeping the test set completely untainted. Hyperparameter tuning with RandomizedSearchCV evaluated F1-Scores across four algorithms: Random Forest, Linear SVM, K-Nearest Neighbors, and Logistic Regression.
- Dataset
- 158,355 rows / 22 columns
- Stratified split
- 80:20
- Random Forest accuracy
- 71.93%
- Random Forest ROC-AUC
- 0.8015

Serving Predictions via a Standalone Flask API
- Patient Health Data in iHealth Edu
- Laravel Application Backend
- Flask REST API Microservice
- Serialized Preprocessing Artifacts
- Random Forest Inference
- Structured Risk Payload
In iHealth Edu, developed in collaboration with Puskesmas Padangsari in Semarang, patient screening, educational modules, health records, and ESP32 IoT biometrics live inside a Next.js and Laravel web application. Instead of running Python models directly inside the web server, the machine learning workflow was separated into its own lightweight Flask REST API.
Using Joblib, the trained Random Forest model artifact (.pkl), MinMaxScaler, and feature mapping dictionaries were saved together. This ensures that live incoming patient data undergoes the exact same mathematical transformations computed during offline training. The Flask service was containerized with Docker and deployed on a Linux Ubuntu server.
Translating Probabilities into Useful Decision Support
Random Forest was chosen for the prototype because it achieved the highest documented accuracy of 71.93% and the highest ROC-AUC of 0.8015 among compared algorithms, even though Logistic Regression scored highest in F1 (0.6618) and KNN in recall (70.40%).
When an authorized health worker inputs patient vitals, the Flask API returns a structured JSON response containing the predicted risk category, calculated numerical probability, contextual rule-based risk factors, and global top-5 feature importances. The frontend displays these indicators as helpful visual context within the broader patient history record.

Clear Medical Boundaries and Practical Impact
- Present predictions and probability scores as statistical indicators rather than medical diagnoses.
- Display rule-based risk factors as helpful reference points rather than definite causes.
- Treat top feature importances as global model insights, not individualized medical advice.
- Protect patient records through strict role-based access control.
Machine learning in healthcare is most useful when its limits are clearly communicated. By pairing solid model training with transparent decision support, the platform provides helpful early risk insights while keeping clinical judgment firmly in the hands of healthcare professionals.