Diabetes Prediction Using Machine Learning
1. Introduction
Diabetes Prediction is a Machine Learning project that aims to predict whether a person is likely to have diabetes based on selected health-related information. Diabetes is a common medical condition that can be associated with factors such as blood glucose level, blood pressure, body mass index, and age.
Machine Learning can be used to analyze historical patient data and identify patterns that may be associated with diabetes. By learning from previously labeled patient records, a model can make a prediction for a new patient based on their available health information.
This is a Supervised Machine Learning problem because the training dataset contains input health information along with a known diabetes status. The model learns from these examples and uses the learned relationship to classify new patients.
The target variable has two possible categories:
0 – Not Diabetic
1 – Diabetic
Therefore, this is a Binary Classification problem. In this project, Logistic Regression is used because it is a simple and commonly used classification algorithm for predicting two possible outcomes.
The project is intended as an educational demonstration of Machine Learning classification. It should not be considered a medical diagnostic system or used to make real clinical decisions.
2. Objective
The main objective of this project is to build a Machine Learning model that learns from sample patient health data and predicts whether a new patient is classified as diabetic or not diabetic.
The project demonstrates important Machine Learning concepts such as:
Creating a patient dataset
Selecting input features
Selecting a target variable
Binary classification
Logistic Regression
Model training
Making predictions
Interpreting classification results
3. Features Used
The model uses four health-related features.
Glucose
Glucose represents the patient's blood glucose measurement. It is an important feature in the dataset because glucose levels can be associated with diabetes.
Blood Pressure
Blood pressure represents the patient's blood pressure measurement. It is included as one of the input features used by the model.
BMI
BMI stands for Body Mass Index. It is calculated using a person's weight and height and is included as a health-related feature in the sample dataset.
Age
Age represents the patient's age in years. Age can be an important factor when analyzing patterns in health data.
The target variable is:
Diabetes – Indicates whether the patient belongs to the diabetic or non-diabetic class.
4. Technologies Used
The following technologies are used:
Python – Main programming language.
Pandas – Used to create and manage the patient dataset.
Scikit-learn – Used to implement the Machine Learning algorithm.
Logistic Regression – Used for binary classification.
5. Dataset
The project uses a small sample dataset containing information about eight patients.
Each record contains:
Glucose level
Blood pressure
BMI
Age
Diabetes status
The diabetes status is represented numerically:
ValueMeaning0Not Diabetic1Diabetic
Dataset
Glucose BloodPressure BMI Age Diabetes
0 85 66 24.5 22 0
1 89 70 26.2 30 0
2 120 80 28.5 35 0
3 145 85 31.8 45 1
4 160 90 34.2 50 1
5 180 92 36.5 60 1
6 95 68 25.0 28 0
7 130 78 29.4 40 1
The model learns patterns from these labeled examples.
6. Working Principle
The system follows a basic Machine Learning classification workflow.
First, a sample patient dataset is created using Python and Pandas. The dataset contains health information and the corresponding diabetes labels.
Next, the four health-related columns—Glucose, BloodPressure, BMI, and Age—are selected as input features and stored in X.
The Diabetes column is selected as the target variable and stored in y.
A Logistic Regression model is then created using Scikit-learn. The model is trained using the sample patient data.
During training, the model analyzes the relationship between the input health features and the known diabetes labels.
After training, information about a new patient is provided to the model. The model then predicts whether the new patient belongs to the diabetic or non-diabetic class.
7. Python Implementation
The following Python program implements the Diabetes Prediction system.
# Import required libraries
import pandas as pd
from sklearn.linear_model import LogisticRegression
# --------------------------------------------
# Step 1: Create a sample dataset
# --------------------------------------------
# Sample patient data
data = {
"Glucose": [85, 89, 120, 145, 160, 180, 95, 130],
"BloodPressure": [66, 70, 80, 85, 90, 92, 68, 78],
"BMI": [24.5, 26.2, 28.5, 31.8, 34.2, 36.5, 25.0, 29.4],
"Age": [22, 30, 35, 45, 50, 60, 28, 40],
"Diabetes": [0, 0, 0, 1, 1, 1, 0, 1]
}
# Convert dictionary into DataFrame
df = pd.DataFrame(data)
# Display dataset
print("Dataset:")
print(df)
# --------------------------------------------
# Step 2: Select input features (X)
# --------------------------------------------
X = df[["Glucose", "BloodPressure", "BMI", "Age"]]
# --------------------------------------------
# Step 3: Select target variable (y)
# --------------------------------------------
y = df["Diabetes"]
# --------------------------------------------
# Step 4: Create the Logistic Regression model
# --------------------------------------------
model = LogisticRegression()
# --------------------------------------------
# Step 5: Train the model
# --------------------------------------------
model.fit(X, y)
# --------------------------------------------
# Step 6: Predict diabetes
# --------------------------------------------
# Patient details:
# Glucose = 150
# Blood Pressure = 88
# BMI = 32.0
# Age = 48
new_patient = [[150, 88, 32.0, 48]]
prediction = model.predict(new_patient)
# --------------------------------------------
# Step 7: Display prediction
# --------------------------------------------
if prediction[0] == 1:
print("\nPrediction: Diabetic")
else:
print("\nPrediction: Not Diabetic")
8. Explanation of the Python Program
The program begins by importing Pandas and Logistic Regression from Scikit-learn.
Pandas is used to create the sample patient dataset, while Logistic Regression is used to classify patients into two categories.
Step 1: Create the Dataset
A Python dictionary is created containing health information for eight sample patients.
For example:
Glucose = 85
BloodPressure = 66
BMI = 24.5
Age = 22
Diabetes = 0
The dictionary is converted into a Pandas DataFrame.
Step 2: Select Input Features
The four health-related features are selected:
X = df[["Glucose", "BloodPressure", "BMI", "Age"]]
These features are used by the Machine Learning model to make the prediction.
Step 3: Select Target Variable
The diabetes column is selected as the target:
y = df["Diabetes"]
The values are:
0 = Not Diabetic
1 = Diabetic
Step 4: Create the Model
A Logistic Regression model is created:
model = LogisticRegression()
Logistic Regression is suitable for this example because the target contains two possible classes.
Step 5: Train the Model
The model is trained using:
model.fit(X, y)
During training, the model learns patterns from the sample patient records.
Step 6: Predict a New Patient
The new patient's information is:
Glucose = 150
Blood Pressure = 88
BMI = 32.0
Age = 48
The information is passed to the trained model:
new_patient = [[150, 88, 32.0, 48]]
prediction = model.predict(new_patient)
The model returns either 0 or 1.
9. Prediction
Input
Glucose = 150
Blood Pressure = 88
BMI = 32.0
Age = 48
Output
Prediction: Diabetic
Based on the patterns learned from the sample dataset, the model classifies the new patient as Diabetic.
It is important to understand that this is only a Machine Learning classification result from a small educational dataset. It is not a medical diagnosis.
10. How Logistic Regression Works
Logistic Regression is a classification algorithm commonly used when the target variable has two possible outcomes.
In this project, the two classes are:
0 → Not Diabetic
1 → Diabetic
The algorithm analyzes the input features and estimates the probability that a patient belongs to a particular class.
The model learns weights for each input feature during training. When new patient information is provided, these learned weights are used to calculate the predicted class.
For example, the model considers the combination of:
Glucose
Blood Pressure
BMI
Age
It then determines which class is more likely according to the patterns in the training dataset.
11. Advantages
The Diabetes Prediction project has several advantages:
Simple and beginner-friendly.
Demonstrates binary classification.
Uses multiple input features.
Easy to implement using Python.
Demonstrates a real-world Machine Learning application.
Logistic Regression is computationally efficient.
Can be extended with more patient features.
Can be evaluated using standard classification metrics.
12. Limitations
The biggest limitation of this project is the extremely small sample dataset. Only eight patient records are used for training, which is not sufficient for a reliable real-world medical prediction system.
Diabetes risk also depends on many factors that are not included in this example. These may include:
Family medical history
Diet
Physical activity
Medication
Other medical conditions
Genetic factors
Additional laboratory measurements
The model also has not been evaluated using a separate test dataset in this simple example.
Most importantly, Machine Learning predictions from a small educational dataset should not be used as a substitute for professional medical diagnosis or advice.
13. Future Improvements
The project can be improved by using a large, high-quality, medically validated dataset.
The dataset should be divided into training and testing sets so that the model can be evaluated on previously unseen data.
Additional evaluation metrics can be used, including:
Accuracy
Precision
Recall
F1-Score
Confusion Matrix
ROC-AUC
Feature scaling can also be considered because the input variables have different numerical ranges.
Other Machine Learning algorithms can be compared with Logistic Regression, such as:
Decision Tree
Random Forest
Support Vector Machine
K-Nearest Neighbors
Gradient Boosting
The system could also be extended to provide probability estimates rather than only a binary prediction.
14. Real-World Applications
Machine Learning-based health prediction systems can have applications in areas such as:
Risk Assessment
A properly validated model could help identify patients who may require further assessment by healthcare professionals.
Health Monitoring
AI systems can analyze health information over time and help identify changes that may require attention.
Medical Research
Machine Learning can help researchers analyze large datasets and identify patterns between health factors and medical outcomes.
Clinical Decision Support
With appropriate validation, regulation, privacy protection, and professional oversight, predictive models can potentially support healthcare professionals in decision-making.
15. Conclusion
The Diabetes Prediction Using Machine Learning project demonstrates how a supervised Machine Learning classification algorithm can be used to predict a binary outcome based on patient health information.
The project uses Logistic Regression with four input features: glucose level, blood pressure, BMI, and age. The model is trained using a small sample dataset containing labeled patient records.
For the new patient with:
Glucose = 150
Blood Pressure = 88
BMI = 32.0
Age = 48
the model produces the following result:
Prediction: Diabetic
This project provides a useful introduction to supervised learning, binary classification, feature selection, model training, and prediction. However, because the example uses a very small educational dataset, the prediction should not be interpreted as a medical diagnosis. A real-world healthcare system would require much larger datasets, rigorous validation, privacy and security controls, and professional medical oversight.
