<jupyter_start><jupyter_text>**Diabetes Health Indicator**Diabetes mellitus also known as diabetes is the combination of metabolic disorders. Diabetes is very serious problem if it is not treated on time then it will cause so many body complications. As its long-term complication can cause cardiovascular disease, stroke, kidney disease or failure and damage to the nerves. Diabetes is a lifelong condition that causes a person's blood sugar level to become too high.There are three main types of diabetes mellitus:•	Type 1•	Type 2•	Gestational diabetes  **Importing the Libraries**<jupyter_code># Importing pandas as pd
import pandas as pd
# Importing matplotlib as mt
import matplotlib as mt
# Importing LabelEncoder from sklearn
from sklearn.preprocessing import LabelEncoder
# Importing StandardScaler from sklearn
from sklearn.preprocessing import StandardScaler
# Importing OneHotEncoder from sklearn
from sklearn.preprocessing import OneHotEncoder
# Importing make_imbalance from imblearn
from imblearn.datasets import make_imbalance
# Importing matplotlib.pyplot as plt
import matplotlib.pyplot as plt
# Importing seaborn as sns
import seaborn as sns
# Importing counter from collection
from collections import Counter
# Importing matplotlib
import matplotlib<jupyter_output><empty_output><jupyter_text>**Loading the dataset**<jupyter_code># loading the dataset in csv from to data variable
data = pd.read_csv('diabetes.csv')
# to print the loaded dataset
data<jupyter_output><empty_output><jupyter_text>**Pre-Processing and Cleaning the data**<jupyter_code># to print first 5 rows of dataset we use head command
data.head()
# the command to check the types of data is
data.dtypes
# this is the code for plotting the heat map
color = sns.color_palette()
sns.set_style('darkgrid')
corrmat = data.corr()
plt.subplots(figsize=(12,9))
sns.heatmap(corrmat, vmax=0.9, square=True)
# to count the number of each class in attribute we use value_counts
data.Diabetes_binary.value_counts()
# here we used isnull for checking any null value is present or not
data.isnull().sum(axis = 0)
# Plotting histograms for all the attributes of dataset
data.hist(figsize = (20,20))
plt.show()
# copying the data of Diabetes_binary to y variable
y = data['Diabetes_binary'].copy()
# dropping the heart disease attribute from dataset and storing it in x variable
x = data.drop(['Diabetes_binary'], axis = 1)
# printing the number of class present in y with their time of occurance
print(f'Distribution Before Imblancing : {Counter(y)}')
#Calculating hte imbalance percentage in the dataset
imbalance = len(data[data['Diabetes_binary'] == 0])/len(data)*100
imbalance
# plotting the histogram for low imbalancing
hist = data['Diabetes_binary'].hist()
# tile of histogram
plt.title('Balance Data Set')
# label for x-axis
plt.xlabel('Number of Classes')
# label for y-axis
plt.ylabel('Total Number of Sample')
# to display histogram
plt.show
# saving the figure in jpg format of hist
fig= hist.get_figure()
fig.savefig('Hist_Main%.jpg')<jupyter_output><empty_output><jupyter_text>**Low imblance****The dataset over here is 65% Imbalanced**<jupyter_code># making the data imbalance by 65% and storing it in XA and YA
XA, YA = make_imbalance(x, y, 
                          sampling_strategy={1: 35346, 0: 19032},
                        random_state = 42)
# printing the count after low imbalancing
print(f'Distribution After Imblancing 65%: {Counter(YA)}')
# plotting the histogram for low imbalancing
hist1 = YA.hist()
# tile of histogram
plt.title('65% Imblance Dataset')
# label for x-axis
plt.xlabel('Number of Classes')
# label for y-axis
plt.ylabel('Total Number of Sample')
# to display histogram
plt.show
# saving the figure in jpg format of hist1
fig= hist1.get_figure()
fig.savefig('Hist_65%.jpg')<jupyter_output><empty_output><jupyter_text>**Medium Imblance****The dataset over here is 75% Imbalanced**<jupyter_code># making the data imbalance by 75% and storing it in XB and YB
XB, YB = make_imbalance(x, y, 
                          sampling_strategy={1: 35346, 0: 11782},
                        random_state = 42)
# printing the count after medium imbalancing
print(f'Distribution After Imblancing 75% : {Counter(YB)}')
# plotting the histogram for low imbalancing
hist2 = YB.hist()
# tile of histogram
plt.title('75% Imblance Dataset')
# label for x-axis
plt.xlabel('Number of Classes')
# label for y-axis
plt.ylabel('Total Number of Sample')
# to display histogram
plt.show
# saving the figure in jpg format of hist2
fig= hist2.get_figure()
fig.savefig('Hist_75%.jpg')<jupyter_output><empty_output><jupyter_text>**High Imbalance****The dataset over here is 90% Imbalanced**<jupyter_code># making the data imbalance by 90% and storing it in XC and YC
XC, YC = make_imbalance(x, y, 
                          sampling_strategy={1: 35346, 0: 3927},
                        random_state = 42)
# printing the count after High imbalancing
print(f'Distribution After Imblancing 90% : {Counter(YC)}')
# plotting the histogram for low imbalancing
hist3 = YC.hist()
# tile of histogram
plt.title('90% Imblance Dataset')
# label for x-axis
plt.xlabel('Number of Classes')
# label for y-axis
plt.ylabel('Total Number of Sample')
# to display histogram
plt.show
# saving the figure in jpg format of hist3
fig= hist3.get_figure()
fig.savefig('Hist_90%.jpg')<jupyter_output><empty_output><jupyter_text>**Sampling**<jupyter_code><jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09037472446730345, 'fraction_numerical': 0.018001469507714914, 'mean_word_length': 5.043285238623751, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '89574', 'license': 'MIT', 'n_tokens_mistral': 1808, 'n_tokens_neox': 1643, 'n_words': 608, 'path': 'Diabetes.ipynb', 'repo_name': 'pk21822/Project_Imbalanced_Dataset', 'size': '5444'}