{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":16880,"databundleVersionId":858837,"sourceType":"competition"},{"sourceId":924245,"sourceType":"datasetVersion","datasetId":464091}],"dockerImageVersionId":29845,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        os.path.join(dirname, filename)\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-10-05T02:33:03.734351Z","iopub.execute_input":"2024-10-05T02:33:03.734684Z","iopub.status.idle":"2024-10-05T02:33:19.507154Z","shell.execute_reply.started":"2024-10-05T02:33:03.734636Z","shell.execute_reply":"2024-10-05T02:33:19.506223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_path = '/kaggle/input/deepfake-faces/metadata.csv'","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:33:23.081603Z","iopub.execute_input":"2024-10-05T02:33:23.081909Z","iopub.status.idle":"2024-10-05T02:33:23.085434Z","shell.execute_reply.started":"2024-10-05T02:33:23.081866Z","shell.execute_reply":"2024-10-05T02:33:23.084691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv(dataset_path)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:33:25.178333Z","iopub.execute_input":"2024-10-05T02:33:25.178675Z","iopub.status.idle":"2024-10-05T02:33:25.331419Z","shell.execute_reply.started":"2024-10-05T02:33:25.178615Z","shell.execute_reply":"2024-10-05T02:33:25.330566Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:33:26.734387Z","iopub.execute_input":"2024-10-05T02:33:26.734793Z","iopub.status.idle":"2024-10-05T02:33:26.760110Z","shell.execute_reply.started":"2024-10-05T02:33:26.734737Z","shell.execute_reply":"2024-10-05T02:33:26.759368Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.tail()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:33:27.581442Z","iopub.execute_input":"2024-10-05T02:33:27.581810Z","iopub.status.idle":"2024-10-05T02:33:27.592726Z","shell.execute_reply.started":"2024-10-05T02:33:27.581750Z","shell.execute_reply":"2024-10-05T02:33:27.592034Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:33:30.563476Z","iopub.execute_input":"2024-10-05T02:33:30.563831Z","iopub.status.idle":"2024-10-05T02:33:30.568484Z","shell.execute_reply.started":"2024-10-05T02:33:30.563774Z","shell.execute_reply":"2024-10-05T02:33:30.567808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def classify_features(df):\n    categorical_features = []\n    non_categorical_features = []\n    discrete_features = []\n    continuous_features = []\n\n    for column in df.columns:\n        if df[column].dtype == 'object':\n            if df[column].nunique() < 10:\n                categorical_features.append(column)\n            else:\n                non_categorical_features.append(column)\n        elif df[column].dtype in ['int64', 'float64']:\n            if df[column].nunique() < 10:\n                discrete_features.append(column)\n            else:\n                continuous_features.append(column)\n\n    return categorical_features, non_categorical_features, discrete_features, continuous_features","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:33:45.448523Z","iopub.execute_input":"2024-10-05T02:33:45.448879Z","iopub.status.idle":"2024-10-05T02:33:45.456902Z","shell.execute_reply.started":"2024-10-05T02:33:45.448821Z","shell.execute_reply":"2024-10-05T02:33:45.456144Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"categorical, non_categorical, discrete, continuous = classify_features(df)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:33:48.218302Z","iopub.execute_input":"2024-10-05T02:33:48.218653Z","iopub.status.idle":"2024-10-05T02:33:48.267834Z","shell.execute_reply.started":"2024-10-05T02:33:48.218601Z","shell.execute_reply":"2024-10-05T02:33:48.267078Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Categorical Features:\", categorical)\nprint(\"Non-Categorical Features:\", non_categorical)\nprint(\"Discrete Features:\", discrete)\nprint(\"Continuous Features:\", continuous)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:33:49.345338Z","iopub.execute_input":"2024-10-05T02:33:49.345660Z","iopub.status.idle":"2024-10-05T02:33:49.351032Z","shell.execute_reply.started":"2024-10-05T02:33:49.345616Z","shell.execute_reply":"2024-10-05T02:33:49.350274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in categorical:\n    print(i,':', df[i].unique())\n    print()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:33:56.685697Z","iopub.execute_input":"2024-10-05T02:33:56.686053Z","iopub.status.idle":"2024-10-05T02:33:56.695363Z","shell.execute_reply.started":"2024-10-05T02:33:56.685996Z","shell.execute_reply":"2024-10-05T02:33:56.694682Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in categorical:\n    print(df[i].value_counts())\n    print()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:33:58.603535Z","iopub.execute_input":"2024-10-05T02:33:58.603831Z","iopub.status.idle":"2024-10-05T02:33:58.629633Z","shell.execute_reply.started":"2024-10-05T02:33:58.603789Z","shell.execute_reply":"2024-10-05T02:33:58.628944Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np \nimport pandas as pd \nimport matplotlib.pyplot as plt\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:34:00.621794Z","iopub.execute_input":"2024-10-05T02:34:00.622189Z","iopub.status.idle":"2024-10-05T02:34:02.546886Z","shell.execute_reply.started":"2024-10-05T02:34:00.622119Z","shell.execute_reply":"2024-10-05T02:34:02.546185Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import warnings\nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:34:02.752771Z","iopub.execute_input":"2024-10-05T02:34:02.753096Z","iopub.status.idle":"2024-10-05T02:34:02.757376Z","shell.execute_reply.started":"2024-10-05T02:34:02.753052Z","shell.execute_reply":"2024-10-05T02:34:02.756382Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in categorical:\n    plt.figure(figsize=(15,6))\n    sns.countplot(x = df[i], data = df, palette = 'hls')\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:34:03.058655Z","iopub.execute_input":"2024-10-05T02:34:03.059172Z","iopub.status.idle":"2024-10-05T02:34:03.433470Z","shell.execute_reply.started":"2024-10-05T02:34:03.058969Z","shell.execute_reply":"2024-10-05T02:34:03.432077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"real_df = df[df[\"label\"] == \"REAL\"]\nfake_df = df[df[\"label\"] == \"FAKE\"]\nsample_size = 10000\n\nreal_df = real_df.sample(sample_size, random_state=42)\nfake_df = fake_df.sample(sample_size, random_state=42)\n\nsample_meta = pd.concat([real_df, fake_df])","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:34:31.084514Z","iopub.execute_input":"2024-10-05T02:34:31.085030Z","iopub.status.idle":"2024-10-05T02:34:31.139217Z","shell.execute_reply.started":"2024-10-05T02:34:31.084827Z","shell.execute_reply":"2024-10-05T02:34:31.138615Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\nTrain_set, Test_set = train_test_split(sample_meta,test_size=0.2,random_state=42,stratify=sample_meta['label'])\nTrain_set, Val_set  = train_test_split(Train_set,test_size=0.3,random_state=42,stratify=Train_set['label'])","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:34:33.703643Z","iopub.execute_input":"2024-10-05T02:34:33.704109Z","iopub.status.idle":"2024-10-05T02:34:33.772801Z","shell.execute_reply.started":"2024-10-05T02:34:33.703912Z","shell.execute_reply":"2024-10-05T02:34:33.772233Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Train_set.shape,Val_set.shape,Test_set.shape","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:34:37.251924Z","iopub.execute_input":"2024-10-05T02:34:37.252251Z","iopub.status.idle":"2024-10-05T02:34:37.258374Z","shell.execute_reply.started":"2024-10-05T02:34:37.252204Z","shell.execute_reply":"2024-10-05T02:34:37.257628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:36:27.825311Z","iopub.execute_input":"2024-10-05T02:36:27.825700Z","iopub.status.idle":"2024-10-05T02:36:28.044165Z","shell.execute_reply.started":"2024-10-05T02:36:27.825654Z","shell.execute_reply":"2024-10-05T02:36:28.043535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15,15))\nfor cur,i in enumerate(Train_set.index[25:50]):\n    plt.subplot(5,5,cur+1)\n    plt.xticks([])\n    plt.yticks([])\n    plt.grid(False)\n    \n    plt.imshow(cv2.imread('../input/deepfake-faces/faces_224/'+Train_set.loc[i,'videoname'][:-4]+'.jpg'))\n    \n    if(Train_set.loc[i,'label']=='FAKE'):\n        plt.xlabel('FAKE Image')\n    else:\n        plt.xlabel('REAL Image')\n        \nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:36:34.596660Z","iopub.execute_input":"2024-10-05T02:36:34.596968Z","iopub.status.idle":"2024-10-05T02:36:36.400151Z","shell.execute_reply.started":"2024-10-05T02:36:34.596924Z","shell.execute_reply":"2024-10-05T02:36:36.399454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def retreive_dataset(set_name):\n    images,labels=[],[]\n    for (img, imclass) in zip(set_name['videoname'], set_name['label']):\n        images.append(cv2.imread('../input/deepfake-faces/faces_224/'+img[:-4]+'.jpg'))\n        if(imclass=='FAKE'):\n            labels.append(1)\n        else:\n            labels.append(0)\n    \n    return np.array(images),np.array(labels)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:36:39.920843Z","iopub.execute_input":"2024-10-05T02:36:39.921146Z","iopub.status.idle":"2024-10-05T02:36:39.928163Z","shell.execute_reply.started":"2024-10-05T02:36:39.921104Z","shell.execute_reply":"2024-10-05T02:36:39.927042Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train,y_train=retreive_dataset(Train_set)\nX_val,y_val=retreive_dataset(Val_set)\nX_test,y_test=retreive_dataset(Test_set)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:36:43.728623Z","iopub.execute_input":"2024-10-05T02:36:43.728931Z","iopub.status.idle":"2024-10-05T02:38:49.811195Z","shell.execute_reply.started":"2024-10-05T02:36:43.728888Z","shell.execute_reply":"2024-10-05T02:38:49.810310Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras import layers, models\nfrom functools import partial","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:38:49.812910Z","iopub.execute_input":"2024-10-05T02:38:49.813141Z","iopub.status.idle":"2024-10-05T02:38:54.392029Z","shell.execute_reply.started":"2024-10-05T02:38:49.813102Z","shell.execute_reply":"2024-10-05T02:38:54.391126Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tf.random.set_seed(42)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:38:54.393344Z","iopub.execute_input":"2024-10-05T02:38:54.393622Z","iopub.status.idle":"2024-10-05T02:38:54.397269Z","shell.execute_reply.started":"2024-10-05T02:38:54.393577Z","shell.execute_reply":"2024-10-05T02:38:54.396528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Model Definition\nmodel = models.Sequential([\n    layers.Reshape((224, 224 * 3), input_shape=[224, 224, 3]),  # Reshaping to (224, 224*3) for RNN\n    layers.SimpleRNN(64, activation=\"relu\", return_sequences=False),\n    layers.BatchNormalization(),\n    layers.Dropout(0.5),\n    layers.Dense(units=64, activation=\"relu\", kernel_initializer=\"he_normal\"),\n    layers.BatchNormalization(),\n    layers.Dropout(0.5),\n    layers.Dense(units=1, activation=\"sigmoid\")\n])\n","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:41:47.213569Z","iopub.execute_input":"2024-10-05T02:41:47.213934Z","iopub.status.idle":"2024-10-05T02:41:51.212369Z","shell.execute_reply.started":"2024-10-05T02:41:47.213876Z","shell.execute_reply":"2024-10-05T02:41:51.211713Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"initial_learning_rate = 0.001\nlr_schedule = tf.keras.optimizers.schedules.ExponentialDecay(\n    initial_learning_rate, decay_steps=100000, decay_rate=0.96, staircase=True\n)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:41:54.583314Z","iopub.execute_input":"2024-10-05T02:41:54.583671Z","iopub.status.idle":"2024-10-05T02:41:54.588374Z","shell.execute_reply.started":"2024-10-05T02:41:54.583608Z","shell.execute_reply":"2024-10-05T02:41:54.587630Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=lr_schedule),\n              loss=\"binary_crossentropy\", metrics=[\"accuracy\"])","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:41:57.950239Z","iopub.execute_input":"2024-10-05T02:41:57.950581Z","iopub.status.idle":"2024-10-05T02:41:57.996280Z","shell.execute_reply.started":"2024-10-05T02:41:57.950518Z","shell.execute_reply":"2024-10-05T02:41:57.995595Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:42:03.030125Z","iopub.execute_input":"2024-10-05T02:42:03.030421Z","iopub.status.idle":"2024-10-05T02:42:03.037225Z","shell.execute_reply.started":"2024-10-05T02:42:03.030379Z","shell.execute_reply":"2024-10-05T02:42:03.036322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model.fit(\n    X_train, y_train,\n    epochs=10,  # Adjust as needed\n    batch_size=32,  # Adjust as needed\n    validation_data=(X_val, y_val),\n    verbose=1\n)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:42:06.637441Z","iopub.execute_input":"2024-10-05T02:42:06.637805Z","iopub.status.idle":"2024-10-05T02:48:33.494238Z","shell.execute_reply.started":"2024-10-05T02:42:06.637743Z","shell.execute_reply":"2024-10-05T02:48:33.493574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:48:39.968068Z","iopub.execute_input":"2024-10-05T02:48:39.968362Z","iopub.status.idle":"2024-10-05T02:48:42.977482Z","shell.execute_reply.started":"2024-10-05T02:48:39.968318Z","shell.execute_reply":"2024-10-05T02:48:42.976810Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"from sklearn.metrics import accuracy_score, f1_score, precision_score, recall_score, confusion_matrix, classification_report, roc_auc_score","metadata":{"execution":{"iopub.status.busy":"2024-03-30T03:21:32.271636Z","iopub.status.idle":"2024-03-30T03:21:32.272102Z","shell.execute_reply.started":"2024-03-30T03:21:32.271849Z","shell.execute_reply":"2024-03-30T03:21:32.27187Z"}}},{"cell_type":"code","source":"y_test_pred_binary = (y_pred > 0.5).astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:48:43.315816Z","iopub.execute_input":"2024-10-05T02:48:43.316115Z","iopub.status.idle":"2024-10-05T02:48:43.320329Z","shell.execute_reply.started":"2024-10-05T02:48:43.316073Z","shell.execute_reply":"2024-10-05T02:48:43.319485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train_pred = model.predict(X_train)\ny_train_pred_binary = (y_train_pred > 0.5).astype(int)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:48:44.669480Z","iopub.execute_input":"2024-10-05T02:48:44.669823Z","iopub.status.idle":"2024-10-05T02:48:52.493150Z","shell.execute_reply.started":"2024-10-05T02:48:44.669768Z","shell.execute_reply":"2024-10-05T02:48:52.492394Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score, f1_score, precision_score, recall_score, confusion_matrix, classification_report, roc_auc_score\n\ntrain_accuracy = accuracy_score(y_train, y_train_pred_binary)\nprint(f\"Training Accuracy: {train_accuracy * 100:.2f}%\")","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:48:52.495168Z","iopub.execute_input":"2024-10-05T02:48:52.495492Z","iopub.status.idle":"2024-10-05T02:48:52.502257Z","shell.execute_reply.started":"2024-10-05T02:48:52.495435Z","shell.execute_reply":"2024-10-05T02:48:52.501329Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_accuracy = accuracy_score(y_test, y_test_pred_binary)\nprint(f\"Test Accuracy: {test_accuracy * 100:.2f}%\")","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:48:52.503416Z","iopub.execute_input":"2024-10-05T02:48:52.503735Z","iopub.status.idle":"2024-10-05T02:48:52.512777Z","shell.execute_reply.started":"2024-10-05T02:48:52.503667Z","shell.execute_reply":"2024-10-05T02:48:52.511858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f1 = f1_score(y_test, y_test_pred_binary)\nprint(f\"F1 Score: {f1:.4f}\")\n\nprecision = precision_score(y_test, y_test_pred_binary)\nprint(f\"Precison: {precision:.4f}\")\n\nrecall = recall_score(y_test, y_test_pred_binary)\nprint(f\"Recall: {recall:.4f}\")\n\n# Calculate AUC-ROC\nauc_roc = roc_auc_score(y_test, y_test_pred_binary)\nprint(f\"AUC-ROC: {auc_roc:.4f}\")","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:48:52.514219Z","iopub.execute_input":"2024-10-05T02:48:52.514557Z","iopub.status.idle":"2024-10-05T02:48:52.532684Z","shell.execute_reply.started":"2024-10-05T02:48:52.514466Z","shell.execute_reply":"2024-10-05T02:48:52.531948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"conf_matrix = confusion_matrix(y_test, y_test_pred_binary)\nprint(\"Confusion Matrix:\")\nprint(conf_matrix)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:48:53.292091Z","iopub.execute_input":"2024-10-05T02:48:53.292429Z","iopub.status.idle":"2024-10-05T02:48:53.306723Z","shell.execute_reply.started":"2024-10-05T02:48:53.292366Z","shell.execute_reply":"2024-10-05T02:48:53.305824Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import scikitplot as skplt","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:48:53.715092Z","iopub.execute_input":"2024-10-05T02:48:53.715356Z","iopub.status.idle":"2024-10-05T02:48:53.939028Z","shell.execute_reply.started":"2024-10-05T02:48:53.715314Z","shell.execute_reply":"2024-10-05T02:48:53.938398Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"skplt.metrics.plot_confusion_matrix(y_test, y_test_pred_binary, normalize=True)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:48:56.370462Z","iopub.execute_input":"2024-10-05T02:48:56.370808Z","iopub.status.idle":"2024-10-05T02:48:56.648853Z","shell.execute_reply.started":"2024-10-05T02:48:56.370745Z","shell.execute_reply":"2024-10-05T02:48:56.647826Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class_report = classification_report(y_test, y_test_pred_binary)\nprint(\"Classification Report:\")\nprint(class_report)","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:48:56.874027Z","iopub.execute_input":"2024-10-05T02:48:56.874263Z","iopub.status.idle":"2024-10-05T02:48:56.888685Z","shell.execute_reply.started":"2024-10-05T02:48:56.874223Z","shell.execute_reply":"2024-10-05T02:48:56.887842Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 4))\nplt.subplot(1, 2, 1)\nplt.plot(history.history['accuracy'], label='Training Accuracy')\nplt.plot(history.history['val_accuracy'], label='Validation Accuracy')\nplt.title('Training and Validation Accuracy')\nplt.xlabel('Epoch')\nplt.ylabel('Accuracy')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:49:00.148532Z","iopub.execute_input":"2024-10-05T02:49:00.148857Z","iopub.status.idle":"2024-10-05T02:49:00.434896Z","shell.execute_reply.started":"2024-10-05T02:49:00.148811Z","shell.execute_reply":"2024-10-05T02:49:00.433676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(history.history['loss'], label='Training Loss')\nplt.plot(history.history['val_loss'], label='Validation Loss')\nplt.title('Training and Validation Loss')\nplt.xlabel('Epoch')\nplt.ylabel('Loss')\nplt.legend()\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-05T02:49:01.597582Z","iopub.execute_input":"2024-10-05T02:49:01.597917Z","iopub.status.idle":"2024-10-05T02:49:02.174446Z","shell.execute_reply.started":"2024-10-05T02:49:01.597860Z","shell.execute_reply":"2024-10-05T02:49:02.173385Z"},"trusted":true},"execution_count":null,"outputs":[]}]}