{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.7.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":4104,"databundleVersionId":46661,"sourceType":"competition"},{"sourceId":265751,"sourceType":"datasetVersion","datasetId":110097}],"dockerImageVersionId":30176,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"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\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 read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-11-30T15:42:59.475588Z","iopub.execute_input":"2023-11-30T15:42:59.476002Z","iopub.status.idle":"2023-11-30T15:42:59.527276Z","shell.execute_reply.started":"2023-11-30T15:42:59.475905Z","shell.execute_reply":"2023-11-30T15:42:59.525752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\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\nprint(\"All modules have been imported\")","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:43:05.067424Z","iopub.execute_input":"2023-11-30T15:43:05.067736Z","iopub.status.idle":"2023-11-30T15:43:17.021243Z","shell.execute_reply.started":"2023-11-30T15:43:05.067702Z","shell.execute_reply":"2023-11-30T15:43:17.020177Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"info=pd.read_csv(\"../input/prepossessed-arrays-of-binary-data/1000_Binary Dataframe\")\ninfo=info.drop('Unnamed: 0',axis=1)\ninfo.head()","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:43:29.735665Z","iopub.execute_input":"2023-11-30T15:43:29.735992Z","iopub.status.idle":"2023-11-30T15:43:29.778447Z","shell.execute_reply.started":"2023-11-30T15:43:29.735956Z","shell.execute_reply":"2023-11-30T15:43:29.777186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"info.level.value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:43:34.851804Z","iopub.execute_input":"2023-11-30T15:43:34.852219Z","iopub.status.idle":"2023-11-30T15:43:34.873124Z","shell.execute_reply.started":"2023-11-30T15:43:34.852174Z","shell.execute_reply":"2023-11-30T15:43:34.871709Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style('darkgrid')\nfig, ax = plt.subplots(figsize=(10,5))\nsns.barplot(x=info.level.unique(),y=info.level.value_counts(),palette='Blues_r',ax=ax)","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:43:40.444965Z","iopub.execute_input":"2023-11-30T15:43:40.445357Z","iopub.status.idle":"2023-11-30T15:43:40.675662Z","shell.execute_reply.started":"2023-11-30T15:43:40.445313Z","shell.execute_reply":"2023-11-30T15:43:40.674792Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sizes = info['level'].values\nsns.distplot(sizes, kde=False)","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:43:43.844668Z","iopub.execute_input":"2023-11-30T15:43:43.844994Z","iopub.status.idle":"2023-11-30T15:43:44.202961Z","shell.execute_reply.started":"2023-11-30T15:43:43.844952Z","shell.execute_reply":"2023-11-30T15:43:44.202164Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Binary_90 = np.load('../input/prepossessed-arrays-of-binary-data/1000_Binary_images_data_90.npz')\nX_90=Binary_90['a']\nBinary_128 = np.load('../input/prepossessed-arrays-of-binary-data/1000_Binary_images_data_128.npz')\nX_128=Binary_128['a']\nBinary_264 = np.load('../input/prepossessed-arrays-of-binary-data/1000_Binary_images_data_264.npz')\nX_264=Binary_264['a']\ny=info['level'].values\n\n\nprint(X_90.shape)\nprint(X_128.shape)\nprint(X_264.shape)\nprint(y.shape)","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:43:50.334374Z","iopub.execute_input":"2023-11-30T15:43:50.335144Z","iopub.status.idle":"2023-11-30T15:44:06.504364Z","shell.execute_reply.started":"2023-11-30T15:43:50.335106Z","shell.execute_reply":"2023-11-30T15:44:06.503353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Shape before reshaping X_90\" +str(X_90.shape))\nX_90=X_90.reshape(1000,90,90,3)\nprint(\"Shape after reshaping X_90\" +str(X_90.shape))\nprint(\"\\n\\n\")\n\nprint(\"Shape before reshaping X_128\" +str(X_128.shape))\nX_128=X_128.reshape(1000,128,128,3)\nprint(\"Shape after reshaping X_128\" +str(X_128.shape))\nprint(\"\\n\\n\")\n\nprint(\"Shape before reshaping X_264\" +str(X_264.shape))\nX_264=X_264.reshape(1000,264,264,3)\nprint(\"Shape after reshaping X_264\" +str(X_264.shape))","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:44:09.585477Z","iopub.execute_input":"2023-11-30T15:44:09.586815Z","iopub.status.idle":"2023-11-30T15:44:09.599440Z","shell.execute_reply.started":"2023-11-30T15:44:09.586750Z","shell.execute_reply":"2023-11-30T15:44:09.597951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.title(\"90*90*3 Image\")\nplt.imshow(X_90[1])\nplt.show()\n\nplt.title(\"128*128*3 Image\")\nplt.imshow(X_128[1])\nplt.show()\n\nplt.title(\"264*264*3 Image\")\nplt.imshow(X_264[1])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:44:14.626982Z","iopub.execute_input":"2023-11-30T15:44:14.627543Z","iopub.status.idle":"2023-11-30T15:44:15.559703Z","shell.execute_reply.started":"2023-11-30T15:44:14.627495Z","shell.execute_reply":"2023-11-30T15:44:15.558704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y.shape","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:44:19.617180Z","iopub.execute_input":"2023-11-30T15:44:19.617577Z","iopub.status.idle":"2023-11-30T15:44:19.624315Z","shell.execute_reply.started":"2023-11-30T15:44:19.617521Z","shell.execute_reply":"2023-11-30T15:44:19.623627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X=np.array(X_264)\nY=np.array(y)\n# 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.5, random_state=42)\nprint(len(x_train),len(x_val),len(x_test))","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:44:26.458136Z","iopub.execute_input":"2023-11-30T15:44:26.458505Z","iopub.status.idle":"2023-11-30T15:44:28.493127Z","shell.execute_reply.started":"2023-11-30T15:44:26.458453Z","shell.execute_reply":"2023-11-30T15:44:28.492199Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y1=pd.DataFrame(Y)\nY1.value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:44:31.318128Z","iopub.execute_input":"2023-11-30T15:44:31.318521Z","iopub.status.idle":"2023-11-30T15:44:31.331369Z","shell.execute_reply.started":"2023-11-30T15:44:31.318478Z","shell.execute_reply":"2023-11-30T15:44:31.330286Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dnn_model=Sequential()\ndnn_model.add(Dense(8, input_dim=3, kernel_initializer = 'uniform', activation = 'relu'))\ndnn_model.add(BatchNormalization())\ndnn_model.add(Dropout(0.2))\ndnn_model.add(Dense(16, kernel_initializer = 'uniform', activation = 'relu' ))\ndnn_model.add(BatchNormalization())\ndnn_model.add(Dropout(0.2))\ndnn_model.add(Dense(32, kernel_initializer = 'uniform', activation = 'relu' ))\ndnn_model.add(BatchNormalization())\ndnn_model.add(Dropout(0.2))\ndnn_model.add(Dense(64, kernel_initializer = 'uniform', activation = 'relu' ))\ndnn_model.add(BatchNormalization())\ndnn_model.add(Dropout(0.2))\ndnn_model.add(Dense(128, kernel_initializer = 'uniform', activation = 'relu'))\ndnn_model.add(BatchNormalization())\ndnn_model.add(Dropout(0.2))\ndnn_model.add(Dense(256, kernel_initializer = 'uniform', activation = 'relu' ))\ndnn_model.add(BatchNormalization())\ndnn_model.add(Dropout(0.2))\ndnn_model.add(Dense(128, kernel_initializer = 'uniform', activation = 'relu' ))\ndnn_model.add(BatchNormalization())\ndnn_model.add(Dropout(0.2))\ndnn_model.add(Dense(64, kernel_initializer = 'uniform', activation = 'relu' ))\ndnn_model.add(BatchNormalization())\ndnn_model.add(Dropout(0.2))\ndnn_model.add(Dense(32, kernel_initializer = 'uniform', activation = 'relu' ))\ndnn_model.add(BatchNormalization())\ndnn_model.add(Dropout(0.2))\ndnn_model.add(Dense(16, kernel_initializer = 'uniform', activation = 'relu' ))\ndnn_model.add(BatchNormalization())\ndnn_model.add(Dropout(0.2))\ndnn_model.add(Dense(8, kernel_initializer = 'uniform', activation = 'relu' ))\ndnn_model.add(BatchNormalization())\ndnn_model.add(Dropout(0.2))\ndnn_model.add(Dense(3,activation='softmax'))\ndnn_model.summary()","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:44:34.386796Z","iopub.execute_input":"2023-11-30T15:44:34.387188Z","iopub.status.idle":"2023-11-30T15:44:35.114412Z","shell.execute_reply.started":"2023-11-30T15:44:34.387145Z","shell.execute_reply":"2023-11-30T15:44:35.113539Z"},"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        \"MLP 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    MLPClassifier()\n        ]\nzipped_clf = zip(names,classifiers)","metadata":{"execution":{"iopub.status.busy":"2023-11-30T15:44:46.210726Z","iopub.execute_input":"2023-11-30T15:44:46.211033Z","iopub.status.idle":"2023-11-30T15:44:46.219450Z","shell.execute_reply.started":"2023-11-30T15:44:46.211000Z","shell.execute_reply":"2023-11-30T15:44:46.218198Z"},"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":"2023-11-30T15:45:03.419101Z","iopub.execute_input":"2023-11-30T15:45:03.419521Z","iopub.status.idle":"2023-11-30T15:45:03.444210Z","shell.execute_reply.started":"2023-11-30T15:45:03.419454Z","shell.execute_reply":"2023-11-30T15:45:03.442796Z"},"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":"2023-11-30T15:45:11.666879Z","iopub.execute_input":"2023-11-30T15:45:11.667242Z","iopub.status.idle":"2023-11-30T15:45:11.675201Z","shell.execute_reply.started":"2023-11-30T15:45:11.667203Z","shell.execute_reply":"2023-11-30T15:45:11.674047Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_model= ResNet50(input_shape=(264,264,3), weights='imagenet', include_top=False)\nx = base_model.output\nx = Dropout(0.5)(x)\nx = Flatten()(x)\nx = BatchNormalization()(x)\nx = Dense(16,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(32,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(64,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(128,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(256,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\npredictions = Dense(3, 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":"2023-11-30T15:45:17.177327Z","iopub.execute_input":"2023-11-30T15:45:17.177738Z","iopub.status.idle":"2023-11-30T15:47:17.380845Z","shell.execute_reply.started":"2023-11-30T15:45:17.177701Z","shell.execute_reply":"2023-11-30T15:47:17.379840Z"},"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        \"MLP 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    MLPClassifier()\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":"2023-11-30T15:47:49.269830Z","iopub.execute_input":"2023-11-30T15:47:49.271229Z","iopub.status.idle":"2023-11-30T15:47:49.296224Z","shell.execute_reply.started":"2023-11-30T15:47:49.271163Z","shell.execute_reply":"2023-11-30T15:47:49.295418Z"},"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":"2023-11-30T15:47:58.425668Z","iopub.execute_input":"2023-11-30T15:47:58.426283Z","iopub.status.idle":"2023-11-30T15:47:59.850226Z","shell.execute_reply.started":"2023-11-30T15:47:58.426242Z","shell.execute_reply":"2023-11-30T15:47:59.848533Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y=to_categorical(y_train,3)\nval_y=to_categorical(y_val,3)\ntest_y=to_categorical(y_test,3)\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":"2023-11-30T15:48:23.817638Z","iopub.execute_input":"2023-11-30T15:48:23.818028Z","iopub.status.idle":"2023-11-30T15:48:33.742296Z","shell.execute_reply.started":"2023-11-30T15:48:23.817991Z","shell.execute_reply":"2023-11-30T15:48:33.741295Z"},"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":"2023-11-30T15:48:39.216784Z","iopub.execute_input":"2023-11-30T15:48:39.217177Z","iopub.status.idle":"2023-11-30T15:48:39.537448Z","shell.execute_reply.started":"2023-11-30T15:48:39.217138Z","shell.execute_reply":"2023-11-30T15:48:39.536052Z"},"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":"2023-11-30T15:48:52.418666Z","iopub.execute_input":"2023-11-30T15:48:52.419070Z","iopub.status.idle":"2023-11-30T15:48:52.733023Z","shell.execute_reply.started":"2023-11-30T15:48:52.419030Z","shell.execute_reply":"2023-11-30T15:48:52.731936Z"},"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":"2023-11-30T15:49:00.826963Z","iopub.execute_input":"2023-11-30T15:49:00.827683Z","iopub.status.idle":"2023-11-30T15:49:01.355399Z","shell.execute_reply.started":"2023-11-30T15:49:00.827637Z","shell.execute_reply":"2023-11-30T15:49:01.354423Z"},"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":"2023-11-30T15:49:04.776977Z","iopub.execute_input":"2023-11-30T15:49:04.777363Z","iopub.status.idle":"2023-11-30T15:49:05.543932Z","shell.execute_reply.started":"2023-11-30T15:49:04.777320Z","shell.execute_reply":"2023-11-30T15:49:05.542741Z"},"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":"2023-11-30T15:49:08.447071Z","iopub.execute_input":"2023-11-30T15:49:08.447436Z","iopub.status.idle":"2023-11-30T15:49:09.188300Z","shell.execute_reply.started":"2023-11-30T15:49:08.447391Z","shell.execute_reply":"2023-11-30T15:49:09.187517Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mlpc = MLPClassifier()\nmlpc.fit(train_features, y_train)\nplot_confusion_matrix(mlpc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2022-04-02T14:02:25.695488Z","iopub.execute_input":"2022-04-02T14:02:25.69618Z","iopub.status.idle":"2022-04-02T14:02:26.162342Z","shell.execute_reply.started":"2022-04-02T14:02:25.696125Z","shell.execute_reply":"2022-04-02T14:02:26.161565Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_model= VGG16(input_shape=(264,264,3), weights='imagenet', include_top=False)\nx = base_model.output\nx = Dropout(0.5)(x)\nx = Flatten()(x)\nx = BatchNormalization()(x)\nx = Dense(16,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(32,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(64,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(128,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(256,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\npredictions = Dense(3, 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":"2022-04-02T14:02:45.009175Z","iopub.execute_input":"2022-04-02T14:02:45.009576Z","iopub.status.idle":"2022-04-02T14:08:49.06446Z","shell.execute_reply.started":"2022-04-02T14:02:45.009535Z","shell.execute_reply":"2022-04-02T14:08:49.063563Z"},"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        \"MLP 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    MLPClassifier()\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":"2022-04-02T14:08:58.806329Z","iopub.execute_input":"2022-04-02T14:08:58.806693Z","iopub.status.idle":"2022-04-02T14:08:58.835155Z","shell.execute_reply.started":"2022-04-02T14:08:58.806655Z","shell.execute_reply":"2022-04-02T14:08:58.834214Z"},"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":"2022-04-02T14:09:30.903973Z","iopub.execute_input":"2022-04-02T14:09:30.904992Z","iopub.status.idle":"2022-04-02T14:09:32.096805Z","shell.execute_reply.started":"2022-04-02T14:09:30.904922Z","shell.execute_reply":"2022-04-02T14:09:32.095837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y=to_categorical(y_train,3)\nval_y=to_categorical(y_val,3)\ntest_y=to_categorical(y_test,3)\ndnn_model.compile(optimizer='sgd',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":"2022-04-02T14:09:56.146475Z","iopub.execute_input":"2022-04-02T14:09:56.146825Z","iopub.status.idle":"2022-04-02T14:10:03.371071Z","shell.execute_reply.started":"2022-04-02T14:09:56.146792Z","shell.execute_reply":"2022-04-02T14:10:03.369456Z"},"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":"2022-04-02T14:10:20.952885Z","iopub.execute_input":"2022-04-02T14:10:20.953765Z","iopub.status.idle":"2022-04-02T14:10:21.238593Z","shell.execute_reply.started":"2022-04-02T14:10:20.953686Z","shell.execute_reply":"2022-04-02T14:10:21.237964Z"},"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":"2022-04-02T14:18:39.458814Z","iopub.execute_input":"2022-04-02T14:18:39.459183Z","iopub.status.idle":"2022-04-02T14:18:39.746363Z","shell.execute_reply.started":"2022-04-02T14:18:39.45915Z","shell.execute_reply":"2022-04-02T14:18:39.745356Z"},"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":"2022-04-02T14:18:54.975895Z","iopub.execute_input":"2022-04-02T14:18:54.976805Z","iopub.status.idle":"2022-04-02T14:18:55.494825Z","shell.execute_reply.started":"2022-04-02T14:18:54.976763Z","shell.execute_reply":"2022-04-02T14:18:55.493888Z"},"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":"2022-04-02T14:19:15.118876Z","iopub.execute_input":"2022-04-02T14:19:15.119249Z","iopub.status.idle":"2022-04-02T14:19:15.495128Z","shell.execute_reply.started":"2022-04-02T14:19:15.11921Z","shell.execute_reply":"2022-04-02T14:19:15.4941Z"},"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":"2022-04-02T14:19:34.700439Z","iopub.execute_input":"2022-04-02T14:19:34.701204Z","iopub.status.idle":"2022-04-02T14:19:35.452875Z","shell.execute_reply.started":"2022-04-02T14:19:34.701151Z","shell.execute_reply":"2022-04-02T14:19:35.451953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mlpc = MLPClassifier()\nmlpc.fit(train_features, y_train)\nplot_confusion_matrix(mlpc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2022-04-02T14:19:57.906633Z","iopub.execute_input":"2022-04-02T14:19:57.907386Z","iopub.status.idle":"2022-04-02T14:19:58.38465Z","shell.execute_reply.started":"2022-04-02T14:19:57.907323Z","shell.execute_reply":"2022-04-02T14:19:58.383713Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_model= VGG19(input_shape=(264,264,3), weights='imagenet', include_top=False)\nx = base_model.output\nx = Dropout(0.5)(x)\nx = Flatten()(x)\nx = BatchNormalization()(x)\nx = Dense(16,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(32,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(64,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(128,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(256,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\npredictions = Dense(3, 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":"2022-04-02T14:20:21.394255Z","iopub.execute_input":"2022-04-02T14:20:21.39462Z","iopub.status.idle":"2022-04-02T14:27:52.535286Z","shell.execute_reply.started":"2022-04-02T14:20:21.394579Z","shell.execute_reply":"2022-04-02T14:27:52.534394Z"},"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        \"MLP 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    MLPClassifier()\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":"2022-04-02T14:28:26.492848Z","iopub.execute_input":"2022-04-02T14:28:26.493194Z","iopub.status.idle":"2022-04-02T14:28:26.516327Z","shell.execute_reply.started":"2022-04-02T14:28:26.49315Z","shell.execute_reply":"2022-04-02T14:28:26.515589Z"},"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":"2022-04-02T14:28:43.76581Z","iopub.execute_input":"2022-04-02T14:28:43.766584Z","iopub.status.idle":"2022-04-02T14:28:44.942519Z","shell.execute_reply.started":"2022-04-02T14:28:43.766535Z","shell.execute_reply":"2022-04-02T14:28:44.941584Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y=to_categorical(y_train,3)\nval_y=to_categorical(y_val,3)\ntest_y=to_categorical(y_test,3)\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":"2022-04-02T14:29:10.467763Z","iopub.execute_input":"2022-04-02T14:29:10.468117Z","iopub.status.idle":"2022-04-02T14:29:18.078409Z","shell.execute_reply.started":"2022-04-02T14:29:10.468076Z","shell.execute_reply":"2022-04-02T14:29:18.077718Z"},"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":"2022-04-02T14:30:59.961524Z","iopub.execute_input":"2022-04-02T14:30:59.962012Z","iopub.status.idle":"2022-04-02T14:31:00.253288Z","shell.execute_reply.started":"2022-04-02T14:30:59.961966Z","shell.execute_reply":"2022-04-02T14:31:00.252026Z"},"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":"2022-04-02T14:31:12.81971Z","iopub.execute_input":"2022-04-02T14:31:12.820371Z","iopub.status.idle":"2022-04-02T14:31:13.103473Z","shell.execute_reply.started":"2022-04-02T14:31:12.82032Z","shell.execute_reply":"2022-04-02T14:31:13.102841Z"},"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":"2022-04-02T14:31:29.043224Z","iopub.execute_input":"2022-04-02T14:31:29.043782Z","iopub.status.idle":"2022-04-02T14:31:29.551878Z","shell.execute_reply.started":"2022-04-02T14:31:29.043724Z","shell.execute_reply":"2022-04-02T14:31:29.551013Z"},"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":"2022-04-02T14:31:44.528518Z","iopub.execute_input":"2022-04-02T14:31:44.529762Z","iopub.status.idle":"2022-04-02T14:31:44.925595Z","shell.execute_reply.started":"2022-04-02T14:31:44.529612Z","shell.execute_reply":"2022-04-02T14:31:44.924508Z"},"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":"2022-04-02T14:32:01.970584Z","iopub.execute_input":"2022-04-02T14:32:01.970922Z","iopub.status.idle":"2022-04-02T14:32:02.706894Z","shell.execute_reply.started":"2022-04-02T14:32:01.97089Z","shell.execute_reply":"2022-04-02T14:32:02.705726Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mlpc = MLPClassifier()\nmlpc.fit(train_features, y_train)\nplot_confusion_matrix(mlpc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2022-04-02T14:32:18.065712Z","iopub.execute_input":"2022-04-02T14:32:18.066067Z","iopub.status.idle":"2022-04-02T14:32:18.542687Z","shell.execute_reply.started":"2022-04-02T14:32:18.066031Z","shell.execute_reply":"2022-04-02T14:32:18.542011Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_model= ResNet101(input_shape=(264,264,3), weights='imagenet', include_top=False)\nx = base_model.output\nx = Dropout(0.5)(x)\nx = Flatten()(x)\nx = BatchNormalization()(x)\nx = Dense(16,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(32,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(64,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(128,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(256,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\npredictions = Dense(3, 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":"2022-04-02T14:32:38.076982Z","iopub.execute_input":"2022-04-02T14:32:38.077315Z","iopub.status.idle":"2022-04-02T14:36:09.502917Z","shell.execute_reply.started":"2022-04-02T14:32:38.077279Z","shell.execute_reply":"2022-04-02T14:36:09.501842Z"},"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        \"MLP 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    MLPClassifier()\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":"2022-04-02T14:36:41.429785Z","iopub.execute_input":"2022-04-02T14:36:41.430596Z","iopub.status.idle":"2022-04-02T14:36:41.454827Z","shell.execute_reply.started":"2022-04-02T14:36:41.430545Z","shell.execute_reply":"2022-04-02T14:36:41.453816Z"},"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":"2022-04-02T14:36:58.26854Z","iopub.execute_input":"2022-04-02T14:36:58.269161Z","iopub.status.idle":"2022-04-02T14:36:59.440317Z","shell.execute_reply.started":"2022-04-02T14:36:58.26912Z","shell.execute_reply":"2022-04-02T14:36:59.439242Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y=to_categorical(y_train,3)\nval_y=to_categorical(y_val,3)\ntest_y=to_categorical(y_test,3)\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":"2022-04-02T14:37:32.050756Z","iopub.execute_input":"2022-04-02T14:37:32.051443Z","iopub.status.idle":"2022-04-02T14:37:39.342492Z","shell.execute_reply.started":"2022-04-02T14:37:32.051379Z","shell.execute_reply":"2022-04-02T14:37:39.341448Z"},"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)\n","metadata":{"execution":{"iopub.status.busy":"2022-04-02T14:38:53.296729Z","iopub.execute_input":"2022-04-02T14:38:53.297117Z","iopub.status.idle":"2022-04-02T14:38:53.585077Z","shell.execute_reply.started":"2022-04-02T14:38:53.297076Z","shell.execute_reply":"2022-04-02T14:38:53.584031Z"},"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":"2022-04-02T14:39:09.982114Z","iopub.execute_input":"2022-04-02T14:39:09.982423Z","iopub.status.idle":"2022-04-02T14:39:10.271141Z","shell.execute_reply.started":"2022-04-02T14:39:09.982394Z","shell.execute_reply":"2022-04-02T14:39:10.270029Z"},"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":"2022-04-02T14:39:23.874545Z","iopub.execute_input":"2022-04-02T14:39:23.874881Z","iopub.status.idle":"2022-04-02T14:39:24.375176Z","shell.execute_reply.started":"2022-04-02T14:39:23.874846Z","shell.execute_reply":"2022-04-02T14:39:24.374203Z"},"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)\n","metadata":{"execution":{"iopub.status.busy":"2022-04-02T14:39:41.852561Z","iopub.execute_input":"2022-04-02T14:39:41.852891Z","iopub.status.idle":"2022-04-02T14:39:42.231487Z","shell.execute_reply.started":"2022-04-02T14:39:41.852855Z","shell.execute_reply":"2022-04-02T14:39:42.2304Z"},"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":"2022-04-02T14:39:55.501347Z","iopub.execute_input":"2022-04-02T14:39:55.50168Z","iopub.status.idle":"2022-04-02T14:39:56.212376Z","shell.execute_reply.started":"2022-04-02T14:39:55.501645Z","shell.execute_reply":"2022-04-02T14:39:56.211292Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mlpc = MLPClassifier()\nmlpc.fit(train_features, y_train)\nplot_confusion_matrix(mlpc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2022-04-02T14:40:12.886179Z","iopub.execute_input":"2022-04-02T14:40:12.886653Z","iopub.status.idle":"2022-04-02T14:40:13.948405Z","shell.execute_reply.started":"2022-04-02T14:40:12.886616Z","shell.execute_reply":"2022-04-02T14:40:13.947725Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_model= MobileNetV2(input_shape=(264,264,3), weights='imagenet', include_top=False)\nx = base_model.output\nx = Dropout(0.5)(x)\nx = Flatten()(x)\nx = BatchNormalization()(x)\nx = Dense(16,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(32,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(64,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(128,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(256,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\npredictions = Dense(3, 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":"2022-04-02T14:40:33.168475Z","iopub.execute_input":"2022-04-02T14:40:33.169117Z","iopub.status.idle":"2022-04-02T14:40:52.245867Z","shell.execute_reply.started":"2022-04-02T14:40:33.169071Z","shell.execute_reply":"2022-04-02T14:40:52.245044Z"},"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        \"MLP 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    MLPClassifier()\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":"2022-04-02T14:41:56.733173Z","iopub.execute_input":"2022-04-02T14:41:56.733519Z","iopub.status.idle":"2022-04-02T14:41:56.75734Z","shell.execute_reply.started":"2022-04-02T14:41:56.733486Z","shell.execute_reply":"2022-04-02T14:41:56.756246Z"},"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":"2022-04-02T14:42:17.200976Z","iopub.execute_input":"2022-04-02T14:42:17.201334Z","iopub.status.idle":"2022-04-02T14:42:18.440001Z","shell.execute_reply.started":"2022-04-02T14:42:17.201298Z","shell.execute_reply":"2022-04-02T14:42:18.438813Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y=to_categorical(y_train,3)\nval_y=to_categorical(y_val,3)\ntest_y=to_categorical(y_test,3)\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":"2022-04-02T14:42:44.63976Z","iopub.execute_input":"2022-04-02T14:42:44.64048Z","iopub.status.idle":"2022-04-02T14:42:51.668112Z","shell.execute_reply.started":"2022-04-02T14:42:44.640436Z","shell.execute_reply":"2022-04-02T14:42:51.667174Z"},"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":"2022-04-02T14:43:11.972438Z","iopub.execute_input":"2022-04-02T14:43:11.972772Z","iopub.status.idle":"2022-04-02T14:43:12.249248Z","shell.execute_reply.started":"2022-04-02T14:43:11.972737Z","shell.execute_reply":"2022-04-02T14:43:12.248417Z"},"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":"2022-04-02T14:43:31.648532Z","iopub.execute_input":"2022-04-02T14:43:31.648879Z","iopub.status.idle":"2022-04-02T14:43:31.942144Z","shell.execute_reply.started":"2022-04-02T14:43:31.648844Z","shell.execute_reply":"2022-04-02T14:43:31.941334Z"},"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":"2022-04-02T14:43:49.370036Z","iopub.execute_input":"2022-04-02T14:43:49.370365Z","iopub.status.idle":"2022-04-02T14:43:49.865187Z","shell.execute_reply.started":"2022-04-02T14:43:49.370333Z","shell.execute_reply":"2022-04-02T14:43:49.864269Z"},"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":"2022-04-02T14:44:03.403565Z","iopub.execute_input":"2022-04-02T14:44:03.404391Z","iopub.status.idle":"2022-04-02T14:44:03.772913Z","shell.execute_reply.started":"2022-04-02T14:44:03.404339Z","shell.execute_reply":"2022-04-02T14:44:03.772121Z"},"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":"2022-04-02T14:44:20.353423Z","iopub.execute_input":"2022-04-02T14:44:20.355255Z","iopub.status.idle":"2022-04-02T14:44:21.061877Z","shell.execute_reply.started":"2022-04-02T14:44:20.355178Z","shell.execute_reply":"2022-04-02T14:44:21.060902Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mlpc = MLPClassifier()\nmlpc.fit(train_features, y_train)\nplot_confusion_matrix(mlpc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2022-04-02T14:44:38.600278Z","iopub.execute_input":"2022-04-02T14:44:38.600596Z","iopub.status.idle":"2022-04-02T14:44:39.102801Z","shell.execute_reply.started":"2022-04-02T14:44:38.600561Z","shell.execute_reply":"2022-04-02T14:44:39.101684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_model= MobileNet(input_shape=(264,264,3), weights='imagenet', include_top=False)\nx = base_model.output\nx = Dropout(0.5)(x)\nx = Flatten()(x)\nx = BatchNormalization()(x)\nx = Dense(16,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(32,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(64,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(128,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(256,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\npredictions = Dense(3, 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":"2022-04-02T14:45:00.001047Z","iopub.execute_input":"2022-04-02T14:45:00.001393Z","iopub.status.idle":"2022-04-02T14:45:19.193145Z","shell.execute_reply.started":"2022-04-02T14:45:00.001362Z","shell.execute_reply":"2022-04-02T14:45:19.192204Z"},"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        \"MLP 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    MLPClassifier()\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":"2022-04-02T14:45:37.660166Z","iopub.execute_input":"2022-04-02T14:45:37.660515Z","iopub.status.idle":"2022-04-02T14:45:37.683958Z","shell.execute_reply.started":"2022-04-02T14:45:37.660479Z","shell.execute_reply":"2022-04-02T14:45:37.683027Z"},"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":"2022-04-02T14:45:49.291967Z","iopub.execute_input":"2022-04-02T14:45:49.292299Z","iopub.status.idle":"2022-04-02T14:45:50.457459Z","shell.execute_reply.started":"2022-04-02T14:45:49.292263Z","shell.execute_reply":"2022-04-02T14:45:50.45631Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y=to_categorical(y_train,3)\nval_y=to_categorical(y_val,3)\ntest_y=to_categorical(y_test,3)\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":"2022-04-02T14:46:19.028854Z","iopub.execute_input":"2022-04-02T14:46:19.029584Z","iopub.status.idle":"2022-04-02T14:46:26.160387Z","shell.execute_reply.started":"2022-04-02T14:46:19.029541Z","shell.execute_reply":"2022-04-02T14:46:26.159114Z"},"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":"2022-04-02T14:46:45.416418Z","iopub.execute_input":"2022-04-02T14:46:45.416729Z","iopub.status.idle":"2022-04-02T14:46:45.687552Z","shell.execute_reply.started":"2022-04-02T14:46:45.416699Z","shell.execute_reply":"2022-04-02T14:46:45.68653Z"},"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":"2022-04-02T14:47:02.800127Z","iopub.execute_input":"2022-04-02T14:47:02.800458Z","iopub.status.idle":"2022-04-02T14:47:03.089525Z","shell.execute_reply.started":"2022-04-02T14:47:02.800422Z","shell.execute_reply":"2022-04-02T14:47:03.088377Z"},"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":"2022-04-02T14:47:22.837001Z","iopub.execute_input":"2022-04-02T14:47:22.837343Z","iopub.status.idle":"2022-04-02T14:47:23.344058Z","shell.execute_reply.started":"2022-04-02T14:47:22.837311Z","shell.execute_reply":"2022-04-02T14:47:23.342974Z"},"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":"2022-04-02T14:47:41.907541Z","iopub.execute_input":"2022-04-02T14:47:41.908725Z","iopub.status.idle":"2022-04-02T14:47:42.320725Z","shell.execute_reply.started":"2022-04-02T14:47:41.908679Z","shell.execute_reply":"2022-04-02T14:47:42.319433Z"},"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":"2022-04-02T14:47:58.939707Z","iopub.execute_input":"2022-04-02T14:47:58.940804Z","iopub.status.idle":"2022-04-02T14:47:59.677891Z","shell.execute_reply.started":"2022-04-02T14:47:58.940746Z","shell.execute_reply":"2022-04-02T14:47:59.676857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mlpc = MLPClassifier()\nmlpc.fit(train_features, y_train)\nplot_confusion_matrix(mlpc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2022-04-02T14:48:16.524437Z","iopub.execute_input":"2022-04-02T14:48:16.5248Z","iopub.status.idle":"2022-04-02T14:48:16.983447Z","shell.execute_reply.started":"2022-04-02T14:48:16.524767Z","shell.execute_reply":"2022-04-02T14:48:16.982722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_model= MobileNet(input_shape=(264,264,3), weights='imagenet', include_top=False)\nx = base_model.output\nx = Dropout(0.5)(x)\nx = Flatten()(x)\nx = BatchNormalization()(x)\nx = Dense(16,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(32,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(64,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(128,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(256,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\npredictions = Dense(3, 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":"2022-04-02T14:48:37.307477Z","iopub.execute_input":"2022-04-02T14:48:37.307835Z","iopub.status.idle":"2022-04-02T14:48:57.68223Z","shell.execute_reply.started":"2022-04-02T14:48:37.307799Z","shell.execute_reply":"2022-04-02T14:48:57.681301Z"},"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        \"MLP 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    MLPClassifier()\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":"2022-04-02T14:49:08.501141Z","iopub.execute_input":"2022-04-02T14:49:08.501462Z","iopub.status.idle":"2022-04-02T14:49:08.525382Z","shell.execute_reply.started":"2022-04-02T14:49:08.50143Z","shell.execute_reply":"2022-04-02T14:49:08.524411Z"},"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":"2022-04-02T14:49:20.032202Z","iopub.execute_input":"2022-04-02T14:49:20.032553Z","iopub.status.idle":"2022-04-02T14:49:22.353598Z","shell.execute_reply.started":"2022-04-02T14:49:20.032517Z","shell.execute_reply":"2022-04-02T14:49:22.35251Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y=to_categorical(y_train,3)\nval_y=to_categorical(y_val,3)\ntest_y=to_categorical(y_test,3)\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":"2022-04-02T14:49:41.419494Z","iopub.execute_input":"2022-04-02T14:49:41.419993Z","iopub.status.idle":"2022-04-02T14:49:48.839657Z","shell.execute_reply.started":"2022-04-02T14:49:41.419947Z","shell.execute_reply":"2022-04-02T14:49:48.838729Z"},"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":"2022-04-02T14:50:17.864915Z","iopub.execute_input":"2022-04-02T14:50:17.865309Z","iopub.status.idle":"2022-04-02T14:50:18.146884Z","shell.execute_reply.started":"2022-04-02T14:50:17.865275Z","shell.execute_reply":"2022-04-02T14:50:18.145844Z"},"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":"2022-04-02T14:50:35.824227Z","iopub.execute_input":"2022-04-02T14:50:35.824757Z","iopub.status.idle":"2022-04-02T14:50:36.118498Z","shell.execute_reply.started":"2022-04-02T14:50:35.824702Z","shell.execute_reply":"2022-04-02T14:50:36.117567Z"},"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":"2022-04-02T14:50:59.943072Z","iopub.execute_input":"2022-04-02T14:50:59.943833Z","iopub.status.idle":"2022-04-02T14:51:00.463083Z","shell.execute_reply.started":"2022-04-02T14:50:59.943765Z","shell.execute_reply":"2022-04-02T14:51:00.462114Z"},"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":"2022-04-02T14:51:16.457024Z","iopub.execute_input":"2022-04-02T14:51:16.457663Z","iopub.status.idle":"2022-04-02T14:51:16.831871Z","shell.execute_reply.started":"2022-04-02T14:51:16.457609Z","shell.execute_reply":"2022-04-02T14:51:16.830817Z"},"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":"2022-04-02T14:51:35.567427Z","iopub.execute_input":"2022-04-02T14:51:35.568045Z","iopub.status.idle":"2022-04-02T14:51:36.284103Z","shell.execute_reply.started":"2022-04-02T14:51:35.567996Z","shell.execute_reply":"2022-04-02T14:51:36.282976Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mlpc = MLPClassifier()\nmlpc.fit(train_features, y_train)\nplot_confusion_matrix(mlpc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2022-04-02T14:51:57.312477Z","iopub.execute_input":"2022-04-02T14:51:57.313594Z","iopub.status.idle":"2022-04-02T14:51:57.881137Z","shell.execute_reply.started":"2022-04-02T14:51:57.31354Z","shell.execute_reply":"2022-04-02T14:51:57.880061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_model= InceptionResNetV2(input_shape=(264,264,3), weights='imagenet', include_top=False)\nx = base_model.output\nx = Dropout(0.5)(x)\nx = Flatten()(x)\nx = BatchNormalization()(x)\nx = Dense(16,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(32,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(64,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(128,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(256,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\npredictions = Dense(3, 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":"2022-04-02T14:52:20.567207Z","iopub.execute_input":"2022-04-02T14:52:20.567521Z","iopub.status.idle":"2022-04-02T14:55:07.261126Z","shell.execute_reply.started":"2022-04-02T14:52:20.56749Z","shell.execute_reply":"2022-04-02T14:55:07.260023Z"},"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        \"MLP 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    MLPClassifier()\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":"2022-04-02T14:55:20.571906Z","iopub.execute_input":"2022-04-02T14:55:20.572648Z","iopub.status.idle":"2022-04-02T14:55:20.596413Z","shell.execute_reply.started":"2022-04-02T14:55:20.572603Z","shell.execute_reply":"2022-04-02T14:55:20.595344Z"},"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":"2022-04-02T14:55:33.044953Z","iopub.execute_input":"2022-04-02T14:55:33.045298Z","iopub.status.idle":"2022-04-02T14:55:34.247322Z","shell.execute_reply.started":"2022-04-02T14:55:33.045266Z","shell.execute_reply":"2022-04-02T14:55:34.245673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y=to_categorical(y_train,3)\nval_y=to_categorical(y_val,3)\ntest_y=to_categorical(y_test,3)\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":"2022-04-02T14:55:55.822712Z","iopub.execute_input":"2022-04-02T14:55:55.823415Z","iopub.status.idle":"2022-04-02T14:56:04.035775Z","shell.execute_reply.started":"2022-04-02T14:55:55.823359Z","shell.execute_reply":"2022-04-02T14:56:04.035045Z"},"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":"2022-04-02T14:56:18.883238Z","iopub.execute_input":"2022-04-02T14:56:18.883817Z","iopub.status.idle":"2022-04-02T14:56:19.169164Z","shell.execute_reply.started":"2022-04-02T14:56:18.883768Z","shell.execute_reply":"2022-04-02T14:56:19.168173Z"},"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":"2022-04-02T14:56:36.289163Z","iopub.execute_input":"2022-04-02T14:56:36.289567Z","iopub.status.idle":"2022-04-02T14:56:36.573639Z","shell.execute_reply.started":"2022-04-02T14:56:36.289529Z","shell.execute_reply":"2022-04-02T14:56:36.57231Z"},"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":"2022-04-02T14:56:54.144825Z","iopub.execute_input":"2022-04-02T14:56:54.145222Z","iopub.status.idle":"2022-04-02T14:56:54.664181Z","shell.execute_reply.started":"2022-04-02T14:56:54.145184Z","shell.execute_reply":"2022-04-02T14:56:54.663181Z"},"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":"2022-04-02T14:57:12.941001Z","iopub.execute_input":"2022-04-02T14:57:12.941363Z","iopub.status.idle":"2022-04-02T14:57:13.310898Z","shell.execute_reply.started":"2022-04-02T14:57:12.941328Z","shell.execute_reply":"2022-04-02T14:57:13.309949Z"},"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":"2022-04-02T14:57:32.719968Z","iopub.execute_input":"2022-04-02T14:57:32.720279Z","iopub.status.idle":"2022-04-02T14:57:33.460977Z","shell.execute_reply.started":"2022-04-02T14:57:32.720248Z","shell.execute_reply":"2022-04-02T14:57:33.459988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mlpc = MLPClassifier()\nmlpc.fit(train_features, y_train)\nplot_confusion_matrix(mlpc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2022-04-02T14:57:52.247898Z","iopub.execute_input":"2022-04-02T14:57:52.248356Z","iopub.status.idle":"2022-04-02T14:57:52.718376Z","shell.execute_reply.started":"2022-04-02T14:57:52.248302Z","shell.execute_reply":"2022-04-02T14:57:52.717564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_model= InceptionResNetV2(input_shape=(264,264,3), weights='imagenet', include_top=False)\nx = base_model.output\nx = Dropout(0.5)(x)\nx = Flatten()(x)\nx = BatchNormalization()(x)\nx = Dense(16,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(32,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(64,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(128,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(256,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\npredictions = Dense(3, 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":"2022-04-02T14:58:12.728664Z","iopub.execute_input":"2022-04-02T14:58:12.729422Z","iopub.status.idle":"2022-04-02T15:00:58.815852Z","shell.execute_reply.started":"2022-04-02T14:58:12.729378Z","shell.execute_reply":"2022-04-02T15:00:58.815118Z"},"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        \"MLP 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    MLPClassifier()\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":"2022-04-02T15:01:07.314667Z","iopub.execute_input":"2022-04-02T15:01:07.31516Z","iopub.status.idle":"2022-04-02T15:01:07.337323Z","shell.execute_reply.started":"2022-04-02T15:01:07.315124Z","shell.execute_reply":"2022-04-02T15:01:07.336493Z"},"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":"2022-04-02T15:01:22.24783Z","iopub.execute_input":"2022-04-02T15:01:22.248185Z","iopub.status.idle":"2022-04-02T15:01:23.483291Z","shell.execute_reply.started":"2022-04-02T15:01:22.248145Z","shell.execute_reply":"2022-04-02T15:01:23.482189Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y=to_categorical(y_train,3)\nval_y=to_categorical(y_val,3)\ntest_y=to_categorical(y_test,3)\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":"2022-04-02T15:01:45.090262Z","iopub.execute_input":"2022-04-02T15:01:45.090604Z","iopub.status.idle":"2022-04-02T15:01:52.31436Z","shell.execute_reply.started":"2022-04-02T15:01:45.090569Z","shell.execute_reply":"2022-04-02T15:01:52.313152Z"},"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":"2022-04-02T15:02:07.110855Z","iopub.execute_input":"2022-04-02T15:02:07.111471Z","iopub.status.idle":"2022-04-02T15:02:07.387535Z","shell.execute_reply.started":"2022-04-02T15:02:07.111429Z","shell.execute_reply":"2022-04-02T15:02:07.386435Z"},"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":"2022-04-02T15:02:22.866662Z","iopub.execute_input":"2022-04-02T15:02:22.8673Z","iopub.status.idle":"2022-04-02T15:02:23.152535Z","shell.execute_reply.started":"2022-04-02T15:02:22.86726Z","shell.execute_reply":"2022-04-02T15:02:23.151637Z"},"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":"2022-04-02T15:02:41.256292Z","iopub.execute_input":"2022-04-02T15:02:41.256863Z","iopub.status.idle":"2022-04-02T15:02:41.745518Z","shell.execute_reply.started":"2022-04-02T15:02:41.256825Z","shell.execute_reply":"2022-04-02T15:02:41.744873Z"},"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":"2022-04-02T15:03:14.829979Z","iopub.execute_input":"2022-04-02T15:03:14.830875Z","iopub.status.idle":"2022-04-02T15:03:15.197332Z","shell.execute_reply.started":"2022-04-02T15:03:14.830821Z","shell.execute_reply":"2022-04-02T15:03:15.196437Z"},"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":"2022-04-02T15:03:51.454959Z","iopub.execute_input":"2022-04-02T15:03:51.4553Z","iopub.status.idle":"2022-04-02T15:03:52.292907Z","shell.execute_reply.started":"2022-04-02T15:03:51.455265Z","shell.execute_reply":"2022-04-02T15:03:52.291926Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mlpc = MLPClassifier()\nmlpc.fit(train_features, y_train)\nplot_confusion_matrix(mlpc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2022-04-02T15:04:10.149893Z","iopub.execute_input":"2022-04-02T15:04:10.150249Z","iopub.status.idle":"2022-04-02T15:04:10.565382Z","shell.execute_reply.started":"2022-04-02T15:04:10.150212Z","shell.execute_reply":"2022-04-02T15:04:10.564591Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_model= InceptionResNetV2(input_shape=(264,264,3), weights='imagenet', include_top=False)\nx = base_model.output\nx = Dropout(0.5)(x)\nx = Flatten()(x)\nx = BatchNormalization()(x)\nx = Dense(16,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(32,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(64,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(128,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(256,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\npredictions = Dense(3, 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":"2022-04-02T15:04:31.757824Z","iopub.execute_input":"2022-04-02T15:04:31.758693Z","iopub.status.idle":"2022-04-02T15:07:19.844568Z","shell.execute_reply.started":"2022-04-02T15:04:31.758653Z","shell.execute_reply":"2022-04-02T15:07:19.843516Z"},"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        \"MLP 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    MLPClassifier()\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":"2022-04-02T15:07:27.25532Z","iopub.execute_input":"2022-04-02T15:07:27.255638Z","iopub.status.idle":"2022-04-02T15:07:27.278763Z","shell.execute_reply.started":"2022-04-02T15:07:27.255607Z","shell.execute_reply":"2022-04-02T15:07:27.277923Z"},"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":"2022-04-02T15:07:40.384048Z","iopub.execute_input":"2022-04-02T15:07:40.384578Z","iopub.status.idle":"2022-04-02T15:07:41.575025Z","shell.execute_reply.started":"2022-04-02T15:07:40.384522Z","shell.execute_reply":"2022-04-02T15:07:41.573965Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y=to_categorical(y_train,3)\nval_y=to_categorical(y_val,3)\ntest_y=to_categorical(y_test,3)\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":"2022-04-02T15:08:03.096596Z","iopub.execute_input":"2022-04-02T15:08:03.096971Z","iopub.status.idle":"2022-04-02T15:08:10.423465Z","shell.execute_reply.started":"2022-04-02T15:08:03.096922Z","shell.execute_reply":"2022-04-02T15:08:10.422426Z"},"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":"2022-04-02T15:08:29.58579Z","iopub.execute_input":"2022-04-02T15:08:29.586121Z","iopub.status.idle":"2022-04-02T15:08:29.86592Z","shell.execute_reply.started":"2022-04-02T15:08:29.586089Z","shell.execute_reply":"2022-04-02T15:08:29.8649Z"},"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":"2022-04-02T15:08:46.373071Z","iopub.execute_input":"2022-04-02T15:08:46.373397Z","iopub.status.idle":"2022-04-02T15:08:46.663121Z","shell.execute_reply.started":"2022-04-02T15:08:46.373366Z","shell.execute_reply":"2022-04-02T15:08:46.662279Z"},"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":"2022-04-02T15:08:59.606596Z","iopub.execute_input":"2022-04-02T15:08:59.606905Z","iopub.status.idle":"2022-04-02T15:09:00.116238Z","shell.execute_reply.started":"2022-04-02T15:08:59.606876Z","shell.execute_reply":"2022-04-02T15:09:00.115273Z"},"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":"2022-04-02T15:09:19.456985Z","iopub.execute_input":"2022-04-02T15:09:19.457324Z","iopub.status.idle":"2022-04-02T15:09:19.836747Z","shell.execute_reply.started":"2022-04-02T15:09:19.457285Z","shell.execute_reply":"2022-04-02T15:09:19.835855Z"},"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":"2022-04-02T15:09:38.221323Z","iopub.execute_input":"2022-04-02T15:09:38.22165Z","iopub.status.idle":"2022-04-02T15:09:38.94911Z","shell.execute_reply.started":"2022-04-02T15:09:38.221618Z","shell.execute_reply":"2022-04-02T15:09:38.948117Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mlpc = MLPClassifier()\nmlpc.fit(train_features, y_train)\nplot_confusion_matrix(mlpc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2022-04-02T15:09:55.638563Z","iopub.execute_input":"2022-04-02T15:09:55.638958Z","iopub.status.idle":"2022-04-02T15:09:56.03086Z","shell.execute_reply.started":"2022-04-02T15:09:55.638908Z","shell.execute_reply":"2022-04-02T15:09:56.030079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_model= InceptionResNetV2(input_shape=(264,264,3), weights='imagenet', include_top=False)\nx = base_model.output\nx = Dropout(0.5)(x)\nx = Flatten()(x)\nx = BatchNormalization()(x)\nx = Dense(16,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(32,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(64,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(128,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(256,kernel_initializer='he_uniform')(x)\nx = BatchNormalization()(x)\nx = Activation('relu')(x)\nx = Dropout(0.5)(x)\npredictions = Dense(3, 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":"2022-04-02T15:10:16.120866Z","iopub.execute_input":"2022-04-02T15:10:16.121354Z","iopub.status.idle":"2022-04-02T15:13:02.203651Z","shell.execute_reply.started":"2022-04-02T15:10:16.12132Z","shell.execute_reply":"2022-04-02T15:13:02.202926Z"},"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        \"MLP 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    MLPClassifier()\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":"2022-04-02T15:13:14.380835Z","iopub.execute_input":"2022-04-02T15:13:14.381766Z","iopub.status.idle":"2022-04-02T15:13:14.40629Z","shell.execute_reply.started":"2022-04-02T15:13:14.381721Z","shell.execute_reply":"2022-04-02T15:13:14.40524Z"},"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":"2022-04-02T15:13:27.278648Z","iopub.execute_input":"2022-04-02T15:13:27.278999Z","iopub.status.idle":"2022-04-02T15:13:28.86587Z","shell.execute_reply.started":"2022-04-02T15:13:27.278966Z","shell.execute_reply":"2022-04-02T15:13:28.864703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y=to_categorical(y_train,3)\nval_y=to_categorical(y_val,3)\ntest_y=to_categorical(y_test,3)\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":"2022-04-02T15:13:50.535799Z","iopub.execute_input":"2022-04-02T15:13:50.536129Z","iopub.status.idle":"2022-04-02T15:13:58.216699Z","shell.execute_reply.started":"2022-04-02T15:13:50.536097Z","shell.execute_reply":"2022-04-02T15:13:58.215677Z"},"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":"2022-04-02T15:14:12.446161Z","iopub.execute_input":"2022-04-02T15:14:12.446856Z","iopub.status.idle":"2022-04-02T15:14:12.672773Z","shell.execute_reply.started":"2022-04-02T15:14:12.446816Z","shell.execute_reply":"2022-04-02T15:14:12.671909Z"},"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":"2022-04-02T15:14:28.082957Z","iopub.execute_input":"2022-04-02T15:14:28.083596Z","iopub.status.idle":"2022-04-02T15:14:28.32588Z","shell.execute_reply.started":"2022-04-02T15:14:28.083557Z","shell.execute_reply":"2022-04-02T15:14:28.324716Z"},"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":"2022-04-02T15:14:46.115829Z","iopub.execute_input":"2022-04-02T15:14:46.116206Z","iopub.status.idle":"2022-04-02T15:14:46.56953Z","shell.execute_reply.started":"2022-04-02T15:14:46.116168Z","shell.execute_reply":"2022-04-02T15:14:46.568487Z"},"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":"2022-04-02T15:15:10.159343Z","iopub.execute_input":"2022-04-02T15:15:10.159681Z","iopub.status.idle":"2022-04-02T15:15:10.489371Z","shell.execute_reply.started":"2022-04-02T15:15:10.159638Z","shell.execute_reply":"2022-04-02T15:15:10.488357Z"},"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":"2022-04-02T15:15:30.94007Z","iopub.execute_input":"2022-04-02T15:15:30.940393Z","iopub.status.idle":"2022-04-02T15:15:31.611083Z","shell.execute_reply.started":"2022-04-02T15:15:30.940361Z","shell.execute_reply":"2022-04-02T15:15:31.61003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mlpc = MLPClassifier()\nmlpc.fit(train_features, y_train)\nplot_confusion_matrix(mlpc, test_features, y_test)","metadata":{"execution":{"iopub.status.busy":"2022-04-02T15:15:49.342714Z","iopub.execute_input":"2022-04-02T15:15:49.343428Z","iopub.status.idle":"2022-04-02T15:15:50.053697Z","shell.execute_reply.started":"2022-04-02T15:15:49.343373Z","shell.execute_reply":"2022-04-02T15:15:50.05271Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}