This project implements an end-to-end machine learning pipeline for predicting medical conditions based on patient symptoms. Using a dataset containing symptom profiles for various diseases, the project evaluates multiple classification algorithms, addresses class imbalance, and builds a robust ensemble model that combines predictions for enhanced diagnostics.
The core implementation is detailed in Disease Prediction.ipynb.
- Project Architecture
- Dataset Analysis
- Data Preprocessing & Resampling
- Model Evaluation & Cross-Validation
- Model Training & Performance
- Ensemble Model Integration
- Real-World Applications
- Future Work
The diagnostic pipeline consists of data ingestion, preprocessing, resampling, cross-validation, model training, and ensemble majority voting.
graph TD
A[Raw Dataset: 10 Symptoms, 38 Diseases] --> B[Label Encoding for Target Classes]
B --> C[Visualizing Class Imbalance]
C --> D[Random Over-Sampling]
D --> E[Resampled Dataset: 3,420 Samples]
E --> F[Stratified 5-Fold Cross-Validation]
E --> G[Model Training]
G --> H1[Support Vector Classifier]
G --> H2[Gaussian Naive Bayes]
G --> H3[Random Forest Classifier]
H1 --> I[Ensemble Combined Model: Majority Voting]
H2 --> I
H3 --> I
I --> J[Disease Predictor Function]
The dataset is loaded from improved_disease_dataset.csv and contains 2,000 patient records.
The model uses 10 binary input features representing the presence (1) or absence (0) of specific symptoms:
- Fever
- Headache
- Nausea
- Vomiting
- Fatigue
- Joint Pain
- Skin Rash
- Cough
- Weight Loss
- Yellow Eyes
There are 38 unique diseases classified by the model, including conditions such as:
- Malaria, Dengue, Typhoid
- Hepatitis A, B, C, D, E
- Diabetes, Hypertension, Hypothyroidism, Hyperthyroidism
- Tuberculosis, Pneumonia, Bronchial Asthma
- Peptic ulcer disease, GERD, Gastroenteritis
- Acne, Psoriasis, Impetigo
The target column disease consists of text labels. We apply the LabelEncoder to map these category labels into numerical indices.
Prior to training, the dataset exhibits a noticeable class imbalance. For example:
- Paralysis (brain hemorrhage) has 90 samples.
- Alcoholic hepatitis has only 10 samples.
- AIDS, Jaundice, and Allergy have 30 samples each.
This imbalance can bias machine learning models towards predicting the majority classes. To resolve this, we use RandomOverSampler from the imblearn library. This duplicates minority class samples, bringing all 38 classes to a uniform count of 90 samples, resulting in a balanced dataset of 3,420 records.
To obtain an unbiased estimate of generalization performance, we use Stratified 5-Fold Cross-Validation. Stratification ensures that each fold maintains the same percentage of samples for each of the 38 classes.
The mean accuracy scores across the 5 folds are as follows:
| Model | Fold Scores | Mean Accuracy |
|---|---|---|
| Decision Tree | [0.5497, 0.5439, 0.5351, 0.5365, 0.5249] |
53.80% |
| Random Forest | [0.5497, 0.5570, 0.5409, 0.5278, 0.5278] |
54.06% |
| SVM | [0.5132, 0.5117, 0.4971, 0.4825, 0.4956] |
50.00% |
An accuracy in the range of 50% to 54% is expected due to the following structural characteristics of the dataset:
- High Class Cardinality: The model classifies inputs into 38 distinct disease categories.
- Low Feature Dimensionality: The input vector consists of only 10 binary features.
- Overlap of Symptoms: Multiple diseases share identical symptom profiles under this limited feature set. For instance, fever, headache, and fatigue are common to Malaria, Dengue, Typhoid, and Influenza, making perfect differentiation mathematically impossible without additional diagnostic features.
We train individual classifiers on the balanced dataset and evaluate their performance on the training data.
The Support Vector Classifier is trained using a radial basis function (RBF) kernel.
- Accuracy: 60.53%
- Performance: The SVM model successfully maps the decision boundaries for the dominant symptom combinations, showing clear diagonal alignments in the confusion matrix but struggling with highly overlapping symptom classes.
The Naive Bayes classifier assumes feature independence given the class.
- Accuracy: 37.98%
- Performance: This model performs poorly here because symptoms are highly correlated (e.g., nausea and vomiting often occur together). The independence assumption leads to misclassifications and a dispersed confusion matrix.
Random Forest is an ensemble of decision trees.
- Accuracy: 68.98%
- Performance: This model achieves the highest individual accuracy, as it effectively captures non-linear feature interactions (combinations of symptoms) and mitigates overfitting.
To improve prediction robustness and mitigate individual model errors, we combine the predictions of the three models using an Ensemble Majority Vote (Mode).
If the three models predict different classes, the mode determines the final prediction. This voting scheme prevents a single model's error from dictating the final output.
- Combined Model Accuracy: 60.64%
The prediction function predict_disease accepts a comma-separated string of symptoms, maps them to a binary vector, and queries the three models:
def predict_disease(input_symptoms):
input_symptoms = input_symptoms.split(",")
input_data = [0] * len(symptom_index)
for symptom in input_symptoms:
if symptom in symptom_index:
input_data[symptom_index[symptom]] = 1
input_df = pd.DataFrame([input_data], columns=symptoms)
rf_pred = encoder.classes_[rf_model.predict(input_df)[0]]
nb_pred = encoder.classes_[nb_model.predict(input_df)[0]]
svm_pred = encoder.classes_[svm_model.predict(input_df)[0]]
final_pred = mode([rf_pred, nb_pred, svm_pred])
return {
"Random Forest Prediction": rf_pred,
"Naive Bayes Prediction": nb_pred,
"SVM Prediction": svm_pred,
"Final Prediction": final_pred
}print(predict_disease("skin_rash,fever,headache"))Output:
{
"Random Forest Prediction": "Peptic ulcer disease",
"Naive Bayes Prediction": "Impetigo",
"SVM Prediction": "Peptic ulcer disease",
"Final Prediction": "Peptic ulcer disease"
}Analysis: Random Forest and SVM agree on "Peptic ulcer disease", while Naive Bayes predicts "Impetigo". The ensemble outputs "Peptic ulcer disease" as the final prediction by majority vote.
This disease prediction model can be applied in several domains within the digital health and clinical technology sectors:
Medical software can integrate this pipeline to assist general practitioners. When a doctor inputs a patient's symptoms during an intake session, the system provides a ranked list of potential conditions. This serves as a secondary check, reducing cognitive load and helping prevent diagnostic blind spots.
Telemedicine applications can use this predictor as an initial screening tool. Patients entering a virtual queue describe their symptoms, and the model classifies their probable condition. This aids in automated triage—routing low-risk cases (e.g., allergies) to standard scheduling and flagging high-risk symptom profiles (e.g., chest pain, breathing difficulties) for immediate clinical intervention.
In rural or low-income areas with limited access to specialized medical personnel, healthcare workers can use this tool on mobile devices. By entering symptoms, they receive guidance on potential diagnoses, enabling them to make informed decisions regarding patient treatment or referral to regional hospitals.
Consumer-facing wellness applications can leverage symptom tracking to help users understand their health trends. By logging symptoms over time, the app can recommend when a user should schedule a check-up, promoting preventive care and early detection of chronic conditions.
To improve accuracy and make the system viable for clinical deployment, the following enhancements are recommended:
- Expand Feature Space: Incorporate additional symptoms, vital signs (blood pressure, heart rate, temperature), and basic laboratory results to resolve class overlaps.
- Incorporate Patient History: Include demographic variables (age, geographic location, travel history) and chronic history to contextualize symptom presentation.
- Weight-Based Ensemble: Replace the simple majority vote (Mode) with a weighted voting system based on model confidence scores, or use a Stacking Classifier.




