<jupyter_start><jupyter_text>Loading Data and Important Libraries<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
data = pd.read_csv("diabetes.csv")
data.head()
y = data.iloc[::,-1]
x = data.iloc[::, 0:-1]
x.head()
def get_na(data):
    flag = False
    na_cols = dict(data.isna().sum())
    for x in na_cols.keys():
        if(na_cols[x] > 0):
            flag = True
            print(x,na_cols[x])
    if(flag == False):
        print("No Columns having NA values :)")
get_na(data)
x.columns<jupyter_output><empty_output><jupyter_text>EDA<jupyter_code>sns.distplot(x.Age).set_title('Age')
sns.distplot(x.BloodPressure).set_title('BloodPressure Level')
sns.distplot(x.SkinThickness).set_title('SkinThickness Level')
sns.distplot(x.Insulin).set_title('Insulin Level')
sns.distplot(x.BMI).set_title('BMI Level')
sns.distplot(x.DiabetesPedigreeFunction).set_title('DiabetesPedigreeFunction Level')
sns.distplot(x.Glucose).set_title('Glucose Level')<jupyter_output><empty_output><jupyter_text>Building Model<jupyter_code>from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.33, random_state=42)<jupyter_output><empty_output><jupyter_text>Logistic Regression<jupyter_code>glm = LogisticRegression(solver='liblinear')
model = glm.fit(x_train,y_train)
predicted = model.predict(x_test)
conf_mat = confusion_matrix(y_test, predicted)
conf_mat<jupyter_output><empty_output><jupyter_text>Random Forest<jupyter_code>from sklearn.ensemble import RandomForestClassifier
rf_obj = RandomForestClassifier(n_estimators=1000, criterion='gini', min_samples_split=2, min_samples_leaf=5, 
min_weight_fraction_leaf=0.0, max_features='auto', max_leaf_nodes=None, min_impurity_decrease=0.0, 
min_impurity_split=None, bootstrap=True, n_jobs=1000, random_state=None, verbose=0)
model_rf = rf_obj.fit(x_train, y_train)
predicted_rf = model.predict(x_test)
# Fitting Random Forest Classification to the Training set 
from sklearn.ensemble import RandomForestClassifier 

classifier = RandomForestClassifier(n_estimators = 10, criterion = 'entropy', random_state = 0) 


classifier.fit(x_train,y_train) 

# Predicting the Test set results 
y_pred = classifier.predict(x_test)
conf_mat_R1 = confusion_matrix(y_test, y_pred) 
conf_mat
conf_mat = confusion_matrix(y_test, predicted_rf)
conf_mat<jupyter_output><empty_output><jupyter_text>Standardization<jupyter_code>from sklearn.preprocessing import StandardScaler
scaler = StandardScaler().fit(x)
scale_data = pd.DataFrame(scaler.transform(x), columns= x.columns)
scale_data.head()
x_scaled_train, x_scaled_test, y_scaled_train, y_scaled_test = train_test_split(scale_data, y, test_size=0.33, random_state=42)<jupyter_output><empty_output><jupyter_text>For scaled Data Logistic Regression and Random Forest Classifier<jupyter_code># For scaled Data Logistic Regression
glm_scaled = LogisticRegression(solver='liblinear')
logistic_model_scaled = glm_scaled.fit(x_scaled_train,y_scaled_train)
logistic_predicted_scaled = logistic_model_scaled.predict(x_scaled_test)
conf_mat = confusion_matrix(y_scaled_test, logistic_predicted_scaled)
conf_mat
rf_obj = RandomForestClassifier(n_estimators=1000, criterion='gini', min_samples_split=2, min_samples_leaf=5, 
min_weight_fraction_leaf=0.0, max_features='auto', max_leaf_nodes=None, min_impurity_decrease=0.0, 
min_impurity_split=None, bootstrap=True, n_jobs=1000, random_state=None, verbose=0)

rf_model_rf_scaled = rf_obj.fit(x_scaled_train,y_scaled_train)
rf_predicted_rf_scaled = model.predict(x_scaled_test)
conf_mat = confusion_matrix(y_scaled_test, logistic_predicted_scaled)
conf_mat<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup