{"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":"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\nimport warnings\nwarnings.filterwarnings('ignore')\n\nprint(\"All modules have been imported\")","metadata":{"execution":{"iopub.status.busy":"2023-05-01T14:51:31.553295Z","iopub.execute_input":"2023-05-01T14:51:31.55396Z","iopub.status.idle":"2023-05-01T14:51:40.603622Z","shell.execute_reply.started":"2023-05-01T14:51:31.553853Z","shell.execute_reply":"2023-05-01T14:51:40.602902Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:02:18.289792Z","iopub.execute_input":"2023-04-28T12:02:18.290538Z","iopub.status.idle":"2023-04-28T12:02:18.341227Z","shell.execute_reply.started":"2023-04-28T12:02:18.290499Z","shell.execute_reply":"2023-04-28T12:02:18.340326Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"info.level.value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-04-28T12:02:18.342635Z","iopub.execute_input":"2023-04-28T12:02:18.343216Z","iopub.status.idle":"2023-04-28T12:02:18.35588Z","shell.execute_reply.started":"2023-04-28T12:02:18.343171Z","shell.execute_reply":"2023-04-28T12:02:18.354986Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:02:18.357338Z","iopub.execute_input":"2023-04-28T12:02:18.357787Z","iopub.status.idle":"2023-04-28T12:02:18.622435Z","shell.execute_reply.started":"2023-04-28T12:02:18.357756Z","shell.execute_reply":"2023-04-28T12:02:18.621637Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sizes = info['level'].values\nsns.distplot(sizes, kde=False)","metadata":{"execution":{"iopub.status.busy":"2023-04-28T12:02:18.624719Z","iopub.execute_input":"2023-04-28T12:02:18.625049Z","iopub.status.idle":"2023-04-28T12:02:18.914241Z","shell.execute_reply.started":"2023-04-28T12:02:18.625019Z","shell.execute_reply":"2023-04-28T12:02:18.913436Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:02:18.915441Z","iopub.execute_input":"2023-04-28T12:02:18.915666Z","iopub.status.idle":"2023-04-28T12:02:40.064768Z","shell.execute_reply.started":"2023-04-28T12:02:18.915639Z","shell.execute_reply":"2023-04-28T12:02:40.06372Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:02:40.0662Z","iopub.execute_input":"2023-04-28T12:02:40.066535Z","iopub.status.idle":"2023-04-28T12:02:40.075587Z","shell.execute_reply.started":"2023-04-28T12:02:40.066493Z","shell.execute_reply":"2023-04-28T12:02:40.074695Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:02:40.077231Z","iopub.execute_input":"2023-04-28T12:02:40.077791Z","iopub.status.idle":"2023-04-28T12:02:40.852522Z","shell.execute_reply.started":"2023-04-28T12:02:40.077733Z","shell.execute_reply":"2023-04-28T12:02:40.851484Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y.shape","metadata":{"execution":{"iopub.status.busy":"2023-04-28T12:02:40.854007Z","iopub.execute_input":"2023-04-28T12:02:40.854333Z","iopub.status.idle":"2023-04-28T12:02:40.861965Z","shell.execute_reply.started":"2023-04-28T12:02:40.854283Z","shell.execute_reply":"2023-04-28T12:02:40.860896Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:02:40.863271Z","iopub.execute_input":"2023-04-28T12:02:40.86353Z","iopub.status.idle":"2023-04-28T12:02:42.594445Z","shell.execute_reply.started":"2023-04-28T12:02:40.863499Z","shell.execute_reply":"2023-04-28T12:02:42.593308Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"Y1=pd.DataFrame(Y)\nY1.value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-04-28T12:02:42.59563Z","iopub.execute_input":"2023-04-28T12:02:42.595881Z","iopub.status.idle":"2023-04-28T12:02:42.608382Z","shell.execute_reply.started":"2023-04-28T12:02:42.59585Z","shell.execute_reply":"2023-04-28T12:02:42.607305Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:02:42.609724Z","iopub.execute_input":"2023-04-28T12:02:42.609997Z","iopub.status.idle":"2023-04-28T12:02:43.237107Z","shell.execute_reply.started":"2023-04-28T12:02:42.609967Z","shell.execute_reply":"2023-04-28T12:02:43.236311Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:02:43.238068Z","iopub.execute_input":"2023-04-28T12:02:43.238299Z","iopub.status.idle":"2023-04-28T12:02:43.246706Z","shell.execute_reply.started":"2023-04-28T12:02:43.238271Z","shell.execute_reply":"2023-04-28T12:02:43.24567Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:02:43.251229Z","iopub.execute_input":"2023-04-28T12:02:43.25151Z","iopub.status.idle":"2023-04-28T12:02:43.267285Z","shell.execute_reply.started":"2023-04-28T12:02:43.251477Z","shell.execute_reply":"2023-04-28T12:02:43.266109Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:02:43.269077Z","iopub.execute_input":"2023-04-28T12:02:43.269948Z","iopub.status.idle":"2023-04-28T12:02:43.28269Z","shell.execute_reply.started":"2023-04-28T12:02:43.269903Z","shell.execute_reply":"2023-04-28T12:02:43.28178Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:02:43.284085Z","iopub.execute_input":"2023-04-28T12:02:43.284803Z","iopub.status.idle":"2023-04-28T12:04:36.28479Z","shell.execute_reply.started":"2023-04-28T12:02:43.284756Z","shell.execute_reply":"2023-04-28T12:04:36.28397Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:04:36.286402Z","iopub.execute_input":"2023-04-28T12:04:36.286654Z","iopub.status.idle":"2023-04-28T12:04:36.306953Z","shell.execute_reply.started":"2023-04-28T12:04:36.286592Z","shell.execute_reply":"2023-04-28T12:04:36.305876Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:04:36.308096Z","iopub.execute_input":"2023-04-28T12:04:36.308319Z","iopub.status.idle":"2023-04-28T12:04:37.470417Z","shell.execute_reply.started":"2023-04-28T12:04:36.308292Z","shell.execute_reply":"2023-04-28T12:04:37.469284Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:04:37.472806Z","iopub.execute_input":"2023-04-28T12:04:37.473532Z","iopub.status.idle":"2023-04-28T12:04:44.659901Z","shell.execute_reply.started":"2023-04-28T12:04:37.473469Z","shell.execute_reply":"2023-04-28T12:04:44.658859Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:04:44.662941Z","iopub.execute_input":"2023-04-28T12:04:44.663175Z","iopub.status.idle":"2023-04-28T12:04:44.895199Z","shell.execute_reply.started":"2023-04-28T12:04:44.663147Z","shell.execute_reply":"2023-04-28T12:04:44.894446Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:04:44.896248Z","iopub.execute_input":"2023-04-28T12:04:44.896732Z","iopub.status.idle":"2023-04-28T12:04:45.170879Z","shell.execute_reply.started":"2023-04-28T12:04:44.896696Z","shell.execute_reply":"2023-04-28T12:04:45.169957Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:04:45.172379Z","iopub.execute_input":"2023-04-28T12:04:45.172719Z","iopub.status.idle":"2023-04-28T12:04:45.643549Z","shell.execute_reply.started":"2023-04-28T12:04:45.172676Z","shell.execute_reply":"2023-04-28T12:04:45.642756Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:04:45.644831Z","iopub.execute_input":"2023-04-28T12:04:45.645267Z","iopub.status.idle":"2023-04-28T12:04:46.251971Z","shell.execute_reply.started":"2023-04-28T12:04:45.645227Z","shell.execute_reply":"2023-04-28T12:04:46.25097Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:04:46.253313Z","iopub.execute_input":"2023-04-28T12:04:46.253544Z","iopub.status.idle":"2023-04-28T12:04:46.975693Z","shell.execute_reply.started":"2023-04-28T12:04:46.253515Z","shell.execute_reply":"2023-04-28T12:04:46.974696Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:04:46.977095Z","iopub.execute_input":"2023-04-28T12:04:46.97743Z","iopub.status.idle":"2023-04-28T12:04:47.502251Z","shell.execute_reply.started":"2023-04-28T12:04:46.977384Z","shell.execute_reply":"2023-04-28T12:04:47.501645Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:04:47.503596Z","iopub.execute_input":"2023-04-28T12:04:47.504041Z","iopub.status.idle":"2023-04-28T12:10:36.589939Z","shell.execute_reply.started":"2023-04-28T12:04:47.504009Z","shell.execute_reply":"2023-04-28T12:10:36.58903Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:10:36.591174Z","iopub.execute_input":"2023-04-28T12:10:36.591427Z","iopub.status.idle":"2023-04-28T12:10:36.615284Z","shell.execute_reply.started":"2023-04-28T12:10:36.591396Z","shell.execute_reply":"2023-04-28T12:10:36.614311Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:10:36.61651Z","iopub.execute_input":"2023-04-28T12:10:36.616764Z","iopub.status.idle":"2023-04-28T12:10:37.810235Z","shell.execute_reply.started":"2023-04-28T12:10:36.616735Z","shell.execute_reply":"2023-04-28T12:10:37.8092Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:10:37.812009Z","iopub.execute_input":"2023-04-28T12:10:37.81266Z","iopub.status.idle":"2023-04-28T12:10:44.165341Z","shell.execute_reply.started":"2023-04-28T12:10:37.812588Z","shell.execute_reply":"2023-04-28T12:10:44.164579Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:10:44.1666Z","iopub.execute_input":"2023-04-28T12:10:44.167487Z","iopub.status.idle":"2023-04-28T12:10:44.388932Z","shell.execute_reply.started":"2023-04-28T12:10:44.167441Z","shell.execute_reply":"2023-04-28T12:10:44.388185Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:10:44.390349Z","iopub.execute_input":"2023-04-28T12:10:44.390571Z","iopub.status.idle":"2023-04-28T12:10:44.617259Z","shell.execute_reply.started":"2023-04-28T12:10:44.390544Z","shell.execute_reply":"2023-04-28T12:10:44.616386Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:10:44.618633Z","iopub.execute_input":"2023-04-28T12:10:44.620151Z","iopub.status.idle":"2023-04-28T12:10:45.02439Z","shell.execute_reply.started":"2023-04-28T12:10:44.620098Z","shell.execute_reply":"2023-04-28T12:10:45.023764Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:10:45.025558Z","iopub.execute_input":"2023-04-28T12:10:45.026333Z","iopub.status.idle":"2023-04-28T12:10:45.322937Z","shell.execute_reply.started":"2023-04-28T12:10:45.026286Z","shell.execute_reply":"2023-04-28T12:10:45.321896Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:10:45.324333Z","iopub.execute_input":"2023-04-28T12:10:45.324668Z","iopub.status.idle":"2023-04-28T12:10:45.953319Z","shell.execute_reply.started":"2023-04-28T12:10:45.324624Z","shell.execute_reply":"2023-04-28T12:10:45.952584Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:10:45.954573Z","iopub.execute_input":"2023-04-28T12:10:45.95496Z","iopub.status.idle":"2023-04-28T12:10:46.394535Z","shell.execute_reply.started":"2023-04-28T12:10:45.954922Z","shell.execute_reply":"2023-04-28T12:10:46.393576Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:10:46.396197Z","iopub.execute_input":"2023-04-28T12:10:46.397185Z","iopub.status.idle":"2023-04-28T12:18:08.254763Z","shell.execute_reply.started":"2023-04-28T12:10:46.397127Z","shell.execute_reply":"2023-04-28T12:18:08.253849Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:18:08.257834Z","iopub.execute_input":"2023-04-28T12:18:08.258521Z","iopub.status.idle":"2023-04-28T12:18:08.278554Z","shell.execute_reply.started":"2023-04-28T12:18:08.258457Z","shell.execute_reply":"2023-04-28T12:18:08.277949Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:18:08.279904Z","iopub.execute_input":"2023-04-28T12:18:08.280244Z","iopub.status.idle":"2023-04-28T12:18:09.481184Z","shell.execute_reply.started":"2023-04-28T12:18:08.280216Z","shell.execute_reply":"2023-04-28T12:18:09.480067Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:18:09.483314Z","iopub.execute_input":"2023-04-28T12:18:09.484014Z","iopub.status.idle":"2023-04-28T12:18:16.685973Z","shell.execute_reply.started":"2023-04-28T12:18:09.483954Z","shell.execute_reply":"2023-04-28T12:18:16.685072Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:18:16.687133Z","iopub.execute_input":"2023-04-28T12:18:16.687427Z","iopub.status.idle":"2023-04-28T12:18:16.963716Z","shell.execute_reply.started":"2023-04-28T12:18:16.687399Z","shell.execute_reply":"2023-04-28T12:18:16.962839Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:18:16.971785Z","iopub.execute_input":"2023-04-28T12:18:16.972077Z","iopub.status.idle":"2023-04-28T12:18:17.270685Z","shell.execute_reply.started":"2023-04-28T12:18:16.972043Z","shell.execute_reply":"2023-04-28T12:18:17.269652Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:18:17.271862Z","iopub.execute_input":"2023-04-28T12:18:17.272094Z","iopub.status.idle":"2023-04-28T12:18:17.750489Z","shell.execute_reply.started":"2023-04-28T12:18:17.272066Z","shell.execute_reply":"2023-04-28T12:18:17.749625Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:18:17.751943Z","iopub.execute_input":"2023-04-28T12:18:17.75256Z","iopub.status.idle":"2023-04-28T12:18:18.115446Z","shell.execute_reply.started":"2023-04-28T12:18:17.752524Z","shell.execute_reply":"2023-04-28T12:18:18.114526Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:18:18.116822Z","iopub.execute_input":"2023-04-28T12:18:18.117076Z","iopub.status.idle":"2023-04-28T12:18:18.815963Z","shell.execute_reply.started":"2023-04-28T12:18:18.117045Z","shell.execute_reply":"2023-04-28T12:18:18.815029Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:18:18.817501Z","iopub.execute_input":"2023-04-28T12:18:18.817879Z","iopub.status.idle":"2023-04-28T12:18:19.310695Z","shell.execute_reply.started":"2023-04-28T12:18:18.817847Z","shell.execute_reply":"2023-04-28T12:18:19.310039Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:18:19.31455Z","iopub.execute_input":"2023-04-28T12:18:19.315897Z","iopub.status.idle":"2023-04-28T12:21:46.710395Z","shell.execute_reply.started":"2023-04-28T12:18:19.315843Z","shell.execute_reply":"2023-04-28T12:21:46.709585Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:21:46.711756Z","iopub.execute_input":"2023-04-28T12:21:46.711998Z","iopub.status.idle":"2023-04-28T12:21:46.731416Z","shell.execute_reply.started":"2023-04-28T12:21:46.71197Z","shell.execute_reply":"2023-04-28T12:21:46.730517Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:21:46.732795Z","iopub.execute_input":"2023-04-28T12:21:46.733034Z","iopub.status.idle":"2023-04-28T12:21:47.87782Z","shell.execute_reply.started":"2023-04-28T12:21:46.733006Z","shell.execute_reply":"2023-04-28T12:21:47.876943Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:21:47.879656Z","iopub.execute_input":"2023-04-28T12:21:47.880315Z","iopub.status.idle":"2023-04-28T12:21:54.893985Z","shell.execute_reply.started":"2023-04-28T12:21:47.88027Z","shell.execute_reply":"2023-04-28T12:21:54.892827Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:21:54.895488Z","iopub.execute_input":"2023-04-28T12:21:54.895839Z","iopub.status.idle":"2023-04-28T12:21:55.198762Z","shell.execute_reply.started":"2023-04-28T12:21:54.895797Z","shell.execute_reply":"2023-04-28T12:21:55.197572Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:21:55.20049Z","iopub.execute_input":"2023-04-28T12:21:55.200765Z","iopub.status.idle":"2023-04-28T12:21:55.49031Z","shell.execute_reply.started":"2023-04-28T12:21:55.200733Z","shell.execute_reply":"2023-04-28T12:21:55.48944Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:21:55.491679Z","iopub.execute_input":"2023-04-28T12:21:55.492474Z","iopub.status.idle":"2023-04-28T12:21:55.963627Z","shell.execute_reply.started":"2023-04-28T12:21:55.492422Z","shell.execute_reply":"2023-04-28T12:21:55.962678Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:21:55.964731Z","iopub.execute_input":"2023-04-28T12:21:55.964955Z","iopub.status.idle":"2023-04-28T12:21:56.338331Z","shell.execute_reply.started":"2023-04-28T12:21:55.964927Z","shell.execute_reply":"2023-04-28T12:21:56.337565Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:21:56.33976Z","iopub.execute_input":"2023-04-28T12:21:56.340085Z","iopub.status.idle":"2023-04-28T12:21:57.045072Z","shell.execute_reply.started":"2023-04-28T12:21:56.340043Z","shell.execute_reply":"2023-04-28T12:21:57.043648Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:21:57.046919Z","iopub.execute_input":"2023-04-28T12:21:57.047696Z","iopub.status.idle":"2023-04-28T12:21:57.885044Z","shell.execute_reply.started":"2023-04-28T12:21:57.047654Z","shell.execute_reply":"2023-04-28T12:21:57.884181Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:21:57.886268Z","iopub.execute_input":"2023-04-28T12:21:57.886579Z","iopub.status.idle":"2023-04-28T12:22:16.3934Z","shell.execute_reply.started":"2023-04-28T12:21:57.88655Z","shell.execute_reply":"2023-04-28T12:22:16.392565Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:22:16.394802Z","iopub.execute_input":"2023-04-28T12:22:16.39507Z","iopub.status.idle":"2023-04-28T12:22:16.414848Z","shell.execute_reply.started":"2023-04-28T12:22:16.395041Z","shell.execute_reply":"2023-04-28T12:22:16.413811Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:22:16.416193Z","iopub.execute_input":"2023-04-28T12:22:16.416419Z","iopub.status.idle":"2023-04-28T12:22:17.583028Z","shell.execute_reply.started":"2023-04-28T12:22:16.416392Z","shell.execute_reply":"2023-04-28T12:22:17.581945Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:22:17.584794Z","iopub.execute_input":"2023-04-28T12:22:17.585525Z","iopub.status.idle":"2023-04-28T12:22:24.595977Z","shell.execute_reply.started":"2023-04-28T12:22:17.58547Z","shell.execute_reply":"2023-04-28T12:22:24.595302Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:22:24.597497Z","iopub.execute_input":"2023-04-28T12:22:24.598039Z","iopub.status.idle":"2023-04-28T12:22:24.876927Z","shell.execute_reply.started":"2023-04-28T12:22:24.597992Z","shell.execute_reply":"2023-04-28T12:22:24.87629Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:22:24.878004Z","iopub.execute_input":"2023-04-28T12:22:24.878317Z","iopub.status.idle":"2023-04-28T12:22:25.165754Z","shell.execute_reply.started":"2023-04-28T12:22:24.878289Z","shell.execute_reply":"2023-04-28T12:22:25.165119Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:22:25.166705Z","iopub.execute_input":"2023-04-28T12:22:25.167356Z","iopub.status.idle":"2023-04-28T12:22:25.649187Z","shell.execute_reply.started":"2023-04-28T12:22:25.167321Z","shell.execute_reply":"2023-04-28T12:22:25.648297Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:22:25.650363Z","iopub.execute_input":"2023-04-28T12:22:25.650628Z","iopub.status.idle":"2023-04-28T12:22:26.017186Z","shell.execute_reply.started":"2023-04-28T12:22:25.650585Z","shell.execute_reply":"2023-04-28T12:22:26.016529Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:22:26.018288Z","iopub.execute_input":"2023-04-28T12:22:26.018732Z","iopub.status.idle":"2023-04-28T12:22:26.727567Z","shell.execute_reply.started":"2023-04-28T12:22:26.018684Z","shell.execute_reply":"2023-04-28T12:22:26.726683Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:22:26.728934Z","iopub.execute_input":"2023-04-28T12:22:26.729536Z","iopub.status.idle":"2023-04-28T12:22:27.225281Z","shell.execute_reply.started":"2023-04-28T12:22:26.729488Z","shell.execute_reply":"2023-04-28T12:22:27.22457Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:22:27.226562Z","iopub.execute_input":"2023-04-28T12:22:27.227343Z","iopub.status.idle":"2023-04-28T12:22:46.820979Z","shell.execute_reply.started":"2023-04-28T12:22:27.227307Z","shell.execute_reply":"2023-04-28T12:22:46.820095Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:22:46.823467Z","iopub.execute_input":"2023-04-28T12:22:46.824281Z","iopub.status.idle":"2023-04-28T12:22:46.842171Z","shell.execute_reply.started":"2023-04-28T12:22:46.824236Z","shell.execute_reply":"2023-04-28T12:22:46.841329Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:22:46.8438Z","iopub.execute_input":"2023-04-28T12:22:46.844058Z","iopub.status.idle":"2023-04-28T12:22:47.94708Z","shell.execute_reply.started":"2023-04-28T12:22:46.844028Z","shell.execute_reply":"2023-04-28T12:22:47.946009Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:22:47.94895Z","iopub.execute_input":"2023-04-28T12:22:47.949527Z","iopub.status.idle":"2023-04-28T12:22:55.191423Z","shell.execute_reply.started":"2023-04-28T12:22:47.949472Z","shell.execute_reply":"2023-04-28T12:22:55.190723Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:22:55.193295Z","iopub.execute_input":"2023-04-28T12:22:55.193634Z","iopub.status.idle":"2023-04-28T12:22:55.477855Z","shell.execute_reply.started":"2023-04-28T12:22:55.193566Z","shell.execute_reply":"2023-04-28T12:22:55.476998Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:22:55.47913Z","iopub.execute_input":"2023-04-28T12:22:55.479352Z","iopub.status.idle":"2023-04-28T12:22:55.790601Z","shell.execute_reply.started":"2023-04-28T12:22:55.479324Z","shell.execute_reply":"2023-04-28T12:22:55.789504Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:22:55.792475Z","iopub.execute_input":"2023-04-28T12:22:55.792815Z","iopub.status.idle":"2023-04-28T12:22:56.271719Z","shell.execute_reply.started":"2023-04-28T12:22:55.792772Z","shell.execute_reply":"2023-04-28T12:22:56.270781Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:22:56.2731Z","iopub.execute_input":"2023-04-28T12:22:56.273421Z","iopub.status.idle":"2023-04-28T12:22:56.646627Z","shell.execute_reply.started":"2023-04-28T12:22:56.273386Z","shell.execute_reply":"2023-04-28T12:22:56.645771Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:22:56.647848Z","iopub.execute_input":"2023-04-28T12:22:56.648074Z","iopub.status.idle":"2023-04-28T12:22:57.374145Z","shell.execute_reply.started":"2023-04-28T12:22:56.648046Z","shell.execute_reply":"2023-04-28T12:22:57.373416Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:22:57.375419Z","iopub.execute_input":"2023-04-28T12:22:57.375654Z","iopub.status.idle":"2023-04-28T12:22:57.878343Z","shell.execute_reply.started":"2023-04-28T12:22:57.375626Z","shell.execute_reply":"2023-04-28T12:22:57.877697Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:22:57.879478Z","iopub.execute_input":"2023-04-28T12:22:57.879824Z","iopub.status.idle":"2023-04-28T12:23:17.764005Z","shell.execute_reply.started":"2023-04-28T12:22:57.87979Z","shell.execute_reply":"2023-04-28T12:23:17.763189Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:23:17.765702Z","iopub.execute_input":"2023-04-28T12:23:17.766051Z","iopub.status.idle":"2023-04-28T12:23:17.785678Z","shell.execute_reply.started":"2023-04-28T12:23:17.766012Z","shell.execute_reply":"2023-04-28T12:23:17.784376Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:23:17.787384Z","iopub.execute_input":"2023-04-28T12:23:17.787738Z","iopub.status.idle":"2023-04-28T12:23:18.910592Z","shell.execute_reply.started":"2023-04-28T12:23:17.787693Z","shell.execute_reply":"2023-04-28T12:23:18.908948Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:23:18.912502Z","iopub.execute_input":"2023-04-28T12:23:18.91312Z","iopub.status.idle":"2023-04-28T12:23:25.874101Z","shell.execute_reply.started":"2023-04-28T12:23:18.913071Z","shell.execute_reply":"2023-04-28T12:23:25.873267Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:23:25.875396Z","iopub.execute_input":"2023-04-28T12:23:25.875623Z","iopub.status.idle":"2023-04-28T12:23:26.152689Z","shell.execute_reply.started":"2023-04-28T12:23:25.875583Z","shell.execute_reply":"2023-04-28T12:23:26.151821Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:23:26.154573Z","iopub.execute_input":"2023-04-28T12:23:26.154854Z","iopub.status.idle":"2023-04-28T12:23:26.445307Z","shell.execute_reply.started":"2023-04-28T12:23:26.154822Z","shell.execute_reply":"2023-04-28T12:23:26.444401Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:23:26.446432Z","iopub.execute_input":"2023-04-28T12:23:26.446668Z","iopub.status.idle":"2023-04-28T12:23:26.918397Z","shell.execute_reply.started":"2023-04-28T12:23:26.446633Z","shell.execute_reply":"2023-04-28T12:23:26.91731Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:23:26.919573Z","iopub.execute_input":"2023-04-28T12:23:26.919833Z","iopub.status.idle":"2023-04-28T12:23:27.259691Z","shell.execute_reply.started":"2023-04-28T12:23:26.919801Z","shell.execute_reply":"2023-04-28T12:23:27.258771Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:23:27.261032Z","iopub.execute_input":"2023-04-28T12:23:27.261527Z","iopub.status.idle":"2023-04-28T12:23:27.903933Z","shell.execute_reply.started":"2023-04-28T12:23:27.261483Z","shell.execute_reply":"2023-04-28T12:23:27.903051Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:23:27.905279Z","iopub.execute_input":"2023-04-28T12:23:27.905923Z","iopub.status.idle":"2023-04-28T12:23:28.308931Z","shell.execute_reply.started":"2023-04-28T12:23:27.905886Z","shell.execute_reply":"2023-04-28T12:23:28.308018Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:23:28.310409Z","iopub.execute_input":"2023-04-28T12:23:28.310757Z","iopub.status.idle":"2023-04-28T12:26:12.45696Z","shell.execute_reply.started":"2023-04-28T12:23:28.310709Z","shell.execute_reply":"2023-04-28T12:26:12.455964Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:26:12.458757Z","iopub.execute_input":"2023-04-28T12:26:12.459017Z","iopub.status.idle":"2023-04-28T12:26:12.480265Z","shell.execute_reply.started":"2023-04-28T12:26:12.458987Z","shell.execute_reply":"2023-04-28T12:26:12.479202Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:26:12.481966Z","iopub.execute_input":"2023-04-28T12:26:12.482214Z","iopub.status.idle":"2023-04-28T12:26:13.747775Z","shell.execute_reply.started":"2023-04-28T12:26:12.482186Z","shell.execute_reply":"2023-04-28T12:26:13.746636Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:26:13.749866Z","iopub.execute_input":"2023-04-28T12:26:13.750732Z","iopub.status.idle":"2023-04-28T12:26:21.440601Z","shell.execute_reply.started":"2023-04-28T12:26:13.750654Z","shell.execute_reply":"2023-04-28T12:26:21.43967Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:26:21.442038Z","iopub.execute_input":"2023-04-28T12:26:21.442274Z","iopub.status.idle":"2023-04-28T12:26:21.658378Z","shell.execute_reply.started":"2023-04-28T12:26:21.442245Z","shell.execute_reply":"2023-04-28T12:26:21.657339Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:26:21.659829Z","iopub.execute_input":"2023-04-28T12:26:21.660465Z","iopub.status.idle":"2023-04-28T12:26:21.960066Z","shell.execute_reply.started":"2023-04-28T12:26:21.66043Z","shell.execute_reply":"2023-04-28T12:26:21.959132Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:26:21.96117Z","iopub.execute_input":"2023-04-28T12:26:21.961389Z","iopub.status.idle":"2023-04-28T12:26:22.440601Z","shell.execute_reply.started":"2023-04-28T12:26:21.961361Z","shell.execute_reply":"2023-04-28T12:26:22.439673Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:26:22.441805Z","iopub.execute_input":"2023-04-28T12:26:22.442026Z","iopub.status.idle":"2023-04-28T12:26:22.818514Z","shell.execute_reply.started":"2023-04-28T12:26:22.441998Z","shell.execute_reply":"2023-04-28T12:26:22.81766Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:26:22.820069Z","iopub.execute_input":"2023-04-28T12:26:22.820865Z","iopub.status.idle":"2023-04-28T12:26:23.612759Z","shell.execute_reply.started":"2023-04-28T12:26:22.820813Z","shell.execute_reply":"2023-04-28T12:26:23.612112Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:26:23.614177Z","iopub.execute_input":"2023-04-28T12:26:23.615025Z","iopub.status.idle":"2023-04-28T12:26:24.180436Z","shell.execute_reply.started":"2023-04-28T12:26:23.614981Z","shell.execute_reply":"2023-04-28T12:26:24.179786Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:26:24.181709Z","iopub.execute_input":"2023-04-28T12:26:24.182579Z","iopub.status.idle":"2023-04-28T12:29:07.478183Z","shell.execute_reply.started":"2023-04-28T12:26:24.182535Z","shell.execute_reply":"2023-04-28T12:29:07.477474Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:29:07.479629Z","iopub.execute_input":"2023-04-28T12:29:07.479935Z","iopub.status.idle":"2023-04-28T12:29:07.501468Z","shell.execute_reply.started":"2023-04-28T12:29:07.479894Z","shell.execute_reply":"2023-04-28T12:29:07.500432Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:29:07.505048Z","iopub.execute_input":"2023-04-28T12:29:07.505292Z","iopub.status.idle":"2023-04-28T12:29:08.704206Z","shell.execute_reply.started":"2023-04-28T12:29:07.505263Z","shell.execute_reply":"2023-04-28T12:29:08.694356Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:29:08.706634Z","iopub.execute_input":"2023-04-28T12:29:08.712462Z","iopub.status.idle":"2023-04-28T12:29:15.756179Z","shell.execute_reply.started":"2023-04-28T12:29:08.712375Z","shell.execute_reply":"2023-04-28T12:29:15.754989Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:29:15.757519Z","iopub.execute_input":"2023-04-28T12:29:15.757923Z","iopub.status.idle":"2023-04-28T12:29:16.043953Z","shell.execute_reply.started":"2023-04-28T12:29:15.757884Z","shell.execute_reply":"2023-04-28T12:29:16.042973Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:29:16.046519Z","iopub.execute_input":"2023-04-28T12:29:16.047068Z","iopub.status.idle":"2023-04-28T12:29:16.343056Z","shell.execute_reply.started":"2023-04-28T12:29:16.047022Z","shell.execute_reply":"2023-04-28T12:29:16.342009Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:29:16.344068Z","iopub.execute_input":"2023-04-28T12:29:16.344291Z","iopub.status.idle":"2023-04-28T12:29:16.834952Z","shell.execute_reply.started":"2023-04-28T12:29:16.344263Z","shell.execute_reply":"2023-04-28T12:29:16.833931Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:29:16.836411Z","iopub.execute_input":"2023-04-28T12:29:16.837296Z","iopub.status.idle":"2023-04-28T12:29:17.205134Z","shell.execute_reply.started":"2023-04-28T12:29:16.83723Z","shell.execute_reply":"2023-04-28T12:29:17.204265Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:29:17.206834Z","iopub.execute_input":"2023-04-28T12:29:17.207213Z","iopub.status.idle":"2023-04-28T12:29:17.917516Z","shell.execute_reply.started":"2023-04-28T12:29:17.207168Z","shell.execute_reply":"2023-04-28T12:29:17.916885Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:29:17.919046Z","iopub.execute_input":"2023-04-28T12:29:17.919586Z","iopub.status.idle":"2023-04-28T12:29:18.46192Z","shell.execute_reply.started":"2023-04-28T12:29:17.919538Z","shell.execute_reply":"2023-04-28T12:29:18.461331Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:29:18.463101Z","iopub.execute_input":"2023-04-28T12:29:18.463767Z","iopub.status.idle":"2023-04-28T12:32:02.885331Z","shell.execute_reply.started":"2023-04-28T12:29:18.463734Z","shell.execute_reply":"2023-04-28T12:32:02.884574Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:32:02.886644Z","iopub.execute_input":"2023-04-28T12:32:02.887292Z","iopub.status.idle":"2023-04-28T12:32:02.90469Z","shell.execute_reply.started":"2023-04-28T12:32:02.887257Z","shell.execute_reply":"2023-04-28T12:32:02.903829Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:32:02.90607Z","iopub.execute_input":"2023-04-28T12:32:02.906328Z","iopub.status.idle":"2023-04-28T12:32:04.04897Z","shell.execute_reply.started":"2023-04-28T12:32:02.906297Z","shell.execute_reply":"2023-04-28T12:32:04.047931Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:32:04.050697Z","iopub.execute_input":"2023-04-28T12:32:04.051309Z","iopub.status.idle":"2023-04-28T12:32:10.915943Z","shell.execute_reply.started":"2023-04-28T12:32:04.051237Z","shell.execute_reply":"2023-04-28T12:32:10.915044Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:32:10.917339Z","iopub.execute_input":"2023-04-28T12:32:10.917668Z","iopub.status.idle":"2023-04-28T12:32:11.19988Z","shell.execute_reply.started":"2023-04-28T12:32:10.917623Z","shell.execute_reply":"2023-04-28T12:32:11.199253Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:32:11.200872Z","iopub.execute_input":"2023-04-28T12:32:11.201343Z","iopub.status.idle":"2023-04-28T12:32:11.490244Z","shell.execute_reply.started":"2023-04-28T12:32:11.201311Z","shell.execute_reply":"2023-04-28T12:32:11.489646Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:32:11.49125Z","iopub.execute_input":"2023-04-28T12:32:11.491591Z","iopub.status.idle":"2023-04-28T12:32:11.966078Z","shell.execute_reply.started":"2023-04-28T12:32:11.491562Z","shell.execute_reply":"2023-04-28T12:32:11.965049Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:32:11.967679Z","iopub.execute_input":"2023-04-28T12:32:11.967931Z","iopub.status.idle":"2023-04-28T12:32:12.34315Z","shell.execute_reply.started":"2023-04-28T12:32:11.967901Z","shell.execute_reply":"2023-04-28T12:32:12.342492Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:32:12.344229Z","iopub.execute_input":"2023-04-28T12:32:12.34447Z","iopub.status.idle":"2023-04-28T12:32:13.109088Z","shell.execute_reply.started":"2023-04-28T12:32:12.344441Z","shell.execute_reply":"2023-04-28T12:32:13.108187Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:32:13.110328Z","iopub.execute_input":"2023-04-28T12:32:13.110573Z","iopub.status.idle":"2023-04-28T12:32:13.689434Z","shell.execute_reply.started":"2023-04-28T12:32:13.110541Z","shell.execute_reply":"2023-04-28T12:32:13.688468Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:32:13.691004Z","iopub.execute_input":"2023-04-28T12:32:13.691744Z","iopub.status.idle":"2023-04-28T12:34:55.399719Z","shell.execute_reply.started":"2023-04-28T12:32:13.691694Z","shell.execute_reply":"2023-04-28T12:34:55.398833Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:34:55.401486Z","iopub.execute_input":"2023-04-28T12:34:55.401781Z","iopub.status.idle":"2023-04-28T12:34:55.421716Z","shell.execute_reply.started":"2023-04-28T12:34:55.401748Z","shell.execute_reply":"2023-04-28T12:34:55.420905Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:34:55.423201Z","iopub.execute_input":"2023-04-28T12:34:55.423477Z","iopub.status.idle":"2023-04-28T12:34:56.555791Z","shell.execute_reply.started":"2023-04-28T12:34:55.423395Z","shell.execute_reply":"2023-04-28T12:34:56.554639Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:34:56.55785Z","iopub.execute_input":"2023-04-28T12:34:56.558999Z","iopub.status.idle":"2023-04-28T12:35:04.755666Z","shell.execute_reply.started":"2023-04-28T12:34:56.558932Z","shell.execute_reply":"2023-04-28T12:35:04.754709Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:35:04.757197Z","iopub.execute_input":"2023-04-28T12:35:04.757852Z","iopub.status.idle":"2023-04-28T12:35:04.979616Z","shell.execute_reply.started":"2023-04-28T12:35:04.757807Z","shell.execute_reply":"2023-04-28T12:35:04.978736Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:35:04.981722Z","iopub.execute_input":"2023-04-28T12:35:04.981963Z","iopub.status.idle":"2023-04-28T12:35:05.209459Z","shell.execute_reply.started":"2023-04-28T12:35:04.981934Z","shell.execute_reply":"2023-04-28T12:35:05.208577Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:35:05.219436Z","iopub.execute_input":"2023-04-28T12:35:05.219843Z","iopub.status.idle":"2023-04-28T12:35:05.642933Z","shell.execute_reply.started":"2023-04-28T12:35:05.219793Z","shell.execute_reply":"2023-04-28T12:35:05.641982Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:35:05.64469Z","iopub.execute_input":"2023-04-28T12:35:05.645275Z","iopub.status.idle":"2023-04-28T12:35:05.948175Z","shell.execute_reply.started":"2023-04-28T12:35:05.645227Z","shell.execute_reply":"2023-04-28T12:35:05.947236Z"},"trusted":true},"outputs":[],"execution_count":null},{"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-04-28T12:35:05.949698Z","iopub.execute_input":"2023-04-28T12:35:05.950017Z","iopub.status.idle":"2023-04-28T12:35:06.571435Z","shell.execute_reply.started":"2023-04-28T12:35:05.949976Z","shell.execute_reply":"2023-04-28T12:35:06.570524Z"},"trusted":true},"outputs":[],"execution_count":null},{"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":"2023-04-28T12:35:06.572887Z","iopub.execute_input":"2023-04-28T12:35:06.573827Z","iopub.status.idle":"2023-04-28T12:35:07.029511Z","shell.execute_reply.started":"2023-04-28T12:35:06.573776Z","shell.execute_reply":"2023-04-28T12:35:07.028676Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{},"outputs":[],"execution_count":null}]}