<jupyter_start><jupyter_text>1. Defining the Question  a) Specifying the Data Analysis QuestionWhat is your research question? What problem is it that you are trying to solve?My  task for this project will be to perform univariate and bivariate analysis in an effort to  prepare your data for modeling in the later stages.  b) Defining the Metric for SuccessWhat will convince you that your project has succeeded?Once the Models crated as a result of the analysis of this data  are  used to formulate solutions that will solve the research question.  c) Understanding the context The background information surrounding the problem or research question.The management of a certain NGO Hospital would like to have a product developed thatwould make predictions on whether a person has diabetics or not.The data were collected and made available by “National Institute of Diabetes andDigestive and Kidney Diseases” as part of the Pima Indians Diabetes Database. Severalconstraints were placed on the selection of these instances from a larger database. Inparticular, all patients here belong to the Pima Indian heritage (a subgroup of NativeAmericans) and are females of ages 21 and above.  d) Recording the Experimental DesignThe steps you will take from the beginning to the end of this project.*   Data Cleaning*   Data Preparation*   Data Analysis  e) Data RelevanceIs your data relevant to the problem or research question?  2. Data Cleaning & Preparation<jupyter_code># load libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# load and preview dataset
# diabetes = pd.read_csv('https://bit.ly/3eoAbDS')

diabetes_df = pd.read_csv('/content/datasets_185987_416528_diabetes2.csv')
diabetes_df.sample(3)
# preview dataset shape

diabetes_df.shape
# look for duplicates

diabetes_df.duplicated().sum()
# look for missing records

diabetes_df.isnull().sum()
# preview datatypes

diabetes_df.dtypes
# check for outliers
sns.boxplot(diabetes_df["Pregnancies"]);

sns.boxplot(diabetes_df["Glucose"]);
sns.boxplot(diabetes_df["BloodPressure"]);
sns.boxplot(diabetes_df["SkinThickness"]);  
sns.boxplot(diabetes_df["Insulin"]); 
sns.boxplot(diabetes_df["BMI"]); 
sns.boxplot(diabetes_df["DiabetesPedigreeFunction"]); 
sns.boxplot(diabetes_df["Age"]); 
sns.boxplot(diabetes_df["Outcome"]);<jupyter_output>/usr/local/lib/python3.7/dist-packages/seaborn/_decorators.py:43: FutureWarning: Pass the following variable as a keyword arg: x. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.
  FutureWarning<jupyter_text>3. Data Analysis  3.1 General Analysis<jupyter_code># distribution of Pregnancies
fig, axes = plt.subplots(nrows = 1, ncols = 2, figsize = (12, 4))

plt.subplot(1, 2, 1)
diabetes_df.Pregnancies.hist(color = '#ff7f0e')
plt.title('Histogram of Pregnancies')

plt.subplot(1, 2, 2)
sns.boxplot(diabetes_df.Pregnancies, color = '#9467bd')
plt.title('Box plot of Pregnancies')

plt.show()
# summary statistics of Pregnancies
diabetes_df.Pregnancies.describe()<jupyter_output><empty_output><jupyter_text>What do you observe about the Pregnancies variable?1. The median for pregnanacies is 32. The minimum recorded pregnancies is 0 and the maximum is 17.3. 75% of pregnancies  was above 6 and 25% was 1<jupyter_code># distribution of Glucose

fig, axes = plt.subplots(nrows = 1, ncols = 2, figsize = (12, 4))

plt.subplot(1, 2, 1)
diabetes_df.Glucose.hist(color = '#ff7f0e')
plt.title('Histogram of Glucose')

plt.subplot(1, 2, 2)
sns.boxplot(diabetes_df.Glucose, color = '#9467bd')
plt.title('Box plot of Glucose')

plt.show()

# summary statistics of Glucose

diabetes_df.Glucose.describe()<jupyter_output><empty_output><jupyter_text>What do you observe about the Glucose variable?1. The median for the Glucose patients  is 1172. The minimum recorded for Glucose patients is 0 and the maximum is 199.3. 75% of the Glucose patients was 140 and 25% was 99<jupyter_code># distribution of BloodPressure

fig, axes = plt.subplots(nrows = 1, ncols = 2, figsize = (12, 4))

plt.subplot(1, 2, 1)
diabetes_df.BloodPressure.hist(color = '#ff7f0e')
plt.title('Histogram of BloodPressure ')

plt.subplot(1, 2, 2)
sns.boxplot(diabetes_df.BloodPressure, color = '#9467bd')
plt.title('Box plot of BloodPressure')

plt.show()

# summary statistics of BloodPressure

diabetes_df.BloodPressure.describe()<jupyter_output><empty_output><jupyter_text>Note your observations.1. The median for the BloodPressure patients  is 722. The minimum recorded for BloodPressure patients is 0 and the maximum is 122.3. 75% of the BloodPressure patients was 80 and 25% was 62<jupyter_code># distribution of SkinThickness

fig, axes = plt.subplots(nrows = 1, ncols = 2, figsize = (12, 4))

plt.subplot(1, 2, 1)
diabetes_df.SkinThickness.hist(color = '#ff7f0e')
plt.title('Histogram of SkinThickness ')

plt.subplot(1, 2, 2)
sns.boxplot(diabetes_df.SkinThickness, color = '#9467bd')
plt.title('Box plot of SkinThikness')

plt.show()
# summary statistics of SkinThickness

diabetes_df.SkinThickness.describe()<jupyter_output><empty_output><jupyter_text>Note your observations.1. The median for the SkinThickness patients  is 232. The minimum recorded for SkinThickness patients is 0 and the maximum is 99.3. 75% of the SkinThickness patients was 32 and 25% was 0<jupyter_code># distribution of Insulin

fig, axes = plt.subplots(nrows = 1, ncols = 2, figsize = (12, 4))

plt.subplot(1, 2, 1)
diabetes_df.Insulin.hist(color = '#ff7f0e')
plt.title('Histogram of Insulin')

plt.subplot(1, 2, 2)
sns.boxplot(diabetes_df.Insulin, color = '#9467bd')
plt.title('Box plot of Insulin')

plt.show()
# summary statistics of Insulin

diabetes_df.Insulin.describe()<jupyter_output><empty_output><jupyter_text>Note your observations.1. The median for the Insulin patients  is 30.52. The minimum recorded for Insulin patients is 0 and the maximum is 846.3. 75% of the Insulin patients was 127 and 25% was 0<jupyter_code># distribution of BMI

fig, axes = plt.subplots(nrows = 1, ncols = 2, figsize = (12, 4))

plt.subplot(1, 2, 1)
diabetes_df.BMI.hist(color = '#ff7f0e')
plt.title('Histogram of BMI')

plt.subplot(1, 2, 2)
sns.boxplot(diabetes_df.BMI, color = '#9467bd')
plt.title('Box plot of BMI')

plt.show()

# summary statistics of BMI

diabetes_df.BMI.describe()<jupyter_output><empty_output><jupyter_text>Note your observations.1. The median for the BMI patients  is 32.2. The minimum recorded for BMI patients is 0 and the maximum is 67.3. 75% of the BMI patients was 36 and 25% was 27<jupyter_code># distribution of DiabetesPedigreeFunction

fig, axes = plt.subplots(nrows = 1, ncols = 2, figsize = (12, 4))

plt.subplot(1, 2, 1)
diabetes_df.DiabetesPedigreeFunction.hist(color = '#ff7f0e')
plt.title('Histogram of DiabetesPedigreeFunction')

plt.subplot(1, 2, 2)
sns.boxplot(diabetes_df.DiabetesPedigreeFunction, color = '#9467bd')
plt.title('Box plot of DiabetesPedigreeFunction')

plt.show()
# summary statistics of DiabetesPedigreeFunction

diabetes_df.DiabetesPedigreeFunction.describe()<jupyter_output><empty_output><jupyter_text>Note your observations.1. The median for the DiabetesPedigreeFunction patients  is 0.32. The minimum recorded for DiabetesPedigreeFunction patients is 0 and the maximum is 2.43. 75% of the DiabetesPedigreeFunction patients was 0.6 and 25% was 0.2<jupyter_code># distribution of Age

fig, axes = plt.subplots(nrows = 1, ncols = 2, figsize = (12, 4))

plt.subplot(1, 2, 1)
diabetes_df.Age.hist(color = '#ff7f0e')
plt.title('Histogram of Age')

plt.subplot(1, 2, 2)
sns.boxplot(diabetes_df.Age, color = '#9467bd')
plt.title('Box plot of Age')

plt.show()
# summary statistics of Age

diabetes_df.Age.describe()<jupyter_output><empty_output><jupyter_text>Note your observations.1. The median for the Age of the patients  is 292. The minimum recorded for Age of the  patients is 21 and the maximum is 813. 75% of the Age of the patients was 41 and 25% was 24<jupyter_code># distribution of outcome - create a pie chart

Outcome = diabetes_df['Outcome'].value_counts()
Outcome


# create our labels
# ---
labels = Outcome.index.tolist()
labels


# Then later create our pie chart
# ---
plt.pie(Outcome, labels=labels, autopct='%i%%');<jupyter_output><empty_output><jupyter_text>Note your observations.*   Out of the total 768 patients 65% had an outcome of 0 (Non-diabetic) while 34% had an outcome of 1 (Diabetic)  3.2 Research-Specific Analysis Since our research question requires us to discover the factors that determine whether a patient has diabetes or not, we will make the 'Outcome' variable our main focus during this analysis.<jupyter_code># box and bar plots of Pregnancies by Outcome
fig, axes = plt.subplots(nrows = 1, ncols = 2, figsize = (12, 4))

plt.subplot(1, 2, 1)
sns.barplot(data = diabetes_df, x = 'Outcome', y = 'Pregnancies')
plt.title('Bar plot of Outcome by Pregnancies')

plt.subplot(1, 2, 2)
sns.boxplot(diabetes_df.Pregnancies, diabetes_df.Outcome, orient = 'h')
plt.title('Box plot of Pregnancies by Outcome')

plt.show()<jupyter_output>/usr/local/lib/python3.7/dist-packages/seaborn/_decorators.py:43: FutureWarning: Pass the following variables as keyword args: x, y. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.
  FutureWarning<jupyter_text>``` This is formatted as code```What do you notice?The number of  diabetic  pregnant patients is higher compared to to the non-diabetic patients<jupyter_code># box and bar plots of Glucose by Outcome

fig, axes = plt.subplots(nrows = 1, ncols = 2, figsize = (12, 4))

plt.subplot(1, 2, 1)
sns.barplot(data = diabetes_df, x = 'Outcome', y = 'Glucose')
plt.title('Bar plot of Outcome by Glucose')

plt.subplot(1, 2, 2)
sns.boxplot(diabetes_df.Glucose, diabetes_df.Outcome, orient = 'h')
plt.title('Box plot of Glucose by Outcome')

plt.show()<jupyter_output>/usr/local/lib/python3.7/dist-packages/seaborn/_decorators.py:43: FutureWarning: Pass the following variables as keyword args: x, y. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.
  FutureWarning<jupyter_text>Note your observartions.As expected, diabetic patients have a higher level of Glucose compared to normal patients.<jupyter_code># box and bar plots of BloodPressure by Outcome

fig, axes = plt.subplots(nrows = 1, ncols = 2, figsize = (12, 4))

plt.subplot(1, 2, 1)
sns.barplot(data = diabetes_df, x = 'Outcome', y = 'BloodPressure')
plt.title('Bar plot of Outcome by BloodPressure')

plt.subplot(1, 2, 2)
sns.boxplot(diabetes_df.BloodPressure, diabetes_df.Outcome, orient = 'h')
plt.title('Box plot of BloodPressure by Outcome')

plt.show()<jupyter_output>/usr/local/lib/python3.7/dist-packages/seaborn/_decorators.py:43: FutureWarning: Pass the following variables as keyword args: x, y. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.
  FutureWarning<jupyter_text>Note your observations.The trand for BloodPressure almost looks the same for both diabetic and non-diabetic patients<jupyter_code># box and bar plots of SkinThickness by Outcome

fig, axes = plt.subplots(nrows = 1, ncols = 2, figsize = (12, 4))

plt.subplot(1, 2, 1)
sns.barplot(data = diabetes_df, x = 'Outcome', y = 'SkinThickness')
plt.title('Bar plot of Outcome by SkinThickness')

plt.subplot(1, 2, 2)
sns.boxplot(diabetes_df.SkinThickness, diabetes_df.Outcome, orient = 'h')
plt.title('Box plot of SkinThickness by Outcome')

plt.show()<jupyter_output>/usr/local/lib/python3.7/dist-packages/seaborn/_decorators.py:43: FutureWarning: Pass the following variables as keyword args: x, y. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.
  FutureWarning<jupyter_text>Note your observations.Skin Thickness for Diabetics is more than that of Non-Diabetics.<jupyter_code># box and bar plots of Insulin by Outcome

fig, axes = plt.subplots(nrows = 1, ncols = 2, figsize = (12, 4))

plt.subplot(1, 2, 1)
sns.barplot(data = diabetes_df, x = 'Outcome', y = 'Insulin')
plt.title('Bar plot of Outcome by Insulin')

plt.subplot(1, 2, 2)
sns.boxplot(diabetes_df.Insulin, diabetes_df.Outcome, orient = 'h')
plt.title('Box plot of Insulin by Outcome')

plt.show()<jupyter_output>/usr/local/lib/python3.7/dist-packages/seaborn/_decorators.py:43: FutureWarning: Pass the following variables as keyword args: x, y. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.
  FutureWarning<jupyter_text>Note your observations.The Diabetic patients have a higher insulin level compared to the non-diabetic patients<jupyter_code># box and bar plots of BMI by Outcome

fig, axes = plt.subplots(nrows = 1, ncols = 2, figsize = (12, 4))

plt.subplot(1, 2, 1)
sns.barplot(data = diabetes_df, x = 'Outcome', y = 'BMI')
plt.title('Bar plot of Outcome by BMI')

plt.subplot(1, 2, 2)
sns.boxplot(diabetes_df.BMI, diabetes_df.Outcome, orient = 'h')
plt.title('Box plot of BMI by Outcome')

plt.show()<jupyter_output>/usr/local/lib/python3.7/dist-packages/seaborn/_decorators.py:43: FutureWarning: Pass the following variables as keyword args: x, y. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.
  FutureWarning<jupyter_text>Note your observations.BMI for diabetics is higher than the BMI for non-diabetics<jupyter_code># box and bar plots of DiabetesPedigreeFunction by Outcome

fig, axes = plt.subplots(nrows = 1, ncols = 2, figsize = (12, 4))

plt.subplot(1, 2, 1)
sns.barplot(data = diabetes_df, x = 'Outcome', y = 'DiabetesPedigreeFunction')
plt.title('Bar plot of Outcome by DiabetesPedigreeFunction')

plt.subplot(1, 2, 2)
sns.boxplot(diabetes_df.DiabetesPedigreeFunction, diabetes_df.Outcome, orient = 'h')
plt.title('Box plot of DiabetesPedigreeFunction by Outcome')

plt.show()<jupyter_output>/usr/local/lib/python3.7/dist-packages/seaborn/_decorators.py:43: FutureWarning: Pass the following variables as keyword args: x, y. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.
  FutureWarning<jupyter_text>Note your observations.Diabetics seem to have a higher pedigree function that the non-diabetics.<jupyter_code># box and bar plots of Age by Outcome

fig, axes = plt.subplots(nrows = 1, ncols = 2, figsize = (12, 4))

plt.subplot(1, 2, 1)
sns.barplot(data = diabetes_df, x = 'Outcome', y = 'Age')
plt.title('Bar plot of Outcome by Age')

plt.subplot(1, 2, 2)
sns.boxplot(diabetes_df.Age, diabetes_df.Outcome, orient = 'h')
plt.title('Box plot of Age by Outcome')

plt.show()<jupyter_output>/usr/local/lib/python3.7/dist-packages/seaborn/_decorators.py:43: FutureWarning: Pass the following variables as keyword args: x, y. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.
  FutureWarning
{'fraction_non_alphanumeric': 0.1000386498325174, 'fraction_numerical': 0.029051790775573304, 'mean_word_length': 5.423251965246173, 'pattern_counts': {'":': 0, '<': 64, '<?xml version=': 0, '>': 64, 'https://': 1, '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': '18', 'dir': 'jupyter-structured-clean-dedup', 'id': '616964', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 5671, 'n_tokens_neox': 5032, 'n_words': 1734, 'path': 'Delight_Assignment_Diabetes_Statistical_Analysis_Project_Guiding_Notebook.ipynb', 'repo_name': 'Deli8t/data', 'size': '15524'}