<jupyter_start><jupyter_text>**Importing essential libraries**<jupyter_code>import numpy as np
import pandas as pd
import pickle
import seaborn as sns<jupyter_output><empty_output><jupyter_text>**Loading the dataset**<jupyter_code>df = pd.read_csv('../Datasets/diabetes.csv')
df.head(5)<jupyter_output><empty_output><jupyter_text>**Data Visualization**<jupyter_code>df.plot.hist(subplots=True, layout=(4,4), figsize=(20, 20), bins=20)
sns.pairplot(
    df,
    x_vars=['Pregnancies','Glucose','BloodPressure','SkinThickness','Insulin','BMI','DiabetesPedigreeFunction'],
    y_vars=['Age'],
)
df.boxplot(column=['Pregnancies','Glucose','BloodPressure','SkinThickness','Insulin','BMI','DiabetesPedigreeFunction','Age'], figsize=(30,20))<jupyter_output><empty_output><jupyter_text>**Data Preprocessing**<jupyter_code># Renaming DiabetesPedigreeFunction as DPF
df = df.rename(columns={'DiabetesPedigreeFunction':'DPF'})
# Replacing the 0 values from ['Glucose','BloodPressure','SkinThickness','Insulin','BMI'] by NaN
df_copy = df.copy(deep=True)
df_copy[['Glucose','BloodPressure','SkinThickness','Insulin','BMI']] = df_copy[['Glucose','BloodPressure','SkinThickness','Insulin','BMI']].replace(0,np.NaN)
# Replacing NaN value by mean, median depending upon distribution
df_copy['Glucose'].fillna(df_copy['Glucose'].mean(), inplace=True)
df_copy['BloodPressure'].fillna(df_copy['BloodPressure'].mean(), inplace=True)
df_copy['SkinThickness'].fillna(df_copy['SkinThickness'].median(), inplace=True)
df_copy['Insulin'].fillna(df_copy['Insulin'].median(), inplace=True)
df_copy['BMI'].fillna(df_copy['BMI'].median(), inplace=True)<jupyter_output><empty_output><jupyter_text>**Random Forest Classifier Model**<jupyter_code>from sklearn.model_selection import train_test_split
X = df.drop(columns='Outcome')
y = df['Outcome']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_state=0)
# Training the model on Random Forest Algorithm
from sklearn.ensemble import RandomForestClassifier
classifier = RandomForestClassifier(n_estimators = 50,random_state=0)
classifier.fit(X_train, y_train)

import pickle
filename = 'RFmodel.pkl'
with open(filename, 'wb') as file:
    pickle.dump(classifier, file)
# Predicting the Test set results
y_pred = classifier.predict(X_test)
df2 = pd.DataFrame({'Actual':y_test,'Predicted':y_pred})
df2
df2.plot.hist(alpha=0.5)<jupyter_output><empty_output><jupyter_text>**Evaluation Metrics**<jupyter_code>from sklearn.metrics import confusion_matrix, accuracy_score
print("Confusion Matrix:", confusion_matrix(y_test, y_pred))
print("Accuracy:",accuracy_score(y_test,y_pred))
from sklearn import metrics
print('Root Mean Squared Error (RMSE):', np.sqrt(metrics.mean_squared_error(y_test, y_pred)))
print('Mean Absolute Error (MAE):', metrics.mean_absolute_error(y_test, y_pred))
print('Mean Squared Error (MSE):', metrics.mean_squared_error(y_test, y_pred))<jupyter_output>Root Mean Squared Error (RMSE): 0.44866323818505716
Mean Absolute Error (MAE): 0.2012987012987013
Mean Squared Error (MSE): 0.2012987012987013
{'fraction_non_alphanumeric': 0.1554031994776363, 'fraction_numerical': 0.025791707476330396, 'mean_word_length': 11.158730158730158, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '337180', 'license': 'MIT', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1080, 'n_words': 173, 'path': 'Notebooks/DiabetesNotebook_fixed.ipynb', 'repo_name': 'Manasi2001/HealthCheck', 'size': '3063'}