· Fabian Schreuder · Data Science Projects  · 6 min read

Predicting Chronic Kidney Disease: A Data-Driven Approach Using Machine Learning

Leveraging machine learning on clinical data to build a robust model for early Chronic Kidney Disease (CKD) detection, improving patient outcomes and potentially reducing healthcare costs.

Leveraging machine learning on clinical data to build a robust model for early Chronic Kidney Disease (CKD) detection, improving patient outcomes and potentially reducing healthcare costs.

Chronic Kidney Disease (CKD) is a silent but growing global health issue affecting roughly 10% of adults worldwide. Often developing as a complication of diseases like diabetes and hypertension, CKD involves a gradual loss of kidney function. Early detection is crucial to slow its progression and improve patient outcomes, but traditional diagnostic methods can be invasive and slow.

This project aimed to address this challenge by developing a machine learning model capable of accurately predicting the onset of CKD using readily available clinical data. The goal was to create an efficient, potentially less invasive tool to identify at-risk individuals, particularly those with diabetes.

The Challenge & Dataset

We started with a dataset containing information from 400 patients across 24 features (attributes) and one target variable indicating CKD presence (‘ckd’ or ‘notckd’). The features included:

  • Demographics: Age
  • Blood Samples: Hemoglobin (hemo), Packed Cell Volume (pcv), Red Blood Cell Count (rbcc), Blood Glucose (bgr), Blood Urea (bu), Serum Creatinine (sc), Sodium (sod), Potassium (pot), White Blood Cell Count (wbcc).
  • Urine Samples: Specific Gravity (sg), Albumin (al), Sugar (su), Red Blood Cells (rbc), Pus Cells (pc), Bacteria (ba), Pus Cell Clumps (pcc).
  • Clinical Observations: Blood Pressure (bp), Hypertension (htn), Diabetes Mellitus (dm), Coronary Artery Disease (cad), Appetite (appet), Pedal Edema (pe), Anemia (ane).

Initial exploration revealed common real-world data challenges: missing values (around 10% overall) and some outliers. The dataset was also slightly imbalanced regarding the target classes.

Our Approach: Methodology

We adopted a systematic data science approach to build and evaluate our predictive models:

  1. Data Exploration & Preprocessing:

    • Univariate & Bivariate Analysis: We analyzed variable distributions (histograms, bar charts) and relationships (box plots comparing features across CKD classes, correlation heatmaps for continuous variables, chi-square tests for categorical variables) to understand the data and identify potential predictors.
    • Missing Value Treatment: Given the significant number of missing values (>10%), we employed targeted imputation strategies. For categorical variables, we used Mode imputation stratified by age groups (0-20, 21-40, 41-60, 60+). For continuous variables, we utilized Regression imputation to predict missing values based on other features.
    • Outlier Handling: We identified outliers using the Interquartile Range (IQR) method. As the outliers were few (<5%) and didn’t drastically skew distributions, we chose to remove them to potentially improve model robustness.
  2. Feature Engineering:

    • Several continuous variables (pcv, hemo, rbcc) exhibited left-skewed distributions. To normalize them for better model performance, we applied a log transformation followed by a Z-score transformation.
  3. Modeling Strategy:

    • Train-Test Split: We split the data into a 70% training set and a 30% testing set. This ratio was chosen to provide sufficient data for training given the dataset size, while retaining a reasonably large test set for robust evaluation.
    • Model Selection:
      • Decision Tree: We first built a Decision Tree model using only the variables identified as most highly correlated with CKD in our initial analysis (hemo, pcv, rbcc, sg, al, htn, dm). Decision Trees are interpretable and computationally efficient, providing a good baseline.
      • Random Forest: Recognizing the power of ensemble methods, especially for handling mixed data types and potentially mitigating overfitting, we trained a Random Forest model using all available features. Random Forests build multiple decision trees and aggregate their predictions, typically leading to higher accuracy and robustness.
    • Cross-Validation: To rigorously assess the Random Forest model’s stability and generalizability, and mitigate the risk of overfitting to a single train-test split (especially with a smaller dataset), we performed 5-fold Cross-Validation. This involves splitting the data into 5 folds, training on 4, testing on 1, and repeating this process 5 times with different folds held out for testing.
  4. Evaluation:

    • We used standard classification metrics: Accuracy, Precision, Recall, and F1-Score. Given the slight class imbalance and the clinical context (where missing a CKD case - false negative - can be critical), Recall was a particularly important metric.
    • Confusion Matrices were generated to visualize true positives, true negatives, false positives, and false negatives.
    • Feature Importance analysis was conducted for both models to understand which clinical factors were most influential in predicting CKD.

Results & Key Findings

Our modeling efforts yielded promising results:

  • Model 1: Decision Tree (Selected Features):

    • Achieved an accuracy of 97%, with Precision and Recall both at 93%.
    • Feature importance highlighted sg, al, hemo, and pcv as the key decision drivers.
  • Model 2: Random Forest (All Features, Train-Test Split):

    • Outperformed the Decision Tree with 98% accuracy, 100% precision, and 93% recall.
    • Feature importance confirmed the significance of sg, hemo, pcv, and al, but also incorporated contributions from other variables.
  • Model 3: Random Forest (5-Fold Cross-Validation):

    • Demonstrated strong consistency with a mean accuracy of 98% across the folds (standard deviation of 2%). This validated the robustness of the Random Forest model and increased confidence in its ability to generalize to unseen data.

Across all models, four key clinical indicators consistently emerged as the most important predictors for CKD:

  • Specific Gravity (sg)
  • Albumin (al)
  • Hemoglobin (hemo)
  • Packed Cell Volume (pcv)

These findings align well with existing medical literature linking these factors to kidney function and CKD progression.

Discussion & Impact

The results demonstrate the potential of machine learning to accurately predict CKD using routinely collected clinical data. While both models performed exceptionally well, the Random Forest model, especially when validated with 5-fold cross-validation, proved slightly superior in accuracy and robustness. Its ability to leverage all features and its inherent resistance to overfitting (further bolstered by CV) make it the preferred model.

The high performance metrics (97-100%) are encouraging, though with smaller datasets, vigilance against overfitting is always necessary. The cross-validation results strongly suggest our model generalizes well.

Potential Impact:

  • Early Detection: This model could serve as a valuable screening tool, identifying high-risk individuals earlier than traditional methods might allow.
  • Improved Patient Outcomes: Early intervention based on model predictions could slow disease progression and reduce complications.
  • Reduced Invasiveness & Cost: While some key predictors still require blood/urine tests, the model focuses prediction on a few key, relatively standard tests, potentially streamlining the diagnostic process and potentially reducing reliance on more complex or frequent testing initially.
  • Societal Benefit: Earlier detection and management can lessen the overall burden of CKD on patients and healthcare systems.

It’s crucial to remember that this model is a supportive tool, not a replacement for clinical judgment. Further validation on larger, diverse datasets and prospective studies would be needed before clinical implementation.

Conclusion

This project successfully developed and validated a machine learning model, primarily leveraging a Random Forest algorithm, capable of predicting Chronic Kidney Disease with high accuracy (98%) using standard clinical measurements. Key predictors identified included specific gravity, albumin, hemoglobin, and packed cell volume. By demonstrating the feasibility of data-driven CKD prediction, this work highlights the potential for AI to enhance early detection strategies, ultimately contributing to better patient care and reduced healthcare burdens.

Back to Blog

Related Posts

View All Posts »