This project uses a Random Forest Classifier to predict whether a patient has diabetes based on medical diagnostic measurements from the Pima Indians Diabetes Dataset.
The project covers the complete machine learning workflow, including data preprocessing, hyperparameter tuning with GridSearchCV, model evaluation, and feature importance analysis.
- Dataset: Pima Indians Diabetes Database
- Target Variable: Outcome
- 0: Non-Diabetic
- 1: Diabetic
Features include:
- Pregnancies
- Glucose
- BloodPressure
- SkinThickness
- Insulin
- BMI
- DiabetesPedigreeFunction
- Age
- Python
- NumPy
- Pandas
- Matplotlib
- Seaborn
- Scikit-learn
- Jupyter Notebook
- Load the dataset
- Exploratory Data Analysis (EDA)
- Data cleaning
- Train-Test Split
- Train a Random Forest Classifier
- Hyperparameter tuning using GridSearchCV
- Model evaluation
- Feature importance analysis
The Random Forest model was optimized using GridSearchCV with 5-fold cross-validation.
The following hyperparameters were tested:
- n_estimators: 20, 50, 100
- max_depth: 3, 5, 7, 9
Best parameters found:
- n_estimators: 100
- max_depth: 5
- Accuracy: 74.0%
- Confusion Matrix
- Classification Report
- Feature Importance Visualization
| Model | Accuracy |
|---|---|
| K-Nearest Neighbors | 79.2% |
| Decision Tree | 78.6% |
| Random Forest | 74.0% |
Although Random Forest is generally more powerful than a single Decision Tree, it did not achieve the highest accuracy on this dataset. This demonstrates that model performance depends on the dataset and that a more complex algorithm is not always the best choice.
Through this project, I learned how to:
- Train a Random Forest Classifier
- Tune hyperparameters using GridSearchCV
- Apply cross-validation
- Evaluate a classification model
- Interpret feature importance
- Compare multiple machine learning models
Project_03_Diabetes/
│
├── diabetes_random_forest.ipynb
├── diabetes.csv
├── README.md
├── requirements.txt
└── .gitignore
Taha Lazar