5/8/25, 11:34 AM Rough work.
ipynb - Colab
1) Dataset Overview: Load the dataset and display basic information, including the number of rows, columns, and data types.
import pandas as pd
# Load the dataset (replace 'your_dataset.csv' with your dataset file path)
df = pd.read_csv('/content/drive/MyDrive/[Link]')
# Display basic information about the dataset
print("Basic Information:")
print([Link]())
# Display the number of rows and columns
print("\nNumber of rows and columns:", [Link])
# Display the first few rows of the dataset
print("\nFirst 5 rows of the dataset:")
print([Link]())
Basic Information:
<class '[Link]'>
RangeIndex: 768 entries, 0 to 767
Data columns (total 9 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Pregnancies 768 non-null int64
1 Glucose 768 non-null int64
2 BloodPressure 768 non-null int64
3 SkinThickness 768 non-null int64
4 Insulin 768 non-null int64
5 BMI 768 non-null float64
6 DiabetesPedigreeFunction 768 non-null float64
7 Age 768 non-null int64
8 Outcome 768 non-null int64
dtypes: float64(2), int64(7)
memory usage: 54.1 KB
None
Number of rows and columns: (768, 9)
First 5 rows of the dataset:
Pregnancies Glucose BloodPressure SkinThickness Insulin BMI \
0 6 148 72 35 0 33.6
1 1 85 66 29 0 26.6
2 8 183 64 0 0 23.3
3 1 89 66 23 94 28.1
4 0 137 40 35 168 43.1
DiabetesPedigreeFunction Age Outcome
0 0.627 50 1
1 0.351 31 0
2 0.672 32 1
3 0.167 21 0
4 2.288 33 1
2) Checking and handling Missing Values: Verify if there are any missing values in the dataset. If found, decide on an appropriate handling
method. Identify columns where zero values are unrealistic (e.g., BloodPressure, SkinThickness, Insulin, BMI) and replace them with
appropriate values (mean or median).
# Step 1: Check for missing values
print("Checking for missing values:")
print([Link]().sum()) # Show the number of missing values per column
# Step 2: Replace missing values if any (you can choose mean or median)
# Replace missing values for numerical columns with the median
[Link]([Link](), inplace=True)
# Step 3: Identify unrealistic zero values
columns_to_check = ['BloodPressure', 'SkinThickness', 'Insulin', 'BMI']
for column in columns_to_check:
# Replace zero values with the median of the respective column
df[column] = df[column].replace(0, df[column].median())
# Step 4: Verify the changes
print("\nUpdated dataset with missing and unrealistic zero values handled:")
print([Link]().sum()) # Check if any missing values remain
print("\nFirst 5 rows of the updated dataset:")
print([Link]())
[Link] 1/4
5/8/25, 11:34 AM Rough [Link] - Colab
Checking for missing values:
Pregnancies 0
Glucose 0
BloodPressure 0
SkinThickness 0
Insulin 0
BMI 0
DiabetesPedigreeFunction 0
Age 0
Outcome 0
dtype: int64
Updated dataset with missing and unrealistic zero values handled:
Pregnancies 0
Glucose 0
BloodPressure 0
SkinThickness 0
Insulin 0
BMI 0
DiabetesPedigreeFunction 0
Age 0
Outcome 0
dtype: int64
First 5 rows of the updated dataset:
Pregnancies Glucose BloodPressure SkinThickness Insulin BMI \
0 6 148 72 35 30.5 33.6
1 1 85 66 29 30.5 26.6
2 8 183 64 23 30.5 23.3
3 1 89 66 23 94.0 28.1
4 0 137 40 35 168.0 43.1
DiabetesPedigreeFunction Age Outcome
0 0.627 50 1
1 0.351 31 0
2 0.672 32 1
3 0.167 21 0
4 2.288 33 1
3) Statistical Summary: Generate summary statistics (mean, median, std, min, max) for numerical columns.
# Generate summary statistics for numerical columns
summary_stats = [Link]()
# Display the summary statistics
print("Summary Statistics for Numerical Columns:")
print(summary_stats)
Summary Statistics for Numerical Columns:
Pregnancies Glucose BloodPressure SkinThickness Insulin \
count 768.000000 768.000000 768.000000 768.000000 768.000000
mean 3.845052 120.894531 72.386719 27.334635 94.652344
std 3.369578 31.972618 12.096642 9.229014 105.547598
min 0.000000 0.000000 24.000000 7.000000 14.000000
25% 1.000000 99.000000 64.000000 23.000000 30.500000
50% 3.000000 117.000000 72.000000 23.000000 31.250000
75% 6.000000 140.250000 80.000000 32.000000 127.250000
max 17.000000 199.000000 122.000000 99.000000 846.000000
BMI DiabetesPedigreeFunction Age Outcome
count 768.000000 768.000000 768.000000 768.000000
mean 32.450911 0.471876 33.240885 0.348958
std 6.875366 0.331329 11.760232 0.476951
min 18.200000 0.078000 21.000000 0.000000
25% 27.500000 0.243750 24.000000 0.000000
50% 32.000000 0.372500 29.000000 0.000000
75% 36.600000 0.626250 41.000000 1.000000
max 67.100000 2.420000 81.000000 1.000000
4) Diabetes Distribution: Calculate the percentage of diabetic (Outcome = 1) and non-diabetic (Outcome = 0) patients.
# Calculate the total number of patients
total_patients = df['Outcome'].count()
# Calculate the number of diabetic (Outcome = 1) and non-diabetic (Outcome = 0) patients
diabetic_patients = df[df['Outcome'] == 1].shape[0]
non_diabetic_patients = df[df['Outcome'] == 0].shape[0]
# Calculate the percentage of diabetic and non-diabetic patients
diabetic_percentage = (diabetic_patients / total_patients) * 100
[Link] 2/4
5/8/25, 11:34 AM Rough [Link] - Colab
non_diabetic_percentage = (non_diabetic_patients / total_patients) * 100
# Print the results
print(f"Percentage of diabetic patients: {diabetic_percentage:.2f}%")
print(f"Percentage of non-diabetic patients: {non_diabetic_percentage:.2f}%")
Percentage of diabetic patients: 34.90%
Percentage of non-diabetic patients: 65.10%
5) BMI vs. Diabetes: Find the average BMI for diabetic and non-diabetic individuals.
# Calculate the average BMI for diabetic and non-diabetic individuals
average_bmi = [Link]('Outcome')['BMI'].mean()
# Print the result
print("Average BMI for diabetic and non-diabetic individuals:")
print(average_bmi)
Average BMI for diabetic and non-diabetic individuals:
Outcome
0 30.880200
1 35.381343
Name: BMI, dtype: float64
6) Glucose Levels & Diabetes: Find the average glucose level for diabetic and non-diabetic patients.
# Calculate the average glucose level for diabetic and non-diabetic individuals
average_glucose = [Link]('Outcome')['Glucose'].mean()
# Print the result
print("Average glucose level for diabetic and non-diabetic individuals:")
print(average_glucose)
Average glucose level for diabetic and non-diabetic individuals:
Outcome
0 109.980000
1 141.257463
Name: Glucose, dtype: float64
7) Correlation Analysis: Find the correlation between glucose level, BMI, and diabetes outcome
# Select the relevant columns: Glucose, BMI, and Outcome
correlation_data = df[['Glucose', 'BMI', 'Outcome']]
# Calculate the correlation matrix
correlation_matrix = correlation_data.corr()
# Print the correlation matrix
print("Correlation matrix between Glucose, BMI, and Outcome:")
print(correlation_matrix)
Correlation matrix between Glucose, BMI, and Outcome:
Glucose BMI Outcome
Glucose 1.000000 0.218806 0.466581
BMI 0.218806 1.000000 0.312249
Outcome 0.466581 0.312249 1.000000
Start coding or generate with AI.
[Link] 3/4
5/8/25, 11:34 AM Rough [Link] - Colab
[Link] 4/4