Skip to content

zubershk/Disease-Prediction-Using-Machine-Learning

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Disease Prediction Using Machine Learning

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.


Table of Contents

  1. Project Architecture
  2. Dataset Analysis
  3. Data Preprocessing & Resampling
  4. Model Evaluation & Cross-Validation
  5. Model Training & Performance
  6. Ensemble Model Integration
  7. Real-World Applications
  8. Future Work

1. Project Architecture

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]
Loading

2. Dataset Analysis

The dataset is loaded from improved_disease_dataset.csv and contains 2,000 patient records.

Features (Symptoms)

The model uses 10 binary input features representing the presence (1) or absence (0) of specific symptoms:

  1. Fever
  2. Headache
  3. Nausea
  4. Vomiting
  5. Fatigue
  6. Joint Pain
  7. Skin Rash
  8. Cough
  9. Weight Loss
  10. Yellow Eyes

Target Classes (Diseases)

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

3. Data Preprocessing & Resampling

Label Encoding

The target column disease consists of text labels. We apply the LabelEncoder to map these category labels into numerical indices.

Class Imbalance Mitigation

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.

Disease Class Distribution Before Resampling


4. Model Evaluation & Cross-Validation

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%

Insights on Accuracy

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.

5. Model Training & Performance

We train individual classifiers on the balanced dataset and evaluate their performance on the training data.

Support Vector Classifier (SVC)

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.

Confusion Matrix for SVM Classifier

Gaussian Naive Bayes (GaussianNB)

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.

Confusion Matrix for Naive Bayes Classifier

Random Forest Classifier (RandomForestClassifier)

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.

Confusion Matrix for Random Forest Classifier


6. Ensemble Model Integration

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%

Confusion Matrix for Combined Model

Predictor Implementation

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
    }

Example Usage

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.


7. Real-World Applications

This disease prediction model can be applied in several domains within the digital health and clinical technology sectors:

Clinical Decision Support Systems (CDSS)

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.

Telehealth and Digital Triage

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.

Remote and Under-resourced Healthcare

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.

Health Insurance and Wellness Apps

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.


8. Future Work

To improve accuracy and make the system viable for clinical deployment, the following enhancements are recommended:

  1. Expand Feature Space: Incorporate additional symptoms, vital signs (blood pressure, heart rate, temperature), and basic laboratory results to resolve class overlaps.
  2. Incorporate Patient History: Include demographic variables (age, geographic location, travel history) and chronic history to contextualize symptom presentation.
  3. Weight-Based Ensemble: Replace the simple majority vote (Mode) with a weighted voting system based on model confidence scores, or use a Stacking Classifier.

About

Machine Learning based disease prediction system that analyzes patient symptoms using ensemble learning, Random Forest, SVM, and Naive Bayes models to predict potential medical conditions and support intelligent healthcare diagnostics.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors