{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\n# import os\n# for dirname, _, filenames in os.walk('/kaggle/input'):\n#     for filename in filenames:\n#         print(os.path.join(dirname, filename))\n\n# Any results you write to the current directory are saved as output.","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-05-24T10:39:37.238654Z","iopub.execute_input":"2021-05-24T10:39:37.239120Z","iopub.status.idle":"2021-05-24T10:39:37.244386Z","shell.execute_reply.started":"2021-05-24T10:39:37.238993Z","shell.execute_reply":"2021-05-24T10:39:37.243103Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport os\nimport pandas as pd\nimport cv2\nfrom PIL import Image\nimport scipy\n\nimport tensorflow as tf\nfrom tensorflow.keras.applications import *\nfrom tensorflow.keras.optimizers import *\nfrom tensorflow.keras.losses import *\nfrom tensorflow.keras.layers import *\nfrom tensorflow.keras.models import *\nfrom tensorflow.keras.callbacks import *\nfrom tensorflow.keras.preprocessing.image import *\nfrom tensorflow.keras.utils import *\nfrom sklearn.neural_network import MLPClassifier\n# import pydot\nfrom sklearn.neighbors import KNeighborsClassifier\nfrom sklearn.metrics import *\nfrom sklearn.model_selection import *\nimport tensorflow.keras.backend as K\n\nfrom tqdm import tqdm, tqdm_notebook\nfrom colorama import Fore\nimport json\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom glob import glob\nfrom skimage.io import *\n%config Completer.use_jedi = False\nimport time\nfrom sklearn.decomposition import PCA\nfrom sklearn.svm import SVC\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.metrics import accuracy_score\nimport lightgbm as lgb\nfrom xgboost import XGBClassifier\nfrom sklearn.ensemble import AdaBoostClassifier,RandomForestClassifier\n\nfrom sklearn.metrics import confusion_matrix\n\nimport numpy as np\nimport pandas as pd\nfrom pathlib import Path\nimport os.path\nimport matplotlib.pyplot as plt\nfrom IPython.display import Image, display, Markdown\nimport matplotlib.cm as cm\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import confusion_matrix\nimport tensorflow as tf\nfrom time import perf_counter\nimport seaborn as sns\n\ndef printmd(string):\n    # Print with Markdowns    \n    display(Markdown(string))\n\nprint(\"All modules have been imported\")","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:39:37.265563Z","iopub.execute_input":"2021-05-24T10:39:37.265869Z","iopub.status.idle":"2021-05-24T10:39:37.300260Z","shell.execute_reply.started":"2021-05-24T10:39:37.265840Z","shell.execute_reply":"2021-05-24T10:39:37.298832Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_dir = Path('../input/diabetic-retinopathy-224x224-gaussian-filtered/gaussian_filtered_images/gaussian_filtered_images')\n\n# Get filepaths and labels\nfilepaths = list(image_dir.glob(r'**/*.png'))\nlabels = list(map(lambda x: os.path.split(os.path.split(x)[0])[1], filepaths))","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:39:37.302318Z","iopub.execute_input":"2021-05-24T10:39:37.303028Z","iopub.status.idle":"2021-05-24T10:39:37.617245Z","shell.execute_reply.started":"2021-05-24T10:39:37.302946Z","shell.execute_reply":"2021-05-24T10:39:37.616201Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filepaths = pd.Series(filepaths, name='Filepath').astype(str)\nlabels = pd.Series(labels, name='Label')\n\n# Concatenate filepaths and labels\nimage_df = pd.concat([filepaths, labels], axis=1)\n\n# Shuffle the DataFrame and reset index\nimage_df = image_df.sample(frac=1).reset_index(drop = True)\n\n# Show the result\nimage_df.head()","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:39:37.619402Z","iopub.execute_input":"2021-05-24T10:39:37.619695Z","iopub.status.idle":"2021-05-24T10:39:37.643362Z","shell.execute_reply.started":"2021-05-24T10:39:37.619667Z","shell.execute_reply":"2021-05-24T10:39:37.642046Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"level = []\nfor i in image_df['Label']:\n    if i=='No_DR':\n        level.append(0)\n    elif i=='Mild':\n        level.append(1)\n    elif i=='Moderate':\n        level.append(1)\n    elif i=='Severe':\n        level.append(1)\n    else:\n        level.append(1)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:39:37.646858Z","iopub.execute_input":"2021-05-24T10:39:37.647352Z","iopub.status.idle":"2021-05-24T10:39:37.655378Z","shell.execute_reply.started":"2021-05-24T10:39:37.647307Z","shell.execute_reply":"2021-05-24T10:39:37.654181Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_df['Level'] = level\nimage_df.head()","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:39:37.657181Z","iopub.execute_input":"2021-05-24T10:39:37.657878Z","iopub.status.idle":"2021-05-24T10:39:37.678202Z","shell.execute_reply.started":"2021-05-24T10:39:37.657832Z","shell.execute_reply":"2021-05-24T10:39:37.677260Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = []\nfor i in image_df['Filepath']:\n    image = cv2.imread(i)\n    X.append(image)\n    \nX = np.asarray(X)\ny = image_df['Level']\nY = np.asarray(y)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:39:37.680189Z","iopub.execute_input":"2021-05-24T10:39:37.680840Z","iopub.status.idle":"2021-05-24T10:39:50.235576Z","shell.execute_reply.started":"2021-05-24T10:39:37.680793Z","shell.execute_reply":"2021-05-24T10:39:50.234420Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Y=to_categorical(Y,5)\nx_train, x_test1, y_train, y_test1 = train_test_split(X, Y, test_size=0.4, random_state=42)\nx_val, x_test, y_val, y_test = train_test_split(x_test1, y_test1, test_size=0.1, random_state=42)\nprint(len(x_train),len(x_val),len(x_test))","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:39:50.237724Z","iopub.execute_input":"2021-05-24T10:39:50.238132Z","iopub.status.idle":"2021-05-24T10:39:50.492510Z","shell.execute_reply.started":"2021-05-24T10:39:50.238093Z","shell.execute_reply":"2021-05-24T10:39:50.491238Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# DNN Model","metadata":{}},{"cell_type":"code","source":"# Defining our DNN Model\ndnn_model=Sequential()\ndnn_model.add(Dense(8, input_dim=2, kernel_initializer = 'uniform', activation = 'relu'))\n# dnn_model.add(BatchNormalization())\n# dnn_model.add(Dropout(0.2))\ndnn_model.add(Dense(16, kernel_initializer = 'uniform', activation = 'relu' ))\n# dnn_model.add(BatchNormalization())\n# dnn_model.add(Dropout(0.2))\ndnn_model.add(Dense(32, kernel_initializer = 'uniform', activation = 'relu' ))\n# dnn_model.add(BatchNormalization())\n# dnn_model.add(Dropout(0.2))\ndnn_model.add(Dense(64, kernel_initializer = 'uniform', activation = 'relu' ))\n# dnn_model.add(BatchNormalization())\n# dnn_model.add(Dropout(0.2))\ndnn_model.add(Dense(128, kernel_initializer = 'uniform', activation = 'relu'))\n# dnn_model.add(BatchNormalization())\n# dnn_model.add(Dropout(0.2))\ndnn_model.add(Dense(256, kernel_initializer = 'uniform', activation = 'relu' ))\n# dnn_model.add(BatchNormalization())\n# dnn_model.add(Dropout(0.2))\ndnn_model.add(Dense(128, kernel_initializer = 'uniform', activation = 'relu' ))\n# dnn_model.add(BatchNormalization())\n# dnn_model.add(Dropout(0.2))\ndnn_model.add(Dense(64, kernel_initializer = 'uniform', activation = 'relu' ))\n# dnn_model.add(BatchNormalization())\n# dnn_model.add(Dropout(0.2))\ndnn_model.add(Dense(32, kernel_initializer = 'uniform', activation = 'relu' ))\n# dnn_model.add(BatchNormalization())\n# dnn_model.add(Dropout(0.2))\ndnn_model.add(Dense(16, kernel_initializer = 'uniform', activation = 'relu' ))\n# dnn_model.add(BatchNormalization())\n# dnn_model.add(Dropout(0.2))\ndnn_model.add(Dense(8, kernel_initializer = 'uniform', activation = 'relu' ))\n# dnn_model.add(BatchNormalization())\n# dnn_model.add(Dropout(0.2))\ndnn_model.add(Dense(2,activation='softmax'))\ndnn_model.summary()","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:39:50.494590Z","iopub.execute_input":"2021-05-24T10:39:50.495131Z","iopub.status.idle":"2021-05-24T10:39:50.616771Z","shell.execute_reply.started":"2021-05-24T10:39:50.495084Z","shell.execute_reply":"2021-05-24T10:39:50.615779Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.pipeline import make_pipeline\nfrom sklearn.pipeline import Pipeline\nnames = [\n        \"K Nearest Neighbour Classifier\",\n        'SVM',\n        \"Random Forest Classifier\",\n        \"AdaBoost Classifier\", \n        \"XGB Classifier\"\n         ]\nclassifiers = [\n    KNeighborsClassifier(n_neighbors = 5, algorithm='ball_tree', leaf_size=30),\n    SVC(),\n    RandomForestClassifier(max_depth=9,criterion = 'entropy'),\n    AdaBoostClassifier(),\n    XGBClassifier()\n        ]\nzipped_clf = zip(names,classifiers)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:39:50.619040Z","iopub.execute_input":"2021-05-24T10:39:50.619531Z","iopub.status.idle":"2021-05-24T10:39:50.630048Z","shell.execute_reply.started":"2021-05-24T10:39:50.619489Z","shell.execute_reply":"2021-05-24T10:39:50.628673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def classifier_summary(pipeline, X_train, y_train, X_val, y_val,X_test,y_test):\n    sentiment_fit = pipeline.fit(X_train, y_train)\n    \n    y_pred_train= sentiment_fit.predict(X_train)\n    y_pred_val = sentiment_fit.predict(X_val)\n    y_pred_test = sentiment_fit.predict(X_test)\n    \n    y_pred_train = [1 if x>0.5 else 0 for x in y_pred_train]\n    y_pred_val = [1 if x>0.5 else 0 for x in y_pred_val]\n    y_pred_test = [1 if x>0.5 else 0 for x in y_pred_test]\n    \n    train_accuracy = np.round(accuracy_score(y_train, y_pred_train),4)*100\n    train_precision = np.round(precision_score(y_train, y_pred_train, average='weighted'),4)\n    train_recall = np.round(recall_score(y_train, y_pred_train, average='weighted'),4)\n    train_F1 = np.round(f1_score(y_train, y_pred_train, average='weighted'),4)\n    train_kappa =  np.round(cohen_kappa_score(y_train, y_pred_train),4)\n    \n    \n    val_accuracy = np.round(accuracy_score(y_val, y_pred_val),4)*100\n    val_precision = np.round(precision_score(y_val, y_pred_val, average='weighted'),4)\n    val_recall = np.round(recall_score(y_val, y_pred_val, average='weighted'),4)\n    val_F1 = np.round(f1_score(y_val, y_pred_val, average='weighted'),4)\n    val_kappa =  np.round(cohen_kappa_score(y_val, y_pred_val),4)\n   \n    \n    test_accuracy = np.round(accuracy_score(y_test, y_pred_test),4)*100\n    test_precision = np.round(precision_score(y_test, y_pred_test, average='weighted'),2)\n    test_recall = np.round(recall_score(y_test, y_pred_test, average='weighted'),2)\n    test_F1 = np.round(f1_score(y_test, y_pred_test, average='weighted'),2)\n    test_kappa =  np.round(cohen_kappa_score(y_test, y_pred_test),2) \n  \n    \n    \n    print()\n    print('------------------------ Train Set Metrics------------------------')\n    print()\n    print(\"Accuracy core : {}%\".format(train_accuracy)) \n    \n    print('------------------------ Validation Set Metrics------------------------')\n    print()\n    print(\"Accuracy score : {}%\".format(val_accuracy))\n                          \n    print('------------------------ Test Set Metrics------------------------')\n    print()\n    print(\"Accuracy score : {}%\".format(test_accuracy))\n    print(\"F1_score : {}\".format(test_F1))\n    print(\"Kappa Score : {} \".format(test_kappa))\n    print(\"Recall score: {}\".format(test_recall))\n    print(\"Precision score : {}\".format(test_precision))\n          \n    print(\"-\"*80)\n    print()","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:39:50.633997Z","iopub.execute_input":"2021-05-24T10:39:50.635151Z","iopub.status.idle":"2021-05-24T10:39:50.656242Z","shell.execute_reply.started":"2021-05-24T10:39:50.635104Z","shell.execute_reply":"2021-05-24T10:39:50.654959Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def classifier_comparator(X_train,y_train,X_val,y_val,X_test,y_test,classifier=zipped_clf): \n    result = []\n    for n,c in classifier:\n        checker_pipeline = Pipeline([('Classifier', c)])\n        print(\"------------------------------Fitting {} on input_data-------------------------------- \".format(n))\n        #print(c)\n        classifier_summary(checker_pipeline,X_train, y_train, X_val, y_val,X_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:39:50.658323Z","iopub.execute_input":"2021-05-24T10:39:50.658911Z","iopub.status.idle":"2021-05-24T10:39:50.672328Z","shell.execute_reply.started":"2021-05-24T10:39:50.658848Z","shell.execute_reply":"2021-05-24T10:39:50.671255Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# ResNet50","metadata":{}},{"cell_type":"code","source":"base_model= ResNet50(input_shape=(224,224,3), weights='imagenet', include_top=False)\nx = base_model.output\n# x = Dropout(0.5)(x)\nx = Flatten()(x)\n# x = BatchNormalization()(x)\nx = Dense(16,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(32,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(64,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(128,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(256,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\npredictions = Dense(2, activation='softmax')(x)\n\nmodel_feat = Model(inputs=base_model.input,outputs=predictions)\n\ntrain_features = model_feat.predict(x_train)\nval_features=model_feat.predict(x_val)\ntest_features=model_feat.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:39:50.680929Z","iopub.execute_input":"2021-05-24T10:39:50.681306Z","iopub.status.idle":"2021-05-24T10:39:59.680316Z","shell.execute_reply.started":"2021-05-24T10:39:50.681276Z","shell.execute_reply":"2021-05-24T10:39:59.679362Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.pipeline import make_pipeline\nfrom sklearn import pipeline\nfrom sklearn.pipeline import Pipeline\nnames = [\n        \"K Nearest Neighbour Classifier\",\n        'SVM',\n        \"Random Forest Classifier\",\n        \"AdaBoost Classifier\", \n        \"XGB Classifier\"\n         ]\nclassifiers = [\n    KNeighborsClassifier(n_neighbors = 5, algorithm='ball_tree', leaf_size=30),\n    SVC(),\n    RandomForestClassifier(max_depth=9,criterion = 'entropy'),\n    AdaBoostClassifier(),\n    XGBClassifier()\n        ]\nzipped_clf = zip(names,classifiers)\ndef classifier_summary(pipeline, X_train, y_train, X_val, y_val,X_test,y_test):\n    sentiment_fit = pipeline.fit(X_train, y_train)\n    \n    y_pred_train= sentiment_fit.predict(X_train)\n    y_pred_val = sentiment_fit.predict(X_val)\n    y_pred_test = sentiment_fit.predict(X_test)\n    \n    train_accuracy = np.round(accuracy_score(y_train, y_pred_train),4)*100\n    train_precision = np.round(precision_score(y_train, y_pred_train, average='weighted'),4)\n    train_recall = np.round(recall_score(y_train, y_pred_train, average='weighted'),4)\n    train_F1 = np.round(f1_score(y_train, y_pred_train, average='weighted'),4)\n    train_kappa =  np.round(cohen_kappa_score(y_train, y_pred_train),4)\n    \n    \n    val_accuracy = np.round(accuracy_score(y_val, y_pred_val),4)*100\n    val_precision = np.round(precision_score(y_val, y_pred_val, average='weighted'),4)\n    val_recall = np.round(recall_score(y_val, y_pred_val, average='weighted'),4)\n    val_F1 = np.round(f1_score(y_val, y_pred_val, average='weighted'),4)\n    val_kappa =  np.round(cohen_kappa_score(y_val, y_pred_val),4)\n    \n    \n    test_accuracy = np.round(accuracy_score(y_test, y_pred_test),4)*100\n    test_precision = np.round(precision_score(y_test, y_pred_test, average='weighted'),2)\n    test_recall = np.round(recall_score(y_test, y_pred_test, average='weighted'),2)\n    test_F1 = np.round(f1_score(y_test, y_pred_test, average='weighted'),2)\n    test_kappa =  np.round(cohen_kappa_score(y_test, y_pred_test),2) \n  \n    \n    \n    print()\n    print('------------------------ Train Set Metrics------------------------')\n    print()\n    print(\"Accuracy core : {}%\".format(train_accuracy))\n    \n    print('------------------------ Validation Set Metrics------------------------')\n    print()\n    print(\"Accuracy score : {}%\".format(val_accuracy))\n   \n    print('------------------------ Test Set Metrics------------------------')\n    print(\"Accuracy score : {}%\".format(test_accuracy))\n    \n    print()\n    print(\"Accuracy score : {}%\".format(test_accuracy))\n    print(\"F1_score : {}\".format(test_F1))\n    print(\"Kappa Score : {} \".format(test_kappa))\n    print(\"Recall score: {}\".format(test_recall))\n    print(\"Precision score : {}\".format(test_precision))\n    \n    print(\"-\"*80)\n    print()\n    \ndef classifier_comparator(X_train,y_train,X_val,y_val,X_test,y_test,classifier=zipped_clf): \n    result = []\n    for n,c in classifier:\n        checker_pipeline = Pipeline([('Classifier', c)])\n        print(\"------------------------------Fitting {} on input_data-------------------------------- \".format(n))\n        #print(c)\n        classifier_summary(checker_pipeline,X_train, y_train, X_val, y_val,X_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:39:59.687668Z","iopub.execute_input":"2021-05-24T10:39:59.688014Z","iopub.status.idle":"2021-05-24T10:39:59.709108Z","shell.execute_reply.started":"2021-05-24T10:39:59.687962Z","shell.execute_reply":"2021-05-24T10:39:59.708062Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classifier_comparator(train_features,y_train,val_features,y_val,test_features,y_test,classifier=zipped_clf)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:39:59.711570Z","iopub.execute_input":"2021-05-24T10:39:59.712163Z","iopub.status.idle":"2021-05-24T10:40:01.429574Z","shell.execute_reply.started":"2021-05-24T10:39:59.712117Z","shell.execute_reply":"2021-05-24T10:40:01.428618Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y=to_categorical(y_train,2)\nval_y=to_categorical(y_val,2)\ntest_y=to_categorical(y_test,2)\ndnn_model.compile(optimizer='adam',loss='categorical_crossentropy', metrics=['accuracy'])\nhistory = dnn_model.fit(train_features, train_y,validation_data=(val_features,val_y), epochs=10)\nloss_value , accuracy = dnn_model.evaluate(train_features, train_y)\nprint('Train_accuracy is:' + str(accuracy))\nloss_value , accuracy = dnn_model.evaluate(val_features, val_y)\nprint('Validation_accuracy is := ' + str(accuracy))\nloss_value , accuracy = dnn_model.evaluate(test_features, test_y)\nprint('test_accuracy is : = ' + str(accuracy))","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:01.431303Z","iopub.execute_input":"2021-05-24T10:40:01.431778Z","iopub.status.idle":"2021-05-24T10:40:07.032806Z","shell.execute_reply.started":"2021-05-24T10:40:01.431732Z","shell.execute_reply":"2021-05-24T10:40:07.031710Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Performance Report:\")\ny_pred10=dnn_model.predict_classes(test_features)\ny_test10=[np.argmax(x) for x in test_y]\ny_pred_prb10=dnn_model.predict_proba(test_features)\ntarget=['0','1']\nfrom sklearn import metrics\nprint('Accuracy score is :', np.round(metrics.accuracy_score(y_test10, y_pred10),4))\nprint('Precision score is :', np.round(metrics.precision_score(y_test10, y_pred10, average='weighted'),4))\nprint('Recall score is :', np.round(metrics.recall_score(y_test10,y_pred10, average='weighted'),4))\nprint('F1 Score is :', np.round(metrics.f1_score(y_test10, y_pred10, average='weighted'),4))\nprint('Cohen Kappa Score:', np.round(metrics.cohen_kappa_score(y_test10, y_pred10),4))\nprint('\\t\\tClassification Report:\\n', metrics.classification_report(y_test10, y_pred10,target_names=target))","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:07.034554Z","iopub.execute_input":"2021-05-24T10:40:07.035028Z","iopub.status.idle":"2021-05-24T10:40:07.255491Z","shell.execute_reply.started":"2021-05-24T10:40:07.034979Z","shell.execute_reply":"2021-05-24T10:40:07.254504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"knn = KNeighborsClassifier(n_neighbors = 5, algorithm='ball_tree', leaf_size=30)\nknn.fit(train_features, y_train)\nplot_confusion_matrix(knn, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:07.257484Z","iopub.execute_input":"2021-05-24T10:40:07.257903Z","iopub.status.idle":"2021-05-24T10:40:07.486678Z","shell.execute_reply.started":"2021-05-24T10:40:07.257846Z","shell.execute_reply":"2021-05-24T10:40:07.485544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"svc = SVC()\nsvc.fit(train_features, y_train)\nplot_confusion_matrix(svc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:07.488228Z","iopub.execute_input":"2021-05-24T10:40:07.488662Z","iopub.status.idle":"2021-05-24T10:40:07.901358Z","shell.execute_reply.started":"2021-05-24T10:40:07.488617Z","shell.execute_reply":"2021-05-24T10:40:07.900023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rf = RandomForestClassifier()\nrf.fit(train_features, y_train)\nplot_confusion_matrix(rf, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:07.903452Z","iopub.execute_input":"2021-05-24T10:40:07.903951Z","iopub.status.idle":"2021-05-24T10:40:08.546896Z","shell.execute_reply.started":"2021-05-24T10:40:07.903906Z","shell.execute_reply":"2021-05-24T10:40:08.545479Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ada = AdaBoostClassifier()\nada.fit(train_features, y_train)\nplot_confusion_matrix(ada, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:08.548966Z","iopub.execute_input":"2021-05-24T10:40:08.549448Z","iopub.status.idle":"2021-05-24T10:40:08.904202Z","shell.execute_reply.started":"2021-05-24T10:40:08.549402Z","shell.execute_reply":"2021-05-24T10:40:08.902789Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xgbc = XGBClassifier()\nxgbc.fit(train_features, y_train)\nplot_confusion_matrix(xgbc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:08.906158Z","iopub.execute_input":"2021-05-24T10:40:08.906750Z","iopub.status.idle":"2021-05-24T10:40:09.259359Z","shell.execute_reply.started":"2021-05-24T10:40:08.906703Z","shell.execute_reply":"2021-05-24T10:40:09.258204Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# VGG-16","metadata":{}},{"cell_type":"code","source":"base_model= VGG16(input_shape=(224,224,3), weights='imagenet', include_top=False)\nx = base_model.output\n# x = Dropout(0.5)(x)\nx = Flatten()(x)\n# x = BatchNormalization()(x)\nx = Dense(16,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(32,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(64,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(128,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(256,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\npredictions = Dense(2, activation='softmax')(x)\n\nmodel_feat = Model(inputs=base_model.input,outputs=predictions)\n\ntrain_features = model_feat.predict(x_train)\nval_features=model_feat.predict(x_val)\ntest_features=model_feat.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:09.260853Z","iopub.execute_input":"2021-05-24T10:40:09.261294Z","iopub.status.idle":"2021-05-24T10:40:16.767190Z","shell.execute_reply.started":"2021-05-24T10:40:09.261252Z","shell.execute_reply":"2021-05-24T10:40:16.766203Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.pipeline import make_pipeline\nfrom sklearn.pipeline import Pipeline\nnames = [\n        \"K Nearest Neighbour Classifier\",\n        'SVM',\n        \"Random Forest Classifier\",\n        \"AdaBoost Classifier\", \n        \"XGB Classifier\"\n         ]\nclassifiers = [\n    KNeighborsClassifier(n_neighbors = 5, algorithm='ball_tree', leaf_size=30),\n    SVC(),\n    RandomForestClassifier(max_depth=9,criterion = 'entropy'),\n    AdaBoostClassifier(),\n    XGBClassifier()\n        ]\nzipped_clf = zip(names,classifiers)\ndef classifier_summary(pipeline, X_train, y_train, X_val, y_val,X_test,y_test):\n    sentiment_fit = pipeline.fit(X_train, y_train)\n    \n    y_pred_train= sentiment_fit.predict(X_train)\n    y_pred_val = sentiment_fit.predict(X_val)\n    y_pred_test = sentiment_fit.predict(X_test)\n    \n    train_accuracy = np.round(accuracy_score(y_train, y_pred_train),4)*100\n    train_precision = np.round(precision_score(y_train, y_pred_train, average='weighted'),4)\n    train_recall = np.round(recall_score(y_train, y_pred_train, average='weighted'),4)\n    train_F1 = np.round(f1_score(y_train, y_pred_train, average='weighted'),4)\n    train_kappa =  np.round(cohen_kappa_score(y_train, y_pred_train),4)\n    \n    \n    val_accuracy = np.round(accuracy_score(y_val, y_pred_val),4)*100\n    val_precision = np.round(precision_score(y_val, y_pred_val, average='weighted'),4)\n    val_recall = np.round(recall_score(y_val, y_pred_val, average='weighted'),4)\n    val_F1 = np.round(f1_score(y_val, y_pred_val, average='weighted'),4)\n    val_kappa =  np.round(cohen_kappa_score(y_val, y_pred_val),4)\n   \n    \n    test_accuracy = np.round(accuracy_score(y_test, y_pred_test),4)*100\n    test_precision = np.round(precision_score(y_test, y_pred_test, average='weighted'),2)\n    test_recall = np.round(recall_score(y_test, y_pred_test, average='weighted'),2)\n    test_F1 = np.round(f1_score(y_test, y_pred_test, average='weighted'),2)\n    test_kappa =  np.round(cohen_kappa_score(y_test, y_pred_test),2) \n  \n    \n    \n    print()\n    print('------------------------ Train Set Metrics------------------------')\n    print()\n    print(\"Accuracy core : {}%\".format(train_accuracy))\n    \n    print('------------------------ Validation Set Metrics------------------------')\n    print()\n    print(\"Accuracy score : {}%\".format(val_accuracy))\n    print('------------------------ Test Set Metrics------------------------')\n    print()\n    print(\"Accuracy score : {}%\".format(test_accuracy))\n    print(\"F1_score : {}\".format(test_F1))\n    print(\"Kappa Score : {} \".format(test_kappa))\n    print(\"Recall score: {}\".format(test_recall))\n    print(\"Precision score : {}\".format(test_precision))\n    \n    print(\"-\"*80)\n    print()\n    \ndef classifier_comparator(X_train,y_train,X_val,y_val,X_test,y_test,classifier=zipped_clf): \n    result = []\n    for n,c in classifier:\n        checker_pipeline = Pipeline([('Classifier', c)])\n        print(\"------------------------------Fitting {} on input_data-------------------------------- \".format(n))\n        #print(c)\n        classifier_summary(checker_pipeline,X_train, y_train, X_val, y_val,X_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:16.769140Z","iopub.execute_input":"2021-05-24T10:40:16.769662Z","iopub.status.idle":"2021-05-24T10:40:16.789468Z","shell.execute_reply.started":"2021-05-24T10:40:16.769605Z","shell.execute_reply":"2021-05-24T10:40:16.788244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classifier_comparator(train_features,y_train,val_features,y_val,test_features,y_test,classifier=zipped_clf)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:16.791173Z","iopub.execute_input":"2021-05-24T10:40:16.791916Z","iopub.status.idle":"2021-05-24T10:40:18.610299Z","shell.execute_reply.started":"2021-05-24T10:40:16.791812Z","shell.execute_reply":"2021-05-24T10:40:18.606853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y=to_categorical(y_train,2)\nval_y=to_categorical(y_val,2)\ntest_y=to_categorical(y_test,2)\ndnn_model.compile(optimizer='adam',loss='categorical_crossentropy', metrics=['accuracy'])\nhistory = dnn_model.fit(train_features, train_y,validation_data=(val_features,val_y), epochs=10)\nloss_value , accuracy = dnn_model.evaluate(train_features, train_y)\nprint('Train_accuracy is:' + str(accuracy))\nloss_value , accuracy = dnn_model.evaluate(val_features, val_y)\nprint('Validation_accuracy is := ' + str(accuracy))\nloss_value , accuracy = dnn_model.evaluate(test_features, test_y)\nprint('test_accuracy is : = ' + str(accuracy))","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:18.612019Z","iopub.execute_input":"2021-05-24T10:40:18.612435Z","iopub.status.idle":"2021-05-24T10:40:24.049572Z","shell.execute_reply.started":"2021-05-24T10:40:18.612377Z","shell.execute_reply":"2021-05-24T10:40:24.048518Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Performance Report:\")\ny_pred2=dnn_model.predict_classes(test_features)\ny_test2=[np.argmax(x) for x in test_y]\ny_pred_prb2=dnn_model.predict_proba(test_features)\ntarget=['0','1']\nfrom sklearn import metrics\nprint('Accuracy score is :', np.round(metrics.accuracy_score(y_test2, y_pred2),4))\nprint('Precision score is :', np.round(metrics.precision_score(y_test2, y_pred2, average='weighted'),4))\nprint('Recall score is :', np.round(metrics.recall_score(y_test2,y_pred2, average='weighted'),4))\nprint('F1 Score is :', np.round(metrics.f1_score(y_test2, y_pred2, average='weighted'),4))\nprint('Cohen Kappa Score:', np.round(metrics.cohen_kappa_score(y_test2, y_pred2),4))\nprint('\\t\\tClassification Report:\\n', metrics.classification_report(y_test2, y_pred2,target_names=target))","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:24.053111Z","iopub.execute_input":"2021-05-24T10:40:24.053429Z","iopub.status.idle":"2021-05-24T10:40:24.274030Z","shell.execute_reply.started":"2021-05-24T10:40:24.053397Z","shell.execute_reply":"2021-05-24T10:40:24.273022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"knn = KNeighborsClassifier(n_neighbors = 5, algorithm='ball_tree', leaf_size=30)\nknn.fit(train_features, y_train)\nplot_confusion_matrix(knn, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:24.277800Z","iopub.execute_input":"2021-05-24T10:40:24.278152Z","iopub.status.idle":"2021-05-24T10:40:24.504136Z","shell.execute_reply.started":"2021-05-24T10:40:24.278122Z","shell.execute_reply":"2021-05-24T10:40:24.502928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"svc = SVC()\nsvc.fit(train_features, y_train)\nplot_confusion_matrix(svc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:24.508055Z","iopub.execute_input":"2021-05-24T10:40:24.508426Z","iopub.status.idle":"2021-05-24T10:40:24.951775Z","shell.execute_reply.started":"2021-05-24T10:40:24.508395Z","shell.execute_reply":"2021-05-24T10:40:24.950799Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rf = RandomForestClassifier()\nrf.fit(train_features, y_train)\nplot_confusion_matrix(rf, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:24.955970Z","iopub.execute_input":"2021-05-24T10:40:24.956330Z","iopub.status.idle":"2021-05-24T10:40:25.625599Z","shell.execute_reply.started":"2021-05-24T10:40:24.956300Z","shell.execute_reply":"2021-05-24T10:40:25.624474Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ada = AdaBoostClassifier()\nada.fit(train_features, y_train)\nplot_confusion_matrix(ada, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:25.627115Z","iopub.execute_input":"2021-05-24T10:40:25.627533Z","iopub.status.idle":"2021-05-24T10:40:25.977508Z","shell.execute_reply.started":"2021-05-24T10:40:25.627488Z","shell.execute_reply":"2021-05-24T10:40:25.974912Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xgbc = XGBClassifier()\nxgbc.fit(train_features, y_train)\nplot_confusion_matrix(xgbc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:25.981150Z","iopub.execute_input":"2021-05-24T10:40:25.982326Z","iopub.status.idle":"2021-05-24T10:40:26.887632Z","shell.execute_reply.started":"2021-05-24T10:40:25.982182Z","shell.execute_reply":"2021-05-24T10:40:26.886635Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# VGG-19","metadata":{}},{"cell_type":"code","source":"base_model= VGG19(input_shape=(224,224,3), weights='imagenet', include_top=False)\nx = base_model.output\n# x = Dropout(0.5)(x)\nx = Flatten()(x)\n# x = BatchNormalization()(x)\nx = Dense(16,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(32,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(64,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(128,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(256,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\npredictions = Dense(2, activation='softmax')(x)\n\nmodel_feat = Model(inputs=base_model.input,outputs=predictions)\n\ntrain_features = model_feat.predict(x_train)\nval_features=model_feat.predict(x_val)\ntest_features=model_feat.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:26.891313Z","iopub.execute_input":"2021-05-24T10:40:26.891608Z","iopub.status.idle":"2021-05-24T10:40:36.159246Z","shell.execute_reply.started":"2021-05-24T10:40:26.891579Z","shell.execute_reply":"2021-05-24T10:40:36.158248Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.pipeline import make_pipeline\nfrom sklearn.pipeline import Pipeline\nnames = [\n        \"K Nearest Neighbour Classifier\",\n        'SVM',\n        \"Random Forest Classifier\",\n        \"AdaBoost Classifier\", \n        \"XGB Classifier\"\n         ]\nclassifiers = [\n    KNeighborsClassifier(n_neighbors = 5, algorithm='ball_tree', leaf_size=30),\n    SVC(),\n    RandomForestClassifier(max_depth=9,criterion = 'entropy'),\n    AdaBoostClassifier(),\n    XGBClassifier()\n        ]\nzipped_clf = zip(names,classifiers)\ndef classifier_summary(pipeline, X_train, y_train, X_val, y_val,X_test,y_test):\n    sentiment_fit = pipeline.fit(X_train, y_train)\n    \n    y_pred_train= sentiment_fit.predict(X_train)\n    y_pred_val = sentiment_fit.predict(X_val)\n    y_pred_test = sentiment_fit.predict(X_test)\n    \n    train_accuracy = np.round(accuracy_score(y_train, y_pred_train),4)*100\n    train_precision = np.round(precision_score(y_train, y_pred_train, average='weighted'),4)\n    train_recall = np.round(recall_score(y_train, y_pred_train, average='weighted'),4)\n    train_F1 = np.round(f1_score(y_train, y_pred_train, average='weighted'),4)\n    train_kappa =  np.round(cohen_kappa_score(y_train, y_pred_train),4)\n    \n    \n    val_accuracy = np.round(accuracy_score(y_val, y_pred_val),4)*100\n    val_precision = np.round(precision_score(y_val, y_pred_val, average='weighted'),4)\n    val_recall = np.round(recall_score(y_val, y_pred_val, average='weighted'),4)\n    val_F1 = np.round(f1_score(y_val, y_pred_val, average='weighted'),4)\n    val_kappa =  np.round(cohen_kappa_score(y_val, y_pred_val),4)\n   \n    \n    test_accuracy = np.round(accuracy_score(y_test, y_pred_test),4)*100\n    test_precision = np.round(precision_score(y_test, y_pred_test, average='weighted'),2)\n    test_recall = np.round(recall_score(y_test, y_pred_test, average='weighted'),2)\n    test_F1 = np.round(f1_score(y_test, y_pred_test, average='weighted'),2)\n    test_kappa =  np.round(cohen_kappa_score(y_test, y_pred_test),2) \n  \n    \n    \n    print()\n    print('------------------------ Train Set Metrics------------------------')\n    print()\n    print(\"Accuracy core : {}%\".format(train_accuracy))\n    \n    print('------------------------ Validation Set Metrics------------------------')\n    print()\n    print(\"Accuracy score : {}%\".format(val_accuracy))\n    print('------------------------ Test Set Metrics------------------------')\n    print()\n    print(\"Accuracy score : {}%\".format(test_accuracy))\n    print(\"F1_score : {}\".format(test_F1))\n    print(\"Kappa Score : {} \".format(test_kappa))\n    print(\"Recall score: {}\".format(test_recall))\n    print(\"Precision score : {}\".format(test_precision))\n    \n    print(\"-\"*80)\n    print()\n    \ndef classifier_comparator(X_train,y_train,X_val,y_val,X_test,y_test,classifier=zipped_clf): \n    result = []\n    for n,c in classifier:\n        checker_pipeline = Pipeline([('Classifier', c)])\n        print(\"------------------------------Fitting {} on input_data-------------------------------- \".format(n))\n        #print(c)\n        classifier_summary(checker_pipeline,X_train, y_train, X_val, y_val,X_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:36.161152Z","iopub.execute_input":"2021-05-24T10:40:36.161596Z","iopub.status.idle":"2021-05-24T10:40:36.183092Z","shell.execute_reply.started":"2021-05-24T10:40:36.161548Z","shell.execute_reply":"2021-05-24T10:40:36.179898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classifier_comparator(train_features,y_train,val_features,y_val,test_features,y_test,classifier=zipped_clf)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:36.185225Z","iopub.execute_input":"2021-05-24T10:40:36.185788Z","iopub.status.idle":"2021-05-24T10:40:38.199199Z","shell.execute_reply.started":"2021-05-24T10:40:36.185721Z","shell.execute_reply":"2021-05-24T10:40:38.195535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y=to_categorical(y_train,2)\nval_y=to_categorical(y_val,2)\ntest_y=to_categorical(y_test,2)\ndnn_model.compile(optimizer='adam',loss='categorical_crossentropy', metrics=['accuracy'])\nhistory = dnn_model.fit(train_features, train_y,validation_data=(val_features,val_y), epochs=10)\nloss_value , accuracy = dnn_model.evaluate(train_features, train_y)\nprint('Train_accuracy is:' + str(accuracy))\nloss_value , accuracy = dnn_model.evaluate(val_features, val_y)\nprint('Validation_accuracy is := ' + str(accuracy))\nloss_value , accuracy = dnn_model.evaluate(test_features, test_y)\nprint('test_accuracy is : = ' + str(accuracy))","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:38.201019Z","iopub.execute_input":"2021-05-24T10:40:38.201453Z","iopub.status.idle":"2021-05-24T10:40:43.624193Z","shell.execute_reply.started":"2021-05-24T10:40:38.201409Z","shell.execute_reply":"2021-05-24T10:40:43.623084Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Performance Report:\")\ny_pred1=dnn_model.predict_classes(test_features)\ny_test1=[np.argmax(x) for x in test_y]\ny_pred_prb1=dnn_model.predict_proba(test_features)\ntarget=['0','1']\nfrom sklearn import metrics\nprint('Accuracy score is :', np.round(metrics.accuracy_score(y_test1, y_pred1),4))\nprint('Precision score is :', np.round(metrics.precision_score(y_test1, y_pred1, average='weighted'),4))\nprint('Recall score is :', np.round(metrics.recall_score(y_test1,y_pred1, average='weighted'),4))\nprint('F1 Score is :', np.round(metrics.f1_score(y_test1, y_pred1, average='weighted'),4))\nprint('Cohen Kappa Score:', np.round(metrics.cohen_kappa_score(y_test1, y_pred1),4))\nprint('\\t\\tClassification Report:\\n', metrics.classification_report(y_test1, y_pred1,target_names=target))","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:43.627971Z","iopub.execute_input":"2021-05-24T10:40:43.628286Z","iopub.status.idle":"2021-05-24T10:40:43.853628Z","shell.execute_reply.started":"2021-05-24T10:40:43.628255Z","shell.execute_reply":"2021-05-24T10:40:43.851267Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"knn = KNeighborsClassifier(n_neighbors = 5, algorithm='ball_tree', leaf_size=30)\nknn.fit(train_features, y_train)\nplot_confusion_matrix(knn, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:43.857634Z","iopub.execute_input":"2021-05-24T10:40:43.857984Z","iopub.status.idle":"2021-05-24T10:40:44.100310Z","shell.execute_reply.started":"2021-05-24T10:40:43.857954Z","shell.execute_reply":"2021-05-24T10:40:44.099326Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"svc = SVC()\nsvc.fit(train_features, y_train)\nplot_confusion_matrix(svc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:44.103159Z","iopub.execute_input":"2021-05-24T10:40:44.103507Z","iopub.status.idle":"2021-05-24T10:40:44.568720Z","shell.execute_reply.started":"2021-05-24T10:40:44.103477Z","shell.execute_reply":"2021-05-24T10:40:44.567733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rf = RandomForestClassifier()\nrf.fit(train_features, y_train)\nplot_confusion_matrix(rf, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:44.570491Z","iopub.execute_input":"2021-05-24T10:40:44.570942Z","iopub.status.idle":"2021-05-24T10:40:45.124678Z","shell.execute_reply.started":"2021-05-24T10:40:44.570898Z","shell.execute_reply":"2021-05-24T10:40:45.123757Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ada = AdaBoostClassifier()\nada.fit(train_features, y_train)\nplot_confusion_matrix(ada, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:45.127208Z","iopub.execute_input":"2021-05-24T10:40:45.127668Z","iopub.status.idle":"2021-05-24T10:40:45.472369Z","shell.execute_reply.started":"2021-05-24T10:40:45.127624Z","shell.execute_reply":"2021-05-24T10:40:45.471159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xgbc = XGBClassifier()\nxgbc.fit(train_features, y_train)\nplot_confusion_matrix(xgbc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:45.475019Z","iopub.execute_input":"2021-05-24T10:40:45.475534Z","iopub.status.idle":"2021-05-24T10:40:45.865825Z","shell.execute_reply.started":"2021-05-24T10:40:45.475489Z","shell.execute_reply":"2021-05-24T10:40:45.864848Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# ResNet101","metadata":{}},{"cell_type":"code","source":"base_model= ResNet101(input_shape=(224,224,3), weights='imagenet', include_top=False)\nx = base_model.output\n# x = Dropout(0.5)(x)\nx = Flatten()(x)\n# x = BatchNormalization()(x)\nx = Dense(16,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(32,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(64,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(128,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(256,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\npredictions = Dense(2, activation='softmax')(x)\n\nmodel_feat = Model(inputs=base_model.input,outputs=predictions)\n\ntrain_features = model_feat.predict(x_train)\nval_features=model_feat.predict(x_val)\ntest_features=model_feat.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:40:45.867447Z","iopub.execute_input":"2021-05-24T10:40:45.867947Z","iopub.status.idle":"2021-05-24T10:41:07.140584Z","shell.execute_reply.started":"2021-05-24T10:40:45.867905Z","shell.execute_reply":"2021-05-24T10:41:07.139517Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.pipeline import make_pipeline\nfrom sklearn.pipeline import Pipeline\nnames = [\n        \"K Nearest Neighbour Classifier\",\n        'SVM',\n        \"Random Forest Classifier\",\n        \"AdaBoost Classifier\", \n        \"XGB Classifier\"\n         ]\nclassifiers = [\n    KNeighborsClassifier(n_neighbors = 5, algorithm='ball_tree', leaf_size=30),\n    SVC(),\n    RandomForestClassifier(max_depth=9,criterion = 'entropy'),\n    AdaBoostClassifier(),\n    XGBClassifier()\n        ]\nzipped_clf = zip(names,classifiers)\ndef classifier_summary(pipeline, X_train, y_train, X_val, y_val,X_test,y_test):\n    sentiment_fit = pipeline.fit(X_train, y_train)\n    \n    y_pred_train= sentiment_fit.predict(X_train)\n    y_pred_val = sentiment_fit.predict(X_val)\n    y_pred_test = sentiment_fit.predict(X_test)\n    \n    train_accuracy = np.round(accuracy_score(y_train, y_pred_train),4)*100\n    train_precision = np.round(precision_score(y_train, y_pred_train, average='weighted'),4)\n    train_recall = np.round(recall_score(y_train, y_pred_train, average='weighted'),4)\n    train_F1 = np.round(f1_score(y_train, y_pred_train, average='weighted'),4)\n    train_kappa =  np.round(cohen_kappa_score(y_train, y_pred_train),4)\n    \n    \n    val_accuracy = np.round(accuracy_score(y_val, y_pred_val),4)*100\n    val_precision = np.round(precision_score(y_val, y_pred_val, average='weighted'),4)\n    val_recall = np.round(recall_score(y_val, y_pred_val, average='weighted'),4)\n    val_F1 = np.round(f1_score(y_val, y_pred_val, average='weighted'),4)\n    val_kappa =  np.round(cohen_kappa_score(y_val, y_pred_val),4)\n   \n    \n    test_accuracy = np.round(accuracy_score(y_test, y_pred_test),4)*100\n    test_precision = np.round(precision_score(y_test, y_pred_test, average='weighted'),2)\n    test_recall = np.round(recall_score(y_test, y_pred_test, average='weighted'),2)\n    test_F1 = np.round(f1_score(y_test, y_pred_test, average='weighted'),2)\n    test_kappa =  np.round(cohen_kappa_score(y_test, y_pred_test),2) \n  \n    \n    \n    print()\n    print('------------------------ Train Set Metrics------------------------')\n    print()\n    print(\"Accuracy core : {}%\".format(train_accuracy))\n    \n    print('------------------------ Validation Set Metrics------------------------')\n    print()\n    print(\"Accuracy score : {}%\".format(val_accuracy))\n    print('------------------------ Test Set Metrics------------------------')\n    print()\n    print(\"Accuracy score : {}%\".format(test_accuracy))\n    print(\"F1_score : {}\".format(test_F1))\n    print(\"Kappa Score : {} \".format(test_kappa))\n    print(\"Recall score: {}\".format(test_recall))\n    print(\"Precision score : {}\".format(test_precision))\n    \n    print(\"-\"*80)\n    print()\n    \ndef classifier_comparator(X_train,y_train,X_val,y_val,X_test,y_test,classifier=zipped_clf): \n    result = []\n    for n,c in classifier:\n        checker_pipeline = Pipeline([('Classifier', c)])\n        print(\"------------------------------Fitting {} on input_data-------------------------------- \".format(n))\n        #print(c)\n        classifier_summary(checker_pipeline,X_train, y_train, X_val, y_val,X_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:07.142457Z","iopub.execute_input":"2021-05-24T10:41:07.142948Z","iopub.status.idle":"2021-05-24T10:41:07.166572Z","shell.execute_reply.started":"2021-05-24T10:41:07.142906Z","shell.execute_reply":"2021-05-24T10:41:07.165567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classifier_comparator(train_features,y_train,val_features,y_val,test_features,y_test,classifier=zipped_clf)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:07.170324Z","iopub.execute_input":"2021-05-24T10:41:07.170644Z","iopub.status.idle":"2021-05-24T10:41:09.356537Z","shell.execute_reply.started":"2021-05-24T10:41:07.170604Z","shell.execute_reply":"2021-05-24T10:41:09.352789Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y=to_categorical(y_train,2)\nval_y=to_categorical(y_val,2)\ntest_y=to_categorical(y_test,2)\ndnn_model.compile(optimizer='adam',loss='categorical_crossentropy', metrics=['accuracy'])\nhistory = dnn_model.fit(train_features, train_y,validation_data=(val_features,val_y), epochs=10)\nloss_value , accuracy = dnn_model.evaluate(train_features, train_y)\nprint('Train_accuracy is:' + str(accuracy))\nloss_value , accuracy = dnn_model.evaluate(val_features, val_y)\nprint('Validation_accuracy is := ' + str(accuracy))\nloss_value , accuracy = dnn_model.evaluate(test_features, test_y)\nprint('test_accuracy is : = ' + str(accuracy))","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:09.358340Z","iopub.execute_input":"2021-05-24T10:41:09.358834Z","iopub.status.idle":"2021-05-24T10:41:15.029240Z","shell.execute_reply.started":"2021-05-24T10:41:09.358790Z","shell.execute_reply":"2021-05-24T10:41:15.028309Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Performance Report:\")\ny_pred3=dnn_model.predict_classes(test_features)\ny_test3=[np.argmax(x) for x in test_y]\ny_pred_prb3=dnn_model.predict_proba(test_features)\ntarget=['0','1']\nfrom sklearn import metrics\nprint('Accuracy score is :', np.round(metrics.accuracy_score(y_test3, y_pred3),4))\nprint('Precision score is :', np.round(metrics.precision_score(y_test3, y_pred3, average='weighted'),4))\nprint('Recall score is :', np.round(metrics.recall_score(y_test3,y_pred3, average='weighted'),4))\nprint('F1 Score is :', np.round(metrics.f1_score(y_test3, y_pred3, average='weighted'),4))\nprint('Cohen Kappa Score:', np.round(metrics.cohen_kappa_score(y_test3, y_pred3),4))\nprint('\\t\\tClassification Report:\\n', metrics.classification_report(y_test3, y_pred3,target_names=target))","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:15.032951Z","iopub.execute_input":"2021-05-24T10:41:15.033262Z","iopub.status.idle":"2021-05-24T10:41:15.259455Z","shell.execute_reply.started":"2021-05-24T10:41:15.033233Z","shell.execute_reply":"2021-05-24T10:41:15.257449Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"knn = KNeighborsClassifier(n_neighbors = 5, algorithm='ball_tree', leaf_size=30)\nknn.fit(train_features, y_train)\nplot_confusion_matrix(knn, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:15.263941Z","iopub.execute_input":"2021-05-24T10:41:15.264303Z","iopub.status.idle":"2021-05-24T10:41:15.487929Z","shell.execute_reply.started":"2021-05-24T10:41:15.264271Z","shell.execute_reply":"2021-05-24T10:41:15.486741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"svc = SVC()\nsvc.fit(train_features, y_train)\nplot_confusion_matrix(svc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:15.489554Z","iopub.execute_input":"2021-05-24T10:41:15.490013Z","iopub.status.idle":"2021-05-24T10:41:15.958158Z","shell.execute_reply.started":"2021-05-24T10:41:15.489969Z","shell.execute_reply":"2021-05-24T10:41:15.955413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rf = RandomForestClassifier()\nrf.fit(train_features, y_train)\nplot_confusion_matrix(rf, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:15.960185Z","iopub.execute_input":"2021-05-24T10:41:15.960684Z","iopub.status.idle":"2021-05-24T10:41:16.673500Z","shell.execute_reply.started":"2021-05-24T10:41:15.960636Z","shell.execute_reply":"2021-05-24T10:41:16.672112Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ada = AdaBoostClassifier()\nada.fit(train_features, y_train)\nplot_confusion_matrix(ada, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:16.675597Z","iopub.execute_input":"2021-05-24T10:41:16.676094Z","iopub.status.idle":"2021-05-24T10:41:17.043289Z","shell.execute_reply.started":"2021-05-24T10:41:16.676047Z","shell.execute_reply":"2021-05-24T10:41:17.041846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xgbc = XGBClassifier()\nxgbc.fit(train_features, y_train)\nplot_confusion_matrix(xgbc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:17.045308Z","iopub.execute_input":"2021-05-24T10:41:17.045798Z","iopub.status.idle":"2021-05-24T10:41:17.444681Z","shell.execute_reply.started":"2021-05-24T10:41:17.045755Z","shell.execute_reply":"2021-05-24T10:41:17.443488Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# MobileNetV2","metadata":{}},{"cell_type":"code","source":"base_model= MobileNetV2(input_shape=(224,224,3), weights='imagenet', include_top=False)\nx = base_model.output\nx = Dropout(0.5)(x)\nx = Flatten()(x)\n# x = BatchNormalization()(x)\nx = Dense(16,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(32,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(64,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(128,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(256,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\npredictions = Dense(2, activation='softmax')(x)\n\nmodel_feat = Model(inputs=base_model.input,outputs=predictions)\n\ntrain_features = model_feat.predict(x_train)\nval_features=model_feat.predict(x_val)\ntest_features=model_feat.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:17.446378Z","iopub.execute_input":"2021-05-24T10:41:17.446804Z","iopub.status.idle":"2021-05-24T10:41:23.778929Z","shell.execute_reply.started":"2021-05-24T10:41:17.446759Z","shell.execute_reply":"2021-05-24T10:41:23.777904Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.pipeline import make_pipeline\nfrom sklearn.pipeline import Pipeline\nnames = [\n        \"K Nearest Neighbour Classifier\",\n        'SVM',\n        \"Random Forest Classifier\",\n        \"AdaBoost Classifier\", \n        \"XGB Classifier\"\n         ]\nclassifiers = [\n    KNeighborsClassifier(n_neighbors = 5, algorithm='ball_tree', leaf_size=30),\n    SVC(),\n    RandomForestClassifier(max_depth=9,criterion = 'entropy'),\n    AdaBoostClassifier(),\n    XGBClassifier()\n        ]\nzipped_clf = zip(names,classifiers)\ndef classifier_summary(pipeline, X_train, y_train, X_val, y_val,X_test,y_test):\n    sentiment_fit = pipeline.fit(X_train, y_train)\n    \n    y_pred_train= sentiment_fit.predict(X_train)\n    y_pred_val = sentiment_fit.predict(X_val)\n    y_pred_test = sentiment_fit.predict(X_test)\n    \n    train_accuracy = np.round(accuracy_score(y_train, y_pred_train),4)*100\n    train_precision = np.round(precision_score(y_train, y_pred_train, average='weighted'),4)\n    train_recall = np.round(recall_score(y_train, y_pred_train, average='weighted'),4)\n    train_F1 = np.round(f1_score(y_train, y_pred_train, average='weighted'),4)\n    train_kappa =  np.round(cohen_kappa_score(y_train, y_pred_train),4)\n    \n    \n    val_accuracy = np.round(accuracy_score(y_val, y_pred_val),4)*100\n    val_precision = np.round(precision_score(y_val, y_pred_val, average='weighted'),4)\n    val_recall = np.round(recall_score(y_val, y_pred_val, average='weighted'),4)\n    val_F1 = np.round(f1_score(y_val, y_pred_val, average='weighted'),4)\n    val_kappa =  np.round(cohen_kappa_score(y_val, y_pred_val),4)\n   \n    \n    test_accuracy = np.round(accuracy_score(y_test, y_pred_test),4)*100\n    test_precision = np.round(precision_score(y_test, y_pred_test, average='weighted'),2)\n    test_recall = np.round(recall_score(y_test, y_pred_test, average='weighted'),2)\n    test_F1 = np.round(f1_score(y_test, y_pred_test, average='weighted'),2)\n    test_kappa =  np.round(cohen_kappa_score(y_test, y_pred_test),2) \n  \n    \n    \n    print()\n    print('------------------------ Train Set Metrics------------------------')\n    print()\n    print(\"Accuracy core : {}%\".format(train_accuracy))\n    \n    print('------------------------ Validation Set Metrics------------------------')\n    print()\n    print(\"Accuracy score : {}%\".format(val_accuracy))\n    print('------------------------ Test Set Metrics------------------------')\n    print()\n    print(\"Accuracy score : {}%\".format(test_accuracy))\n    print(\"F1_score : {}\".format(test_F1))\n    print(\"Kappa Score : {} \".format(test_kappa))\n    print(\"Recall score: {}\".format(test_recall))\n    print(\"Precision score : {}\".format(test_precision))\n    \n    print(\"-\"*80)\n    print()\n    \ndef classifier_comparator(X_train,y_train,X_val,y_val,X_test,y_test,classifier=zipped_clf): \n    result = []\n    for n,c in classifier:\n        checker_pipeline = Pipeline([('Classifier', c)])\n        print(\"------------------------------Fitting {} on input_data-------------------------------- \".format(n))\n        #print(c)\n        classifier_summary(checker_pipeline,X_train, y_train, X_val, y_val,X_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:23.783195Z","iopub.execute_input":"2021-05-24T10:41:23.783504Z","iopub.status.idle":"2021-05-24T10:41:23.815923Z","shell.execute_reply.started":"2021-05-24T10:41:23.783459Z","shell.execute_reply":"2021-05-24T10:41:23.814721Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classifier_comparator(train_features,y_train,val_features,y_val,test_features,y_test,classifier=zipped_clf)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:23.819878Z","iopub.execute_input":"2021-05-24T10:41:23.820309Z","iopub.status.idle":"2021-05-24T10:41:25.505053Z","shell.execute_reply.started":"2021-05-24T10:41:23.820275Z","shell.execute_reply":"2021-05-24T10:41:25.502691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y=to_categorical(y_train,2)\nval_y=to_categorical(y_val,2)\ntest_y=to_categorical(y_test,2)\ndnn_model.compile(optimizer='adam',loss='categorical_crossentropy', metrics=['accuracy'])\nhistory = dnn_model.fit(train_features, train_y,validation_data=(val_features,val_y), epochs=10)\nloss_value , accuracy = dnn_model.evaluate(train_features, train_y)\nprint('Train_accuracy is:' + str(accuracy))\nloss_value , accuracy = dnn_model.evaluate(val_features, val_y)\nprint('Validation_accuracy is := ' + str(accuracy))\nloss_value , accuracy = dnn_model.evaluate(test_features, test_y)\nprint('test_accuracy is : = ' + str(accuracy))","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:25.506794Z","iopub.execute_input":"2021-05-24T10:41:25.507232Z","iopub.status.idle":"2021-05-24T10:41:31.061654Z","shell.execute_reply.started":"2021-05-24T10:41:25.507188Z","shell.execute_reply":"2021-05-24T10:41:31.060581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Performance Report:\")\ny_pred4=dnn_model.predict_classes(test_features)\ny_test4=[np.argmax(x) for x in test_y]\ny_pred_prb4=dnn_model.predict_proba(test_features)\ntarget=['0','1']\nfrom sklearn import metrics\nprint('Accuracy score is :', np.round(metrics.accuracy_score(y_test4, y_pred4),4))\nprint('Precision score is :', np.round(metrics.precision_score(y_test4, y_pred4, average='weighted'),4))\nprint('Recall score is :', np.round(metrics.recall_score(y_test4,y_pred4, average='weighted'),4))\nprint('F1 Score is :', np.round(metrics.f1_score(y_test4, y_pred4, average='weighted'),4))\nprint('Cohen Kappa Score:', np.round(metrics.cohen_kappa_score(y_test4, y_pred4),4))\nprint('\\t\\tClassification Report:\\n', metrics.classification_report(y_test4, y_pred4,target_names=target))","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:31.066364Z","iopub.execute_input":"2021-05-24T10:41:31.066706Z","iopub.status.idle":"2021-05-24T10:41:31.294626Z","shell.execute_reply.started":"2021-05-24T10:41:31.066672Z","shell.execute_reply":"2021-05-24T10:41:31.293548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"knn = KNeighborsClassifier(n_neighbors = 5, algorithm='ball_tree', leaf_size=30)\nknn.fit(train_features, y_train)\nplot_confusion_matrix(knn, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:31.298484Z","iopub.execute_input":"2021-05-24T10:41:31.298779Z","iopub.status.idle":"2021-05-24T10:41:31.521976Z","shell.execute_reply.started":"2021-05-24T10:41:31.298749Z","shell.execute_reply":"2021-05-24T10:41:31.521082Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"svc = SVC()\nsvc.fit(train_features, y_train)\nplot_confusion_matrix(svc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:31.523834Z","iopub.execute_input":"2021-05-24T10:41:31.524254Z","iopub.status.idle":"2021-05-24T10:41:31.939903Z","shell.execute_reply.started":"2021-05-24T10:41:31.524211Z","shell.execute_reply":"2021-05-24T10:41:31.938956Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rf = RandomForestClassifier()\nrf.fit(train_features, y_train)\nplot_confusion_matrix(rf, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:31.943714Z","iopub.execute_input":"2021-05-24T10:41:31.944085Z","iopub.status.idle":"2021-05-24T10:41:32.819499Z","shell.execute_reply.started":"2021-05-24T10:41:31.944055Z","shell.execute_reply":"2021-05-24T10:41:32.818267Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ada = AdaBoostClassifier()\nada.fit(train_features, y_train)\nplot_confusion_matrix(ada, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:32.821114Z","iopub.execute_input":"2021-05-24T10:41:32.821543Z","iopub.status.idle":"2021-05-24T10:41:33.196681Z","shell.execute_reply.started":"2021-05-24T10:41:32.821497Z","shell.execute_reply":"2021-05-24T10:41:33.194575Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xgbc = XGBClassifier()\nxgbc.fit(train_features, y_train)\nplot_confusion_matrix(xgbc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:33.199619Z","iopub.execute_input":"2021-05-24T10:41:33.200121Z","iopub.status.idle":"2021-05-24T10:41:33.580055Z","shell.execute_reply.started":"2021-05-24T10:41:33.200075Z","shell.execute_reply":"2021-05-24T10:41:33.579137Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# MobileNet","metadata":{}},{"cell_type":"code","source":"base_model= MobileNet(input_shape=(224,224,3), weights='imagenet', include_top=False)\nx = base_model.output\n# x = Dropout(0.5)(x)\nx = Flatten()(x)\n# x = BatchNormalization()(x)\nx = Dense(16,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(32,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(64,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(128,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(256,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\npredictions = Dense(2, activation='softmax')(x)\n\nmodel_feat = Model(inputs=base_model.input,outputs=predictions)\n\ntrain_features = model_feat.predict(x_train)\nval_features=model_feat.predict(x_val)\ntest_features=model_feat.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:33.582559Z","iopub.execute_input":"2021-05-24T10:41:33.583005Z","iopub.status.idle":"2021-05-24T10:41:39.072037Z","shell.execute_reply.started":"2021-05-24T10:41:33.582961Z","shell.execute_reply":"2021-05-24T10:41:39.070759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.pipeline import make_pipeline\nfrom sklearn.pipeline import Pipeline\nnames = [\n        \"K Nearest Neighbour Classifier\",\n        'SVM',\n        \"Random Forest Classifier\",\n        \"AdaBoost Classifier\", \n        \"XGB Classifier\"\n         ]\nclassifiers = [\n    KNeighborsClassifier(n_neighbors = 5, algorithm='ball_tree', leaf_size=30),\n    SVC(),\n    RandomForestClassifier(max_depth=9,criterion = 'entropy'),\n    AdaBoostClassifier(),\n    XGBClassifier()\n        ]\nzipped_clf = zip(names,classifiers)\ndef classifier_summary(pipeline, X_train, y_train, X_val, y_val,X_test,y_test):\n    sentiment_fit = pipeline.fit(X_train, y_train)\n    \n    y_pred_train= sentiment_fit.predict(X_train)\n    y_pred_val = sentiment_fit.predict(X_val)\n    y_pred_test = sentiment_fit.predict(X_test)\n    \n    train_accuracy = np.round(accuracy_score(y_train, y_pred_train),4)*100\n    train_precision = np.round(precision_score(y_train, y_pred_train, average='weighted'),4)\n    train_recall = np.round(recall_score(y_train, y_pred_train, average='weighted'),4)\n    train_F1 = np.round(f1_score(y_train, y_pred_train, average='weighted'),4)\n    train_kappa =  np.round(cohen_kappa_score(y_train, y_pred_train),4)\n    \n    \n    val_accuracy = np.round(accuracy_score(y_val, y_pred_val),4)*100\n    val_precision = np.round(precision_score(y_val, y_pred_val, average='weighted'),4)\n    val_recall = np.round(recall_score(y_val, y_pred_val, average='weighted'),4)\n    val_F1 = np.round(f1_score(y_val, y_pred_val, average='weighted'),4)\n    val_kappa =  np.round(cohen_kappa_score(y_val, y_pred_val),4)\n   \n    \n    test_accuracy = np.round(accuracy_score(y_test, y_pred_test),4)*100\n    test_precision = np.round(precision_score(y_test, y_pred_test, average='weighted'),2)\n    test_recall = np.round(recall_score(y_test, y_pred_test, average='weighted'),2)\n    test_F1 = np.round(f1_score(y_test, y_pred_test, average='weighted'),2)\n    test_kappa =  np.round(cohen_kappa_score(y_test, y_pred_test),2) \n  \n    \n    \n    print()\n    print('------------------------ Train Set Metrics------------------------')\n    print()\n    print(\"Accuracy core : {}%\".format(train_accuracy))\n    \n    print('------------------------ Validation Set Metrics------------------------')\n    print()\n    print(\"Accuracy score : {}%\".format(val_accuracy))\n    print('------------------------ Test Set Metrics------------------------')\n    print()\n    print(\"Accuracy score : {}%\".format(test_accuracy))\n    print(\"F1_score : {}\".format(test_F1))\n    print(\"Kappa Score : {} \".format(test_kappa))\n    print(\"Recall score: {}\".format(test_recall))\n    print(\"Precision score : {}\".format(test_precision))\n    \n    print(\"-\"*80)\n    print()\n    \ndef classifier_comparator(X_train,y_train,X_val,y_val,X_test,y_test,classifier=zipped_clf): \n    result = []\n    for n,c in classifier:\n        checker_pipeline = Pipeline([('Classifier', c)])\n        print(\"------------------------------Fitting {} on input_data-------------------------------- \".format(n))\n        #print(c)\n        classifier_summary(checker_pipeline,X_train, y_train, X_val, y_val,X_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:39.073798Z","iopub.execute_input":"2021-05-24T10:41:39.074254Z","iopub.status.idle":"2021-05-24T10:41:39.095768Z","shell.execute_reply.started":"2021-05-24T10:41:39.074212Z","shell.execute_reply":"2021-05-24T10:41:39.094453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classifier_comparator(train_features,y_train,val_features,y_val,test_features,y_test,classifier=zipped_clf)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:39.098022Z","iopub.execute_input":"2021-05-24T10:41:39.098477Z","iopub.status.idle":"2021-05-24T10:41:40.867371Z","shell.execute_reply.started":"2021-05-24T10:41:39.098432Z","shell.execute_reply":"2021-05-24T10:41:40.863611Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y=to_categorical(y_train,2)\nval_y=to_categorical(y_val,2)\ntest_y=to_categorical(y_test,2)\ndnn_model.compile(optimizer='adam',loss='categorical_crossentropy', metrics=['accuracy'])\nhistory = dnn_model.fit(train_features, train_y,validation_data=(val_features,val_y), epochs=10)\nloss_value , accuracy = dnn_model.evaluate(train_features, train_y)\nprint('Train_accuracy is:' + str(accuracy))\nloss_value , accuracy = dnn_model.evaluate(val_features, val_y)\nprint('Validation_accuracy is := ' + str(accuracy))\nloss_value , accuracy = dnn_model.evaluate(test_features, test_y)\nprint('test_accuracy is : = ' + str(accuracy))","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:40.871784Z","iopub.execute_input":"2021-05-24T10:41:40.872104Z","iopub.status.idle":"2021-05-24T10:41:46.508712Z","shell.execute_reply.started":"2021-05-24T10:41:40.872074Z","shell.execute_reply":"2021-05-24T10:41:46.507449Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Performance Report:\")\ny_pred5=dnn_model.predict_classes(test_features)\ny_test5=[np.argmax(x) for x in test_y]\ny_pred_prb5=dnn_model.predict_proba(test_features)\ntarget=['0','1']\nfrom sklearn import metrics\nprint('Accuracy score is :', np.round(metrics.accuracy_score(y_test5, y_pred5),4))\nprint('Precision score is :', np.round(metrics.precision_score(y_test5, y_pred5, average='weighted'),4))\nprint('Recall score is :', np.round(metrics.recall_score(y_test5,y_pred5, average='weighted'),4))\nprint('F1 Score is :', np.round(metrics.f1_score(y_test5, y_pred5, average='weighted'),4))\nprint('Cohen Kappa Score:', np.round(metrics.cohen_kappa_score(y_test5, y_pred5),4))\nprint('\\t\\tClassification Report:\\n', metrics.classification_report(y_test5, y_pred5,target_names=target))","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:46.512305Z","iopub.execute_input":"2021-05-24T10:41:46.512642Z","iopub.status.idle":"2021-05-24T10:41:46.740481Z","shell.execute_reply.started":"2021-05-24T10:41:46.512612Z","shell.execute_reply":"2021-05-24T10:41:46.739446Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"knn = KNeighborsClassifier(n_neighbors = 5, algorithm='ball_tree', leaf_size=30)\nknn.fit(train_features, y_train)\nplot_confusion_matrix(knn, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:46.744198Z","iopub.execute_input":"2021-05-24T10:41:46.744504Z","iopub.status.idle":"2021-05-24T10:41:46.953872Z","shell.execute_reply.started":"2021-05-24T10:41:46.744473Z","shell.execute_reply":"2021-05-24T10:41:46.952803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"svc = SVC()\nsvc.fit(train_features, y_train)\nplot_confusion_matrix(svc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:46.957714Z","iopub.execute_input":"2021-05-24T10:41:46.958060Z","iopub.status.idle":"2021-05-24T10:41:47.381919Z","shell.execute_reply.started":"2021-05-24T10:41:46.958030Z","shell.execute_reply":"2021-05-24T10:41:47.381039Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rf = RandomForestClassifier()\nrf.fit(train_features, y_train)\nplot_confusion_matrix(rf, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:47.385943Z","iopub.execute_input":"2021-05-24T10:41:47.386285Z","iopub.status.idle":"2021-05-24T10:41:48.060870Z","shell.execute_reply.started":"2021-05-24T10:41:47.386254Z","shell.execute_reply":"2021-05-24T10:41:48.059626Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ada = AdaBoostClassifier()\nada.fit(train_features, y_train)\nplot_confusion_matrix(ada, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:48.063415Z","iopub.execute_input":"2021-05-24T10:41:48.063943Z","iopub.status.idle":"2021-05-24T10:41:48.409862Z","shell.execute_reply.started":"2021-05-24T10:41:48.063897Z","shell.execute_reply":"2021-05-24T10:41:48.408607Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xgbc = XGBClassifier()\nxgbc.fit(train_features, y_train)\nplot_confusion_matrix(xgbc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:48.412289Z","iopub.execute_input":"2021-05-24T10:41:48.412721Z","iopub.status.idle":"2021-05-24T10:41:48.796098Z","shell.execute_reply.started":"2021-05-24T10:41:48.412676Z","shell.execute_reply":"2021-05-24T10:41:48.794945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# InceptionV3","metadata":{}},{"cell_type":"code","source":"base_model= MobileNet(input_shape=(224,224,3), weights='imagenet', include_top=False)\nx = base_model.output\n# x = Dropout(0.5)(x)\nx = Flatten()(x)\n# x = BatchNormalization()(x)\nx = Dense(16,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(32,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(64,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(128,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(256,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\npredictions = Dense(2, activation='softmax')(x)\n\nmodel_feat = Model(inputs=base_model.input,outputs=predictions)\n\ntrain_features = model_feat.predict(x_train)\nval_features=model_feat.predict(x_val)\ntest_features=model_feat.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:48.797676Z","iopub.execute_input":"2021-05-24T10:41:48.798114Z","iopub.status.idle":"2021-05-24T10:41:52.637115Z","shell.execute_reply.started":"2021-05-24T10:41:48.798069Z","shell.execute_reply":"2021-05-24T10:41:52.636195Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.pipeline import make_pipeline\nfrom sklearn.pipeline import Pipeline\nnames = [\n        \"K Nearest Neighbour Classifier\",\n        'SVM',\n        \"Random Forest Classifier\",\n        \"AdaBoost Classifier\", \n        \"XGB Classifier\"\n         ]\nclassifiers = [\n    KNeighborsClassifier(n_neighbors = 5, algorithm='ball_tree', leaf_size=30),\n    SVC(),\n    RandomForestClassifier(max_depth=9,criterion = 'entropy'),\n    AdaBoostClassifier(),\n    XGBClassifier()\n        ]\nzipped_clf = zip(names,classifiers)\ndef classifier_summary(pipeline, X_train, y_train, X_val, y_val,X_test,y_test):\n    sentiment_fit = pipeline.fit(X_train, y_train)\n    \n    y_pred_train= sentiment_fit.predict(X_train)\n    y_pred_val = sentiment_fit.predict(X_val)\n    y_pred_test = sentiment_fit.predict(X_test)\n    \n    train_accuracy = np.round(accuracy_score(y_train, y_pred_train),4)*100\n    train_precision = np.round(precision_score(y_train, y_pred_train, average='weighted'),4)\n    train_recall = np.round(recall_score(y_train, y_pred_train, average='weighted'),4)\n    train_F1 = np.round(f1_score(y_train, y_pred_train, average='weighted'),4)\n    train_kappa =  np.round(cohen_kappa_score(y_train, y_pred_train),4)\n    \n    \n    val_accuracy = np.round(accuracy_score(y_val, y_pred_val),4)*100\n    val_precision = np.round(precision_score(y_val, y_pred_val, average='weighted'),4)\n    val_recall = np.round(recall_score(y_val, y_pred_val, average='weighted'),4)\n    val_F1 = np.round(f1_score(y_val, y_pred_val, average='weighted'),4)\n    val_kappa =  np.round(cohen_kappa_score(y_val, y_pred_val),4)\n   \n    \n    test_accuracy = np.round(accuracy_score(y_test, y_pred_test),4)*100\n    test_precision = np.round(precision_score(y_test, y_pred_test, average='weighted'),2)\n    test_recall = np.round(recall_score(y_test, y_pred_test, average='weighted'),2)\n    test_F1 = np.round(f1_score(y_test, y_pred_test, average='weighted'),2)\n    test_kappa =  np.round(cohen_kappa_score(y_test, y_pred_test),2) \n  \n    \n    \n    print()\n    print('------------------------ Train Set Metrics------------------------')\n    print()\n    print(\"Accuracy core : {}%\".format(train_accuracy))\n    \n    print('------------------------ Validation Set Metrics------------------------')\n    print()\n    print(\"Accuracy score : {}%\".format(val_accuracy))\n    print('------------------------ Test Set Metrics------------------------')\n    print()\n    print(\"Accuracy score : {}%\".format(test_accuracy))\n    print(\"F1_score : {}\".format(test_F1))\n    print(\"Kappa Score : {} \".format(test_kappa))\n    print(\"Recall score: {}\".format(test_recall))\n    print(\"Precision score : {}\".format(test_precision))\n    \n    print(\"-\"*80)\n    print()\n    \ndef classifier_comparator(X_train,y_train,X_val,y_val,X_test,y_test,classifier=zipped_clf): \n    result = []\n    for n,c in classifier:\n        checker_pipeline = Pipeline([('Classifier', c)])\n        print(\"------------------------------Fitting {} on input_data-------------------------------- \".format(n))\n        #print(c)\n        classifier_summary(checker_pipeline,X_train, y_train, X_val, y_val,X_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:52.638861Z","iopub.execute_input":"2021-05-24T10:41:52.639300Z","iopub.status.idle":"2021-05-24T10:41:52.661709Z","shell.execute_reply.started":"2021-05-24T10:41:52.639261Z","shell.execute_reply":"2021-05-24T10:41:52.660690Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classifier_comparator(train_features,y_train,val_features,y_val,test_features,y_test,classifier=zipped_clf)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:52.664900Z","iopub.execute_input":"2021-05-24T10:41:52.665376Z","iopub.status.idle":"2021-05-24T10:41:55.513833Z","shell.execute_reply.started":"2021-05-24T10:41:52.665345Z","shell.execute_reply":"2021-05-24T10:41:55.512871Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y=to_categorical(y_train,2)\nval_y=to_categorical(y_val,2)\ntest_y=to_categorical(y_test,2)\ndnn_model.compile(optimizer='adam',loss='categorical_crossentropy', metrics=['accuracy'])\nhistory = dnn_model.fit(train_features, train_y,validation_data=(val_features,val_y), epochs=10)\nloss_value , accuracy = dnn_model.evaluate(train_features, train_y)\nprint('Train_accuracy is:' + str(accuracy))\nloss_value , accuracy = dnn_model.evaluate(val_features, val_y)\nprint('Validation_accuracy is := ' + str(accuracy))\nloss_value , accuracy = dnn_model.evaluate(test_features, test_y)\nprint('test_accuracy is : = ' + str(accuracy))","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:41:55.526358Z","iopub.execute_input":"2021-05-24T10:41:55.526648Z","iopub.status.idle":"2021-05-24T10:42:00.928413Z","shell.execute_reply.started":"2021-05-24T10:41:55.526619Z","shell.execute_reply":"2021-05-24T10:42:00.926970Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Performance Report:\")\ny_pred6=dnn_model.predict_classes(test_features)\ny_test6=[np.argmax(x) for x in test_y]\ny_pred_prb6=dnn_model.predict_proba(test_features)\ntarget=['0','1']\nfrom sklearn import metrics\nprint('Accuracy score is :', np.round(metrics.accuracy_score(y_test6, y_pred6),4))\nprint('Precision score is :', np.round(metrics.precision_score(y_test6, y_pred6, average='weighted'),4))\nprint('Recall score is :', np.round(metrics.recall_score(y_test6,y_pred6, average='weighted'),4))\nprint('F1 Score is :', np.round(metrics.f1_score(y_test6, y_pred6, average='weighted'),4))\nprint('Cohen Kappa Score:', np.round(metrics.cohen_kappa_score(y_test6, y_pred6),4))\nprint('\\t\\tClassification Report:\\n', metrics.classification_report(y_test6, y_pred6,target_names=target))","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:42:00.930187Z","iopub.execute_input":"2021-05-24T10:42:00.930471Z","iopub.status.idle":"2021-05-24T10:42:01.164149Z","shell.execute_reply.started":"2021-05-24T10:42:00.930443Z","shell.execute_reply":"2021-05-24T10:42:01.163157Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"knn = KNeighborsClassifier(n_neighbors = 5, algorithm='ball_tree', leaf_size=30)\nknn.fit(train_features, y_train)\nplot_confusion_matrix(knn, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:42:01.165710Z","iopub.execute_input":"2021-05-24T10:42:01.166170Z","iopub.status.idle":"2021-05-24T10:42:01.378835Z","shell.execute_reply.started":"2021-05-24T10:42:01.166127Z","shell.execute_reply":"2021-05-24T10:42:01.377479Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"svc = SVC()\nsvc.fit(train_features, y_train)\nplot_confusion_matrix(svc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:42:01.381031Z","iopub.execute_input":"2021-05-24T10:42:01.381518Z","iopub.status.idle":"2021-05-24T10:42:01.841476Z","shell.execute_reply.started":"2021-05-24T10:42:01.381470Z","shell.execute_reply":"2021-05-24T10:42:01.840286Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rf = RandomForestClassifier()\nrf.fit(train_features, y_train)\nplot_confusion_matrix(rf, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:42:01.843756Z","iopub.execute_input":"2021-05-24T10:42:01.844287Z","iopub.status.idle":"2021-05-24T10:42:02.483892Z","shell.execute_reply.started":"2021-05-24T10:42:01.844242Z","shell.execute_reply":"2021-05-24T10:42:02.482302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ada = AdaBoostClassifier()\nada.fit(train_features, y_train)\nplot_confusion_matrix(ada, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:42:02.485745Z","iopub.execute_input":"2021-05-24T10:42:02.486250Z","iopub.status.idle":"2021-05-24T10:42:02.849821Z","shell.execute_reply.started":"2021-05-24T10:42:02.486203Z","shell.execute_reply":"2021-05-24T10:42:02.848188Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xgbc = XGBClassifier()\nxgbc.fit(train_features, y_train)\nplot_confusion_matrix(xgbc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:42:02.851747Z","iopub.execute_input":"2021-05-24T10:42:02.852419Z","iopub.status.idle":"2021-05-24T10:42:03.253223Z","shell.execute_reply.started":"2021-05-24T10:42:02.852367Z","shell.execute_reply":"2021-05-24T10:42:03.252167Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# InceptionResNetV2","metadata":{}},{"cell_type":"code","source":"base_model= InceptionResNetV2(input_shape=(224,224,3), weights='imagenet', include_top=False)\nx = base_model.output\n# x = Dropout(0.5)(x)\nx = Flatten()(x)\n# x = BatchNormalization()(x)\nx = Dense(16,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(32,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(64,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(128,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(256,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\npredictions = Dense(2, activation='softmax')(x)\n\nmodel_feat = Model(inputs=base_model.input,outputs=predictions)\n\ntrain_features = model_feat.predict(x_train)\nval_features=model_feat.predict(x_val)\ntest_features=model_feat.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:42:03.254858Z","iopub.execute_input":"2021-05-24T10:42:03.255400Z","iopub.status.idle":"2021-05-24T10:42:31.302478Z","shell.execute_reply.started":"2021-05-24T10:42:03.255358Z","shell.execute_reply":"2021-05-24T10:42:31.301461Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.pipeline import make_pipeline\nfrom sklearn.pipeline import Pipeline\nnames = [\n        \"K Nearest Neighbour Classifier\",\n        'SVM',\n        \"Random Forest Classifier\",\n        \"AdaBoost Classifier\", \n        \"XGB Classifier\"\n         ]\nclassifiers = [\n    KNeighborsClassifier(n_neighbors = 5, algorithm='ball_tree', leaf_size=30),\n    SVC(),\n    RandomForestClassifier(max_depth=9,criterion = 'entropy'),\n    AdaBoostClassifier(),\n    XGBClassifier()\n        ]\nzipped_clf = zip(names,classifiers)\ndef classifier_summary(pipeline, X_train, y_train, X_val, y_val,X_test,y_test):\n    sentiment_fit = pipeline.fit(X_train, y_train)\n    \n    y_pred_train= sentiment_fit.predict(X_train)\n    y_pred_val = sentiment_fit.predict(X_val)\n    y_pred_test = sentiment_fit.predict(X_test)\n    \n    train_accuracy = np.round(accuracy_score(y_train, y_pred_train),4)*100\n    train_precision = np.round(precision_score(y_train, y_pred_train, average='weighted'),4)\n    train_recall = np.round(recall_score(y_train, y_pred_train, average='weighted'),4)\n    train_F1 = np.round(f1_score(y_train, y_pred_train, average='weighted'),4)\n    train_kappa =  np.round(cohen_kappa_score(y_train, y_pred_train),4)\n    \n    \n    val_accuracy = np.round(accuracy_score(y_val, y_pred_val),4)*100\n    val_precision = np.round(precision_score(y_val, y_pred_val, average='weighted'),4)\n    val_recall = np.round(recall_score(y_val, y_pred_val, average='weighted'),4)\n    val_F1 = np.round(f1_score(y_val, y_pred_val, average='weighted'),4)\n    val_kappa =  np.round(cohen_kappa_score(y_val, y_pred_val),4)\n   \n    \n    test_accuracy = np.round(accuracy_score(y_test, y_pred_test),4)*100\n    test_precision = np.round(precision_score(y_test, y_pred_test, average='weighted'),2)\n    test_recall = np.round(recall_score(y_test, y_pred_test, average='weighted'),2)\n    test_F1 = np.round(f1_score(y_test, y_pred_test, average='weighted'),2)\n    test_kappa =  np.round(cohen_kappa_score(y_test, y_pred_test),2) \n  \n    \n    \n    print()\n    print('------------------------ Train Set Metrics------------------------')\n    print()\n    print(\"Accuracy core : {}%\".format(train_accuracy))\n    \n    print('------------------------ Validation Set Metrics------------------------')\n    print()\n    print(\"Accuracy score : {}%\".format(val_accuracy))\n    print('------------------------ Test Set Metrics------------------------')\n    print()\n    print(\"Accuracy score : {}%\".format(test_accuracy))\n    print(\"F1_score : {}\".format(test_F1))\n    print(\"Kappa Score : {} \".format(test_kappa))\n    print(\"Recall score: {}\".format(test_recall))\n    print(\"Precision score : {}\".format(test_precision))\n    \n    print(\"-\"*80)\n    print()\n    \ndef classifier_comparator(X_train,y_train,X_val,y_val,X_test,y_test,classifier=zipped_clf): \n    result = []\n    for n,c in classifier:\n        checker_pipeline = Pipeline([('Classifier', c)])\n        print(\"------------------------------Fitting {} on input_data-------------------------------- \".format(n))\n        #print(c)\n        classifier_summary(checker_pipeline,X_train, y_train, X_val, y_val,X_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:42:31.304704Z","iopub.execute_input":"2021-05-24T10:42:31.305638Z","iopub.status.idle":"2021-05-24T10:42:31.325710Z","shell.execute_reply.started":"2021-05-24T10:42:31.305592Z","shell.execute_reply":"2021-05-24T10:42:31.324422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classifier_comparator(train_features,y_train,val_features,y_val,test_features,y_test,classifier=zipped_clf)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:42:31.327866Z","iopub.execute_input":"2021-05-24T10:42:31.328301Z","iopub.status.idle":"2021-05-24T10:42:33.068841Z","shell.execute_reply.started":"2021-05-24T10:42:31.328271Z","shell.execute_reply":"2021-05-24T10:42:33.067744Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y=to_categorical(y_train,2)\nval_y=to_categorical(y_val,2)\ntest_y=to_categorical(y_test,2)\ndnn_model.compile(optimizer='adam',loss='categorical_crossentropy', metrics=['accuracy'])\nhistory = dnn_model.fit(train_features, train_y,validation_data=(val_features,val_y), epochs=10)\nloss_value , accuracy = dnn_model.evaluate(train_features, train_y)\nprint('Train_accuracy is:' + str(accuracy))\nloss_value , accuracy = dnn_model.evaluate(val_features, val_y)\nprint('Validation_accuracy is := ' + str(accuracy))\nloss_value , accuracy = dnn_model.evaluate(test_features, test_y)\nprint('test_accuracy is : = ' + str(accuracy))","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:42:33.070531Z","iopub.execute_input":"2021-05-24T10:42:33.070964Z","iopub.status.idle":"2021-05-24T10:42:38.837683Z","shell.execute_reply.started":"2021-05-24T10:42:33.070912Z","shell.execute_reply":"2021-05-24T10:42:38.836437Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Performance Report:\")\ny_pred7=dnn_model.predict_classes(test_features)\ny_test7=[np.argmax(x) for x in test_y]\ny_pred_prb7=dnn_model.predict_proba(test_features)\ntarget=['0','1']\nfrom sklearn import metrics\nprint('Accuracy score is :', np.round(metrics.accuracy_score(y_test7, y_pred7),4))\nprint('Precision score is :', np.round(metrics.precision_score(y_test7, y_pred7, average='weighted'),4))\nprint('Recall score is :', np.round(metrics.recall_score(y_test7,y_pred7, average='weighted'),4))\nprint('F1 Score is :', np.round(metrics.f1_score(y_test7, y_pred7, average='weighted'),4))\nprint('Cohen Kappa Score:', np.round(metrics.cohen_kappa_score(y_test7, y_pred7),4))\nprint('\\t\\tClassification Report:\\n', metrics.classification_report(y_test7, y_pred7,target_names=target))","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:42:38.840799Z","iopub.execute_input":"2021-05-24T10:42:38.841252Z","iopub.status.idle":"2021-05-24T10:42:39.066911Z","shell.execute_reply.started":"2021-05-24T10:42:38.841220Z","shell.execute_reply":"2021-05-24T10:42:39.065900Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"knn = KNeighborsClassifier(n_neighbors = 5, algorithm='ball_tree', leaf_size=30)\nknn.fit(train_features, y_train)\nplot_confusion_matrix(knn, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:42:39.070510Z","iopub.execute_input":"2021-05-24T10:42:39.070838Z","iopub.status.idle":"2021-05-24T10:42:39.300631Z","shell.execute_reply.started":"2021-05-24T10:42:39.070807Z","shell.execute_reply":"2021-05-24T10:42:39.299244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"svc = SVC()\nsvc.fit(train_features, y_train)\nplot_confusion_matrix(svc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:42:39.302845Z","iopub.execute_input":"2021-05-24T10:42:39.303481Z","iopub.status.idle":"2021-05-24T10:42:39.661383Z","shell.execute_reply.started":"2021-05-24T10:42:39.303434Z","shell.execute_reply":"2021-05-24T10:42:39.660150Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rf = RandomForestClassifier()\nrf.fit(train_features, y_train)\nplot_confusion_matrix(rf, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:42:39.663714Z","iopub.execute_input":"2021-05-24T10:42:39.664345Z","iopub.status.idle":"2021-05-24T10:42:40.097564Z","shell.execute_reply.started":"2021-05-24T10:42:39.664300Z","shell.execute_reply":"2021-05-24T10:42:40.095963Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ada = AdaBoostClassifier()\nada.fit(train_features, y_train)\nplot_confusion_matrix(ada, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:42:40.099657Z","iopub.execute_input":"2021-05-24T10:42:40.100113Z","iopub.status.idle":"2021-05-24T10:42:40.789270Z","shell.execute_reply.started":"2021-05-24T10:42:40.100069Z","shell.execute_reply":"2021-05-24T10:42:40.787896Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xgbc = XGBClassifier()\nxgbc.fit(train_features, y_train)\nplot_confusion_matrix(xgbc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:42:40.791201Z","iopub.execute_input":"2021-05-24T10:42:40.791616Z","iopub.status.idle":"2021-05-24T10:42:41.041988Z","shell.execute_reply.started":"2021-05-24T10:42:40.791573Z","shell.execute_reply":"2021-05-24T10:42:41.041060Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# DenseNet169","metadata":{}},{"cell_type":"code","source":"base_model= InceptionResNetV2(input_shape=(224,224,3), weights='imagenet', include_top=False)\nx = base_model.output\n# x = Dropout(0.5)(x)\nx = Flatten()(x)\n# x = BatchNormalization()(x)\nx = Dense(16,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(32,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(64,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(128,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(256,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\npredictions = Dense(2, activation='softmax')(x)\n\nmodel_feat = Model(inputs=base_model.input,outputs=predictions)\n\ntrain_features = model_feat.predict(x_train)\nval_features=model_feat.predict(x_val)\ntest_features=model_feat.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:42:41.043704Z","iopub.execute_input":"2021-05-24T10:42:41.044101Z","iopub.status.idle":"2021-05-24T10:43:03.382721Z","shell.execute_reply.started":"2021-05-24T10:42:41.044072Z","shell.execute_reply":"2021-05-24T10:43:03.381459Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.pipeline import make_pipeline\nfrom sklearn.pipeline import Pipeline\nnames = [\n        \"K Nearest Neighbour Classifier\",\n        'SVM',\n        \"Random Forest Classifier\",\n        \"AdaBoost Classifier\", \n        \"XGB Classifier\"\n         ]\nclassifiers = [\n    KNeighborsClassifier(n_neighbors = 5, algorithm='ball_tree', leaf_size=30),\n    SVC(),\n    RandomForestClassifier(max_depth=9,criterion = 'entropy'),\n    AdaBoostClassifier(),\n    XGBClassifier()\n        ]\nzipped_clf = zip(names,classifiers)\ndef classifier_summary(pipeline, X_train, y_train, X_val, y_val,X_test,y_test):\n    sentiment_fit = pipeline.fit(X_train, y_train)\n    \n    y_pred_train= sentiment_fit.predict(X_train)\n    y_pred_val = sentiment_fit.predict(X_val)\n    y_pred_test = sentiment_fit.predict(X_test)\n    \n    train_accuracy = np.round(accuracy_score(y_train, y_pred_train),4)*100\n    train_precision = np.round(precision_score(y_train, y_pred_train, average='weighted'),4)\n    train_recall = np.round(recall_score(y_train, y_pred_train, average='weighted'),4)\n    train_F1 = np.round(f1_score(y_train, y_pred_train, average='weighted'),4)\n    train_kappa =  np.round(cohen_kappa_score(y_train, y_pred_train),4)\n    \n    \n    val_accuracy = np.round(accuracy_score(y_val, y_pred_val),4)*100\n    val_precision = np.round(precision_score(y_val, y_pred_val, average='weighted'),4)\n    val_recall = np.round(recall_score(y_val, y_pred_val, average='weighted'),4)\n    val_F1 = np.round(f1_score(y_val, y_pred_val, average='weighted'),4)\n    val_kappa =  np.round(cohen_kappa_score(y_val, y_pred_val),4)\n   \n    \n    test_accuracy = np.round(accuracy_score(y_test, y_pred_test),4)*100\n    test_precision = np.round(precision_score(y_test, y_pred_test, average='weighted'),2)\n    test_recall = np.round(recall_score(y_test, y_pred_test, average='weighted'),2)\n    test_F1 = np.round(f1_score(y_test, y_pred_test, average='weighted'),2)\n    test_kappa =  np.round(cohen_kappa_score(y_test, y_pred_test),2) \n  \n    \n    \n    print()\n    print('------------------------ Train Set Metrics------------------------')\n    print()\n    print(\"Accuracy core : {}%\".format(train_accuracy))\n    \n    print('------------------------ Validation Set Metrics------------------------')\n    print()\n    print(\"Accuracy score : {}%\".format(val_accuracy))\n    print('------------------------ Test Set Metrics------------------------')\n    print()\n    print(\"Accuracy score : {}%\".format(test_accuracy))\n    print(\"F1_score : {}\".format(test_F1))\n    print(\"Kappa Score : {} \".format(test_kappa))\n    print(\"Recall score: {}\".format(test_recall))\n    print(\"Precision score : {}\".format(test_precision))\n    \n    print(\"-\"*80)\n    print()\n    \ndef classifier_comparator(X_train,y_train,X_val,y_val,X_test,y_test,classifier=zipped_clf): \n    result = []\n    for n,c in classifier:\n        checker_pipeline = Pipeline([('Classifier', c)])\n        print(\"------------------------------Fitting {} on input_data-------------------------------- \".format(n))\n        #print(c)\n        classifier_summary(checker_pipeline,X_train, y_train, X_val, y_val,X_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:43:03.388924Z","iopub.execute_input":"2021-05-24T10:43:03.392064Z","iopub.status.idle":"2021-05-24T10:43:03.421846Z","shell.execute_reply.started":"2021-05-24T10:43:03.391998Z","shell.execute_reply":"2021-05-24T10:43:03.420589Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classifier_comparator(train_features,y_train,val_features,y_val,test_features,y_test,classifier=zipped_clf)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:43:03.428299Z","iopub.execute_input":"2021-05-24T10:43:03.431724Z","iopub.status.idle":"2021-05-24T10:43:05.252049Z","shell.execute_reply.started":"2021-05-24T10:43:03.431678Z","shell.execute_reply":"2021-05-24T10:43:05.249994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y=to_categorical(y_train,2)\nval_y=to_categorical(y_val,2)\ntest_y=to_categorical(y_test,2)\ndnn_model.compile(optimizer='adam',loss='categorical_crossentropy', metrics=['accuracy'])\nhistory = dnn_model.fit(train_features, train_y,validation_data=(val_features,val_y), epochs=10)\nloss_value , accuracy = dnn_model.evaluate(train_features, train_y)\nprint('Train_accuracy is:' + str(accuracy))\nloss_value , accuracy = dnn_model.evaluate(val_features, val_y)\nprint('Validation_accuracy is := ' + str(accuracy))\nloss_value , accuracy = dnn_model.evaluate(test_features, test_y)\nprint('test_accuracy is : = ' + str(accuracy))","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:43:05.253589Z","iopub.execute_input":"2021-05-24T10:43:05.254132Z","iopub.status.idle":"2021-05-24T10:43:10.686447Z","shell.execute_reply.started":"2021-05-24T10:43:05.254057Z","shell.execute_reply":"2021-05-24T10:43:10.684173Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Performance Report:\")\ny_pred8=dnn_model.predict_classes(test_features)\ny_test8=[np.argmax(x) for x in test_y]\ny_pred_prb8=dnn_model.predict_proba(test_features)\ntarget=['0','1']\nfrom sklearn import metrics\nprint('Accuracy score is :', np.round(metrics.accuracy_score(y_test8, y_pred8),4))\nprint('Precision score is :', np.round(metrics.precision_score(y_test8, y_pred8, average='weighted'),4))\nprint('Recall score is :', np.round(metrics.recall_score(y_test8,y_pred8, average='weighted'),4))\nprint('F1 Score is :', np.round(metrics.f1_score(y_test8, y_pred8, average='weighted'),4))\nprint('Cohen Kappa Score:', np.round(metrics.cohen_kappa_score(y_test8, y_pred8),4))\nprint('\\t\\tClassification Report:\\n', metrics.classification_report(y_test8, y_pred8,target_names=target))","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:43:10.688279Z","iopub.execute_input":"2021-05-24T10:43:10.688808Z","iopub.status.idle":"2021-05-24T10:43:10.912685Z","shell.execute_reply.started":"2021-05-24T10:43:10.688749Z","shell.execute_reply":"2021-05-24T10:43:10.911728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"knn = KNeighborsClassifier(n_neighbors = 5, algorithm='ball_tree', leaf_size=30)\nknn.fit(train_features, y_train)\nplot_confusion_matrix(knn, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:43:10.916429Z","iopub.execute_input":"2021-05-24T10:43:10.916745Z","iopub.status.idle":"2021-05-24T10:43:11.260467Z","shell.execute_reply.started":"2021-05-24T10:43:10.916711Z","shell.execute_reply":"2021-05-24T10:43:11.258648Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"svc = SVC()\nsvc.fit(train_features, y_train)\nplot_confusion_matrix(svc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:43:11.262531Z","iopub.execute_input":"2021-05-24T10:43:11.263008Z","iopub.status.idle":"2021-05-24T10:43:11.798111Z","shell.execute_reply.started":"2021-05-24T10:43:11.262962Z","shell.execute_reply":"2021-05-24T10:43:11.797079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rf = RandomForestClassifier()\nrf.fit(train_features, y_train)\nplot_confusion_matrix(rf, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:43:11.801837Z","iopub.execute_input":"2021-05-24T10:43:11.802164Z","iopub.status.idle":"2021-05-24T10:43:12.237635Z","shell.execute_reply.started":"2021-05-24T10:43:11.802134Z","shell.execute_reply":"2021-05-24T10:43:12.236245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ada = AdaBoostClassifier()\nada.fit(train_features, y_train)\nplot_confusion_matrix(ada, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:43:12.240154Z","iopub.execute_input":"2021-05-24T10:43:12.240617Z","iopub.status.idle":"2021-05-24T10:43:12.935168Z","shell.execute_reply.started":"2021-05-24T10:43:12.240557Z","shell.execute_reply":"2021-05-24T10:43:12.933955Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xgbc = XGBClassifier()\nxgbc.fit(train_features, y_train)\nplot_confusion_matrix(xgbc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:43:12.938945Z","iopub.execute_input":"2021-05-24T10:43:12.939289Z","iopub.status.idle":"2021-05-24T10:43:13.219728Z","shell.execute_reply.started":"2021-05-24T10:43:12.939257Z","shell.execute_reply":"2021-05-24T10:43:13.218680Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# DenseNet121","metadata":{}},{"cell_type":"code","source":"base_model= InceptionResNetV2(input_shape=(224,224,3), weights='imagenet', include_top=False)\nx = base_model.output\n# x = Dropout(0.5)(x)\nx = Flatten()(x)\n# x = BatchNormalization()(x)\nx = Dense(16,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(32,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(64,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(128,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(256,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\npredictions = Dense(2, activation='softmax')(x)\n\nmodel_feat = Model(inputs=base_model.input,outputs=predictions)\n\ntrain_features = model_feat.predict(x_train)\nval_features=model_feat.predict(x_val)\ntest_features=model_feat.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:43:13.221439Z","iopub.execute_input":"2021-05-24T10:43:13.221836Z","iopub.status.idle":"2021-05-24T10:43:34.711284Z","shell.execute_reply.started":"2021-05-24T10:43:13.221793Z","shell.execute_reply":"2021-05-24T10:43:34.710193Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.pipeline import make_pipeline\nfrom sklearn.pipeline import Pipeline\nnames = [\n        \"K Nearest Neighbour Classifier\",\n        'SVM',\n        \"Random Forest Classifier\",\n        \"AdaBoost Classifier\", \n        \"XGB Classifier\"\n         ]\nclassifiers = [\n    KNeighborsClassifier(n_neighbors = 5, algorithm='ball_tree', leaf_size=30),\n    SVC(),\n    RandomForestClassifier(max_depth=9,criterion = 'entropy'),\n    AdaBoostClassifier(),\n    XGBClassifier()\n        ]\nzipped_clf = zip(names,classifiers)\ndef classifier_summary(pipeline, X_train, y_train, X_val, y_val,X_test,y_test):\n    sentiment_fit = pipeline.fit(X_train, y_train)\n    \n    y_pred_train= sentiment_fit.predict(X_train)\n    y_pred_val = sentiment_fit.predict(X_val)\n    y_pred_test = sentiment_fit.predict(X_test)\n    \n    train_accuracy = np.round(accuracy_score(y_train, y_pred_train),4)*100\n    train_precision = np.round(precision_score(y_train, y_pred_train, average='weighted'),4)\n    train_recall = np.round(recall_score(y_train, y_pred_train, average='weighted'),4)\n    train_F1 = np.round(f1_score(y_train, y_pred_train, average='weighted'),4)\n    train_kappa =  np.round(cohen_kappa_score(y_train, y_pred_train),4)\n    \n    \n    val_accuracy = np.round(accuracy_score(y_val, y_pred_val),4)*100\n    val_precision = np.round(precision_score(y_val, y_pred_val, average='weighted'),4)\n    val_recall = np.round(recall_score(y_val, y_pred_val, average='weighted'),4)\n    val_F1 = np.round(f1_score(y_val, y_pred_val, average='weighted'),4)\n    val_kappa =  np.round(cohen_kappa_score(y_val, y_pred_val),4)\n   \n    \n    test_accuracy = np.round(accuracy_score(y_test, y_pred_test),4)*100\n    test_precision = np.round(precision_score(y_test, y_pred_test, average='weighted'),2)\n    test_recall = np.round(recall_score(y_test, y_pred_test, average='weighted'),2)\n    test_F1 = np.round(f1_score(y_test, y_pred_test, average='weighted'),2)\n    test_kappa =  np.round(cohen_kappa_score(y_test, y_pred_test),2) \n  \n    \n    \n    print()\n    print('------------------------ Train Set Metrics------------------------')\n    print()\n    print(\"Accuracy core : {}%\".format(train_accuracy))\n    \n    print('------------------------ Validation Set Metrics------------------------')\n    print()\n    print(\"Accuracy score : {}%\".format(val_accuracy))\n    print('------------------------ Test Set Metrics------------------------')\n    print()\n    print(\"Accuracy score : {}%\".format(test_accuracy))\n    print(\"F1_score : {}\".format(test_F1))\n    print(\"Kappa Score : {} \".format(test_kappa))\n    print(\"Recall score: {}\".format(test_recall))\n    print(\"Precision score : {}\".format(test_precision))\n    \n    print(\"-\"*80)\n    print()\n    \ndef classifier_comparator(X_train,y_train,X_val,y_val,X_test,y_test,classifier=zipped_clf): \n    result = []\n    for n,c in classifier:\n        checker_pipeline = Pipeline([('Classifier', c)])\n        print(\"------------------------------Fitting {} on input_data-------------------------------- \".format(n))\n        #print(c)\n        classifier_summary(checker_pipeline,X_train, y_train, X_val, y_val,X_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:43:34.713112Z","iopub.execute_input":"2021-05-24T10:43:34.713512Z","iopub.status.idle":"2021-05-24T10:43:34.736680Z","shell.execute_reply.started":"2021-05-24T10:43:34.713459Z","shell.execute_reply":"2021-05-24T10:43:34.734882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classifier_comparator(train_features,y_train,val_features,y_val,test_features,y_test,classifier=zipped_clf)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:43:34.738568Z","iopub.execute_input":"2021-05-24T10:43:34.739340Z","iopub.status.idle":"2021-05-24T10:43:36.479399Z","shell.execute_reply.started":"2021-05-24T10:43:34.739296Z","shell.execute_reply":"2021-05-24T10:43:36.478206Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y=to_categorical(y_train,2)\nval_y=to_categorical(y_val,2)\ntest_y=to_categorical(y_test,2)\ndnn_model.compile(optimizer='adam',loss='categorical_crossentropy', metrics=['accuracy'])\nhistory = dnn_model.fit(train_features, train_y,validation_data=(val_features,val_y), epochs=10)\nloss_value , accuracy = dnn_model.evaluate(train_features, train_y)\nprint('Train_accuracy is:' + str(accuracy))\nloss_value , accuracy = dnn_model.evaluate(val_features, val_y)\nprint('Validation_accuracy is := ' + str(accuracy))\nloss_value , accuracy = dnn_model.evaluate(test_features, test_y)\nprint('test_accuracy is : = ' + str(accuracy))","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:43:36.480836Z","iopub.execute_input":"2021-05-24T10:43:36.481246Z","iopub.status.idle":"2021-05-24T10:43:42.461452Z","shell.execute_reply.started":"2021-05-24T10:43:36.481205Z","shell.execute_reply":"2021-05-24T10:43:42.459930Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Performance Report:\")\ny_pred9=dnn_model.predict_classes(test_features)\ny_test9=[np.argmax(x) for x in test_y]\ny_pred_prb9=dnn_model.predict_proba(test_features)\ntarget=['0','1']\nfrom sklearn import metrics\nprint('Accuracy score is :', np.round(metrics.accuracy_score(y_test9, y_pred9),4))\nprint('Precision score is :', np.round(metrics.precision_score(y_test9, y_pred9, average='weighted'),4))\nprint('Recall score is :', np.round(metrics.recall_score(y_test9,y_pred9, average='weighted'),4))\nprint('F1 Score is :', np.round(metrics.f1_score(y_test9, y_pred9, average='weighted'),4))\nprint('Cohen Kappa Score:', np.round(metrics.cohen_kappa_score(y_test9, y_pred9),4))\nprint('\\t\\tClassification Report:\\n', metrics.classification_report(y_test9, y_pred9,target_names=target))","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:43:42.463182Z","iopub.execute_input":"2021-05-24T10:43:42.463596Z","iopub.status.idle":"2021-05-24T10:43:42.696741Z","shell.execute_reply.started":"2021-05-24T10:43:42.463566Z","shell.execute_reply":"2021-05-24T10:43:42.694359Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"knn = KNeighborsClassifier(n_neighbors = 5, algorithm='ball_tree', leaf_size=30)\nknn.fit(train_features, y_train)\nplot_confusion_matrix(knn, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:43:42.698214Z","iopub.execute_input":"2021-05-24T10:43:42.698748Z","iopub.status.idle":"2021-05-24T10:43:42.909448Z","shell.execute_reply.started":"2021-05-24T10:43:42.698675Z","shell.execute_reply":"2021-05-24T10:43:42.908119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"svc = SVC()\nsvc.fit(train_features, y_train)\nplot_confusion_matrix(svc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:43:42.911354Z","iopub.execute_input":"2021-05-24T10:43:42.911793Z","iopub.status.idle":"2021-05-24T10:43:43.311338Z","shell.execute_reply.started":"2021-05-24T10:43:42.911750Z","shell.execute_reply":"2021-05-24T10:43:43.310388Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rf = RandomForestClassifier()\nrf.fit(train_features, y_train)\nplot_confusion_matrix(rf, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:43:43.313880Z","iopub.execute_input":"2021-05-24T10:43:43.314287Z","iopub.status.idle":"2021-05-24T10:43:43.762046Z","shell.execute_reply.started":"2021-05-24T10:43:43.314247Z","shell.execute_reply":"2021-05-24T10:43:43.760859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ada = AdaBoostClassifier()\nada.fit(train_features, y_train)\nplot_confusion_matrix(ada, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:43:43.763894Z","iopub.execute_input":"2021-05-24T10:43:43.764406Z","iopub.status.idle":"2021-05-24T10:43:44.754807Z","shell.execute_reply.started":"2021-05-24T10:43:43.764359Z","shell.execute_reply":"2021-05-24T10:43:44.753828Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xgbc = XGBClassifier()\nxgbc.fit(train_features, y_train)\nplot_confusion_matrix(xgbc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:43:44.756470Z","iopub.execute_input":"2021-05-24T10:43:44.756855Z","iopub.status.idle":"2021-05-24T10:43:45.062205Z","shell.execute_reply.started":"2021-05-24T10:43:44.756826Z","shell.execute_reply":"2021-05-24T10:43:45.060658Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# XceptionNet","metadata":{}},{"cell_type":"code","source":"base_model= InceptionResNetV2(input_shape=(224,224,3), weights='imagenet', include_top=False)\nx = base_model.output\n# x = Dropout(0.5)(x)\nx = Flatten()(x)\n# x = BatchNormalization()(x)\nx = Dense(16,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(32,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(64,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(128,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\nx = Dense(256,kernel_initializer='he_uniform')(x)\n# x = BatchNormalization()(x)\nx = Activation('relu')(x)\n# x = Dropout(0.5)(x)\npredictions = Dense(2, activation='softmax')(x)\n\nmodel_feat = Model(inputs=base_model.input,outputs=predictions)\n\ntrain_features = model_feat.predict(x_train)\nval_features=model_feat.predict(x_val)\ntest_features=model_feat.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:43:45.063935Z","iopub.execute_input":"2021-05-24T10:43:45.064390Z","iopub.status.idle":"2021-05-24T10:44:07.802286Z","shell.execute_reply.started":"2021-05-24T10:43:45.064328Z","shell.execute_reply":"2021-05-24T10:44:07.801321Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.pipeline import make_pipeline\nfrom sklearn.pipeline import Pipeline\nnames = [\n        \"K Nearest Neighbour Classifier\",\n        'SVM',\n        \"Random Forest Classifier\",\n        \"AdaBoost Classifier\", \n        \"XGB Classifier\"\n         ]\nclassifiers = [\n    KNeighborsClassifier(n_neighbors = 5, algorithm='ball_tree', leaf_size=30),\n    SVC(),\n    RandomForestClassifier(max_depth=9,criterion = 'entropy'),\n    AdaBoostClassifier(),\n    XGBClassifier()\n        ]\nzipped_clf = zip(names,classifiers)\ndef classifier_summary(pipeline, X_train, y_train, X_val, y_val,X_test,y_test):\n    sentiment_fit = pipeline.fit(X_train, y_train)\n    \n    y_pred_train= sentiment_fit.predict(X_train)\n    y_pred_val = sentiment_fit.predict(X_val)\n    y_pred_test = sentiment_fit.predict(X_test)\n    \n    train_accuracy = np.round(accuracy_score(y_train, y_pred_train),4)*100\n    train_precision = np.round(precision_score(y_train, y_pred_train, average='weighted'),4)\n    train_recall = np.round(recall_score(y_train, y_pred_train, average='weighted'),4)\n    train_F1 = np.round(f1_score(y_train, y_pred_train, average='weighted'),4)\n    train_kappa =  np.round(cohen_kappa_score(y_train, y_pred_train),4)\n    \n    \n    val_accuracy = np.round(accuracy_score(y_val, y_pred_val),4)*100\n    val_precision = np.round(precision_score(y_val, y_pred_val, average='weighted'),4)\n    val_recall = np.round(recall_score(y_val, y_pred_val, average='weighted'),4)\n    val_F1 = np.round(f1_score(y_val, y_pred_val, average='weighted'),4)\n    val_kappa =  np.round(cohen_kappa_score(y_val, y_pred_val),4)\n   \n    \n    test_accuracy = np.round(accuracy_score(y_test, y_pred_test),4)*100\n    test_precision = np.round(precision_score(y_test, y_pred_test, average='weighted'),2)\n    test_recall = np.round(recall_score(y_test, y_pred_test, average='weighted'),2)\n    test_F1 = np.round(f1_score(y_test, y_pred_test, average='weighted'),2)\n    test_kappa =  np.round(cohen_kappa_score(y_test, y_pred_test),2) \n  \n    \n    \n    print()\n    print('------------------------ Train Set Metrics------------------------')\n    print()\n    print(\"Accuracy core : {}%\".format(train_accuracy))\n    \n    print('------------------------ Validation Set Metrics------------------------')\n    print()\n    print(\"Accuracy score : {}%\".format(val_accuracy))\n    print('------------------------ Test Set Metrics------------------------')\n    print()\n    print(\"Accuracy score : {}%\".format(test_accuracy))\n    print(\"F1_score : {}\".format(test_F1))\n    print(\"Kappa Score : {} \".format(test_kappa))\n    print(\"Recall score: {}\".format(test_recall))\n    print(\"Precision score : {}\".format(test_precision))\n    \n    print(\"-\"*80)\n    print()\n    \ndef classifier_comparator(X_train,y_train,X_val,y_val,X_test,y_test,classifier=zipped_clf): \n    result = []\n    for n,c in classifier:\n        checker_pipeline = Pipeline([('Classifier', c)])\n        print(\"------------------------------Fitting {} on input_data-------------------------------- \".format(n))\n        #print(c)\n        classifier_summary(checker_pipeline,X_train, y_train, X_val, y_val,X_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:44:07.804099Z","iopub.execute_input":"2021-05-24T10:44:07.804526Z","iopub.status.idle":"2021-05-24T10:44:07.825108Z","shell.execute_reply.started":"2021-05-24T10:44:07.804480Z","shell.execute_reply":"2021-05-24T10:44:07.823637Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classifier_comparator(train_features,y_train,val_features,y_val,test_features,y_test,classifier=zipped_clf)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:44:07.827164Z","iopub.execute_input":"2021-05-24T10:44:07.827945Z","iopub.status.idle":"2021-05-24T10:44:10.484239Z","shell.execute_reply.started":"2021-05-24T10:44:07.827900Z","shell.execute_reply":"2021-05-24T10:44:10.483069Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y=to_categorical(y_train,2)\nval_y=to_categorical(y_val,2)\ntest_y=to_categorical(y_test,2)\ndnn_model.compile(optimizer='adam',loss='categorical_crossentropy', metrics=['accuracy'])\nhistory = dnn_model.fit(train_features, train_y,validation_data=(val_features,val_y), epochs=10)\nloss_value , accuracy = dnn_model.evaluate(train_features, train_y)\nprint('Train_accuracy is:' + str(accuracy))\nloss_value , accuracy = dnn_model.evaluate(val_features, val_y)\nprint('Validation_accuracy is := ' + str(accuracy))\nloss_value , accuracy = dnn_model.evaluate(test_features, test_y)\nprint('test_accuracy is : = ' + str(accuracy))","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:44:10.487929Z","iopub.execute_input":"2021-05-24T10:44:10.488263Z","iopub.status.idle":"2021-05-24T10:44:15.908848Z","shell.execute_reply.started":"2021-05-24T10:44:10.488233Z","shell.execute_reply":"2021-05-24T10:44:15.907231Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Performance Report:\")\ny_pred9=dnn_model.predict_classes(test_features)\ny_test9=[np.argmax(x) for x in test_y]\ny_pred_prb9=dnn_model.predict_proba(test_features)\ntarget=['0','1']\nfrom sklearn import metrics\nprint('Accuracy score is :', np.round(metrics.accuracy_score(y_test9, y_pred9),4))\nprint('Precision score is :', np.round(metrics.precision_score(y_test9, y_pred9, average='weighted'),4))\nprint('Recall score is :', np.round(metrics.recall_score(y_test9,y_pred9, average='weighted'),4))\nprint('F1 Score is :', np.round(metrics.f1_score(y_test9, y_pred9, average='weighted'),4))\nprint('Cohen Kappa Score:', np.round(metrics.cohen_kappa_score(y_test9, y_pred9),4))\nprint('\\t\\tClassification Report:\\n', metrics.classification_report(y_test9, y_pred9,target_names=target))","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:44:15.910901Z","iopub.execute_input":"2021-05-24T10:44:15.911358Z","iopub.status.idle":"2021-05-24T10:44:16.147054Z","shell.execute_reply.started":"2021-05-24T10:44:15.911315Z","shell.execute_reply":"2021-05-24T10:44:16.146088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"knn = KNeighborsClassifier(n_neighbors = 5, algorithm='ball_tree', leaf_size=30)\nknn.fit(train_features, y_train)\nplot_confusion_matrix(knn, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:44:16.150780Z","iopub.execute_input":"2021-05-24T10:44:16.151128Z","iopub.status.idle":"2021-05-24T10:44:16.379308Z","shell.execute_reply.started":"2021-05-24T10:44:16.151099Z","shell.execute_reply":"2021-05-24T10:44:16.378453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"svc = SVC()\nsvc.fit(train_features, y_train)\nplot_confusion_matrix(svc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:44:16.382415Z","iopub.execute_input":"2021-05-24T10:44:16.382848Z","iopub.status.idle":"2021-05-24T10:44:16.734433Z","shell.execute_reply.started":"2021-05-24T10:44:16.382805Z","shell.execute_reply":"2021-05-24T10:44:16.733069Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rf = RandomForestClassifier()\nrf.fit(train_features, y_train)\nplot_confusion_matrix(rf, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:44:16.736282Z","iopub.execute_input":"2021-05-24T10:44:16.736914Z","iopub.status.idle":"2021-05-24T10:44:17.296440Z","shell.execute_reply.started":"2021-05-24T10:44:16.736868Z","shell.execute_reply":"2021-05-24T10:44:17.295215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ada = AdaBoostClassifier()\nada.fit(train_features, y_train)\nplot_confusion_matrix(ada, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:44:17.298099Z","iopub.execute_input":"2021-05-24T10:44:17.298891Z","iopub.status.idle":"2021-05-24T10:44:18.125945Z","shell.execute_reply.started":"2021-05-24T10:44:17.298846Z","shell.execute_reply":"2021-05-24T10:44:18.125087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xgbc = XGBClassifier()\nxgbc.fit(train_features, y_train)\nplot_confusion_matrix(xgbc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2021-05-24T10:44:18.127658Z","iopub.execute_input":"2021-05-24T10:44:18.128092Z","iopub.status.idle":"2021-05-24T10:44:18.380717Z","shell.execute_reply.started":"2021-05-24T10:44:18.128046Z","shell.execute_reply":"2021-05-24T10:44:18.379546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}