0% found this document useful (0 votes)
2 views4 pages

Program 1

The document outlines a data preprocessing program for the Pima Indians Diabetes dataset, which includes handling missing values, encoding categorical variables, and normalizing data. It provides summary statistics and visualizations to analyze the dataset. The code demonstrates the steps taken to clean and prepare the data for further analysis.

Uploaded by

thakkar2005
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Program 1

The document outlines a data preprocessing program for the Pima Indians Diabetes dataset, which includes handling missing values, encoding categorical variables, and normalizing data. It provides summary statistics and visualizations to analyze the dataset. The code demonstrates the steps taken to clean and prepare the data for further analysis.

Uploaded by

thakkar2005
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Program 1:

Data Preprocessing — Pima Indians Diabetes Perform preprocessing on


healthcare dataset: handle missing values, encode categorical variables,
normalize, and analyze with summary statistics and visualizations.

---- CODE ----

import pandas as pd

import numpy as np

import [Link] as plt

import seaborn as sns

from [Link] import MinMaxScaler

df = pd.read_csv('[Link]')

cols_with_zeros = ['Glucose', 'BloodPressure', 'SkinThickness', 'Insulin',


'BMI']

for col in cols_with_zeros:

df[col] = df[col].replace(0, [Link])

df[col] = df[col].fillna(df[col].median())

print("Summary Statistics:")

print([Link]())

print(f"\nMissing values:\n{[Link]().sum()}")

scaler = MinMaxScaler()

feature_cols = ['Pregnancies', 'Glucose', 'BloodPressure', 'SkinThickness',

'Insulin', 'BMI', 'DiabetesPedigreeFunction', 'Age']

df[feature_cols] = scaler.fit_transform(df[feature_cols])

print("\nAfter normalization:\n", [Link]())


[Link](figsize=(15, 10))

[Link](221); df['Outcome'].value_counts().plot(kind='bar');
[Link]('Class Distribution')

[Link](222); [Link](df['Glucose'], bins=30); [Link]('Glucose


Distribution')

[Link](223); [Link](x='Outcome', y='Age', data=df);


[Link]('Age vs Outcome')

[Link](224); corr = [Link](); [Link](corr, annot=True,


cmap='coolwarm'); [Link]('Correlation Matrix')

plt.tight_layout(); [Link]()

---- OUTPUT ----

Summary Statistics:

Pregnancies Glucose BloodPressure SkinThickness Insulin \

count 768.000000 768.000000 768.000000 768.000000


768.000000

mean 3.845052 121.656250 72.386719 29.108073 140.671875

std 3.369578 30.438286 12.096642 8.791221 86.383060

min 0.000000 44.000000 24.000000 7.000000 14.000000

25% 1.000000 99.750000 64.000000 25.000000 121.500000

50% 3.000000 117.000000 72.000000 29.000000 125.000000

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.455208 0.471876 33.240885 0.348958

std 6.875177 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.300000 0.372500 29.000000 0.000000

75% 36.600000 0.626250 41.000000 1.000000

max 67.100000 2.420000 81.000000 1.000000

Missing values:

Pregnancies 0

Glucose 0

BloodPressure 0

SkinThickness 0

Insulin 0

BMI 0

DiabetesPedigreeFunction 0

Age 0

Outcome 0

dtype: int64

After normalization:

Pregnancies Glucose BloodPressure SkinThickness Insulin \

count 768.000000 768.000000 768.000000 768.000000


768.000000

mean 0.226180 0.501008 0.493742 0.240305 0.152250

std 0.198210 0.196376 0.123435 0.095557 0.103826

min 0.000000 0.000000 0.000000 0.000000 0.000000

25% 0.058824 0.359677 0.408163 0.195652 0.129207

50% 0.176471 0.470968 0.489796 0.239130 0.133413

75% 0.352941 0.620968 0.571429 0.271739 0.136118

max 1.000000 1.000000 1.000000 1.000000 1.000000


BMI DiabetesPedigreeFunction Age Outcome

count 768.000000 768.000000 768.000000 768.000000

mean 0.291518 0.168179 0.204015 0.348958

std 0.140597 0.141473 0.196004 0.476951

min 0.000000 0.000000 0.000000 0.000000

25% 0.190184 0.070773 0.050000 0.000000

50% 0.288344 0.125747 0.133333 0.000000

75% 0.376278 0.234095 0.333333 1.000000

max 1.000000 1.000000 1.000000 1.000000

You might also like