Data Science Lab Report:
Chronic Kidney Disease
Prediction
1. Business Understanding
Objective
Chronic Kidney Disease (CKD) is a major global health concern, leading to renal failure, cardiovascular
diseases, and premature death. Early detection can significantly improve patient outcomes through timely
intervention. This project aims to develop a machine learning model to predict CKD based on clinical
parameters, enabling early diagnosis and treatment.
Key Goals:
● Predict the likelihood of CKD using patient health data
● Identify the most significant features contributing to CKD
● Deploy the model as a web application using Django for real-time predictions
● Provide a user-friendly interface for healthcare providers and patients
Stakeholders:
● Healthcare Providers: For early diagnosis and patient management
● Patients: To monitor their health status proactively
● Researchers: For further studies on CKD risk factors
● Medical Institutions: For integration into their diagnostic workflows
2. Data Understanding
Dataset Overview
● Source: Kaggle
● Rows: 400
● Columns: 26 (including target variable classification)
● Features: Clinical parameters such as age, blood pressure, albumin levels, etc.
● Target Variable: classification (binary: ckd or notckd)
Data Types:
● Numerical Features:
● age: Patient's age in years
● blood_pressure: Blood pressure in mmHg
● specific_gravity: Urine specific gravity
● albumin: Albumin level in urine
● sugar: Sugar level in urine
● blood_glucose_random: Random blood glucose level
● blood_urea: Blood urea level
● serum_creatinine: Serum creatinine level
● sodium: Sodium level in blood
● potassium: Potassium level in blood
● hemoglobin: Hemoglobin level
● packed_cell_volume: Packed cell volume
● white_blood_cell_count: White blood cell count
● red_blood_cell_count: Red blood cell count
● Categorical Features:
● red_blood_cells: Red blood cells presence (Normal/Abnormal)
● pus_cell: Pus cell presence (Normal/Abnormal)
● pus_cell_clumps: Pus cell clumps presence (Yes/No)
● bacteria: Bacteria presence (Yes/No)
● hypertension: Hypertension status (Yes/No)
● diabetes_mellitus: Diabetes mellitus status (Yes/No)
● coronary_artery_disease: Coronary artery disease status (Yes/No)
● appetite: Appetite status (Good/Poor)
● pedal_edema: Pedal edema presence (Yes/No)
● anemia: Anemia status (Yes/No)
Exploratory Data Analysis (EDA)
● Missing Values: Handled using median (numerical) and mode (categorical) imputation
● Class Distribution:
● ckd: Majority class
● notckd: Minority class
● Key Insights:
● High blood urea and serum creatinine correlate strongly with CKD
● Hypertension and diabetes mellitus are significant risk factors
● Hemoglobin levels show strong correlation with CKD status
● Specific gravity and albumin levels are important indicators
Visualizations:
● Scatter Plots: Relationships between features and CKD
● Box Plots: Distribution of numerical features across classes
● Correlation Heatmap: Identified multicollinearity
● Feature Importance Plots: Highlighted key predictors
3. Data Preparation
Data Cleaning
● Handling Missing Values:
● Numerical: Filled with median
● Categorical: Filled with mode
● Outliers: Addressed using visualization (box plots)
● Data Type Conversion: Ensured proper data types for all features
Feature Engineering
● Label Encoding: Converted categorical variables to numerical
● Feature Selection:
● Dropped correlated features to avoid multicollinearity
● Final features: 22 clinical parameters
● Feature Scaling: Applied StandardScaler for normalization
Data Splitting
● Train-Test Split: 75% training, 25% testing
● Cross-Validation: Implemented for robust model evaluation
4. Modeling
Algorithms Used
1. Logistic Regression (LR)
● Simple, interpretable, suitable for binary classification
● Regularization applied to prevent overfitting
1. Decision Tree (DT)
● Handles non-linear relationships
● Provides feature importance
● Pruning applied to control tree depth
1. K-Nearest Neighbors (KNN)
● Non-parametric approach
● Optimal k-value determined through cross-validation
1. Support Vector Machine (SVM)
● Effective for high-dimensional data
● Kernel trick applied for non-linear classification
1. Random Forest (RF)
● Ensemble method
● Reduces overfitting through bagging
● Feature importance analysis
Training Process
● All models trained on standardized data
● Hyperparameters tuned using cross-validation
● Model performance evaluated using multiple metrics
5. Evaluation
Metrics
| Model | Accuracy | Precision | Recall | F1-Score ||----------------------|----------|-----------|--------|----------||
Logistic Regression | 99% | 0.99 | 0.99 | 0.99 || Decision Tree | 100% | 1.00 | 1.00 | 1.00 || K-Nearest
Neighbors | 98% | 0.98 | 0.98 | 0.98 || SVM | 99% | 0.99 | 0.99 | 0.99 || Random Forest | 100% | 1.00 |
1.00 | 1.00 |
Confusion Matrix Analysis
● High true positive/negative rates across all models
● Decision Tree and Random Forest achieved perfect classification
● Minimal false positives/negatives in other models
Key Findings
● Best Model: Decision Tree and Random Forest (100% accuracy)
● Feature Importance:
1. Hemoglobin
1. Serum Creatinine
1. Blood Urea
1. Hypertension
1. Diabetes Mellitus
6. Deployment
Web Application Architecture
● Backend:
● Django framework for robust web development
● RESTful API design for scalability
● Model persistence using pickle
● StandardScaler integration for real-time feature scaling
● Error handling and validation
● Frontend:
● Responsive Bootstrap design
● User-friendly form interface
● Real-time validation
● Interactive results display
● Progress bars for probability visualization
Deployment Components
1. Model Integration:
2. python
3. Apply to [Link]
4. # Model loading and prediction
5. model = [Link](open('models/RF_model.sav', 'rb'))
6. scaler = [Link](open('models/[Link]', 'rb'))
1. API Endpoints:
● /predict/: Main prediction endpoint
● /compare/: Model comparison endpoint
● /metrics/: Performance metrics endpoint
1. User Interface:
● Input form with validation
● Results display with confidence scores
● Model comparison visualization
● Performance metrics dashboard
1. Security Measures:
● CSRF protection
● Input validation
● Error handling
● Secure model storage
Deployment Process
1. Environment Setup:
● Python virtual environment
● Required packages installation
● Database configuration
1. Model Deployment:
● Model serialization
● Scaler persistence
● Feature preprocessing pipeline
1. Application Deployment:
● Django application setup
● Static files configuration
● Database migrations
● Server configuration
1. Testing:
● Unit tests
● Integration tests
● Performance testing
● Security testing
User Interface Screenshots
● Input Form: Modern, responsive design with validation
● Results Page: Clear visualization of prediction and confidence
● Comparison Page: Interactive model performance comparison
● Metrics Dashboard: Comprehensive performance metrics
7. Conclusion & Future Work
Achievements
● High-accuracy prediction models
● User-friendly web interface
● Comprehensive feature analysis
● Robust deployment architecture
Limitations
● Small dataset size
● Potential overfitting in some models
● Limited to binary classification
Future Improvements
1. Data Enhancement:
● Collect more diverse data
● Include additional clinical parameters
● Implement data augmentation
1. Model Enhancement:
● Experiment with deep learning
● Implement ensemble methods
● Add explainability (SHAP/LIME)
1. Application Enhancement:
● Add user authentication
● Implement patient history tracking
● Add export functionality
● Mobile application development
1. Integration:
● Hospital management systems
● Electronic health records
● Telemedicine platforms
Appendix
● Code Repository: GitHub Repository
● Dataset: kidney_disease.csv
● Documentation: Project Documentation
This report follows the CRISP-DM framework and demonstrates a comprehensive end-to-end workflow
from data analysis to deployment, with a focus on practical implementation and future scalability.