{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":783889,"sourceType":"datasetVersion","datasetId":409297}],"dockerImageVersionId":30698,"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\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import StandardScaler\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Dense, Flatten\nfrom tensorflow.keras.optimizers import Adam\nfrom tensorflow.keras.applications import InceptionV3, VGG16, MobileNetV2, Xception, NASNetLarge, DenseNet201, DenseNet121\nfrom sklearn.metrics import mean_squared_error","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-05-30T06:42:15.531746Z","iopub.execute_input":"2024-05-30T06:42:15.532296Z","iopub.status.idle":"2024-05-30T06:42:30.062245Z","shell.execute_reply.started":"2024-05-30T06:42:15.532256Z","shell.execute_reply":"2024-05-30T06:42:30.060951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\n\n# Load the .data file into a DataFrame\ndf = pd.read_csv('/kaggle/input/parkinsons-data-set/parkinsons.data', delimiter=',')  # Adjust the delimiter as needed\n\n# Display the first few rows of the DataFrame\nprint(df.head())","metadata":{"execution":{"iopub.status.busy":"2024-05-30T06:42:30.110007Z","iopub.execute_input":"2024-05-30T06:42:30.110993Z","iopub.status.idle":"2024-05-30T06:42:30.131460Z","shell.execute_reply.started":"2024-05-30T06:42:30.110955Z","shell.execute_reply":"2024-05-30T06:42:30.130217Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Separate features (X) and target (y)\nX = df.drop(['name', 'status'], axis=1)  # Adjust 'target_column_name' to your target column name\ny = df['status']\nX, y","metadata":{"execution":{"iopub.status.busy":"2024-05-30T06:42:30.133999Z","iopub.execute_input":"2024-05-30T06:42:30.134910Z","iopub.status.idle":"2024-05-30T06:42:30.158700Z","shell.execute_reply.started":"2024-05-30T06:42:30.134878Z","shell.execute_reply":"2024-05-30T06:42:30.157671Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scaler = StandardScaler()\n\n# Fit and transform the features (X)\nX_scaled = scaler.fit_transform(X)\n\n# Now X_scaled contains the scaled features, and y contains the target values\nprint(\"Shape of X_scaled:\", X_scaled.shape)\nprint(\"Shape of y:\", y.shape)","metadata":{"execution":{"iopub.status.busy":"2024-05-30T06:42:30.160231Z","iopub.execute_input":"2024-05-30T06:42:30.160715Z","iopub.status.idle":"2024-05-30T06:42:30.173811Z","shell.execute_reply.started":"2024-05-30T06:42:30.160676Z","shell.execute_reply":"2024-05-30T06:42:30.172473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_scaled.shape","metadata":{"execution":{"iopub.status.busy":"2024-05-30T06:42:30.175173Z","iopub.execute_input":"2024-05-30T06:42:30.175500Z","iopub.status.idle":"2024-05-30T06:42:30.185724Z","shell.execute_reply.started":"2024-05-30T06:42:30.175472Z","shell.execute_reply":"2024-05-30T06:42:30.184633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nfrom sklearn.model_selection import train_test_split\n\n# Assume X_scaled and y are your input features and target labels\ndesired_size = 75 - 9\nnum_channels = 3\n\n# Calculate the number of repeats needed to match the desired size\nnum_repeats = (desired_size * desired_size * num_channels) // X_scaled.shape[1]\n\n# Reshape and upsample the scaled input data to match the desired shape\nX_reshaped = np.repeat(X_scaled[:, np.newaxis, :], num_repeats, axis=1)\nX_reshaped = X_reshaped.reshape(X_scaled.shape[0], desired_size, desired_size, num_channels)\n\nprint(\"Shape of X_reshaped:\", X_reshaped.shape)","metadata":{"execution":{"iopub.status.busy":"2024-05-30T06:42:30.187050Z","iopub.execute_input":"2024-05-30T06:42:30.187394Z","iopub.status.idle":"2024-05-30T06:42:30.203259Z","shell.execute_reply.started":"2024-05-30T06:42:30.187366Z","shell.execute_reply":"2024-05-30T06:42:30.201835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\n\n# Assuming X_reshaped is your reshaped and upsampled data with shape (1030, 330, 330, 3)\ndesired_size = 75\n\n# Create a new array of zeros with the desired shape\nnew_shape = (X_reshaped.shape[0], desired_size, desired_size, X_reshaped.shape[3])\nX_reshaped_padded = np.zeros(new_shape)\n\n# Calculate the starting indices to copy the original data into the padded array\nstart_row = (desired_size - X_reshaped.shape[1]) // 2\nstart_col = (desired_size - X_reshaped.shape[2]) // 2\n\n# Copy the original data into the padded array\nX_reshaped_padded[:, start_row:start_row+X_reshaped.shape[1], start_col:start_col+X_reshaped.shape[2], :] = X_reshaped\n\nprint(\"Shape of X_reshaped_padded:\", X_reshaped_padded.shape)\n\n\n# Split the reshaped and scaled data into training and testing sets\nX_train_final, X_test_final, y_train, y_test = train_test_split(\n    X_reshaped_padded, y, test_size=0.2, random_state=42\n)\n\nprint(\"Shape of X_train_final:\", X_train_final.shape)\nprint(\"Shape of X_test_final:\", X_test_final.shape)\nprint(\"Shape of y_train:\", y_train.shape)\nprint(\"Shape of y_test:\", y_test.shape)\n","metadata":{"execution":{"iopub.status.busy":"2024-05-30T06:42:30.204855Z","iopub.execute_input":"2024-05-30T06:42:30.205358Z","iopub.status.idle":"2024-05-30T06:42:30.249385Z","shell.execute_reply.started":"2024-05-30T06:42:30.205318Z","shell.execute_reply":"2024-05-30T06:42:30.248199Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def reshape_split(X, y, dim):\n    desired_size = dim - (dim % X.shape[1])\n    num_channels = 3\n\n    # Calculate the number of repeats needed to match the desired size\n    num_repeats = (desired_size * desired_size * num_channels) // X_scaled.shape[1]\n\n    # Reshape and upsample the scaled input data to match the desired shape\n    X_reshaped = np.repeat(X_scaled[:, np.newaxis, :], num_repeats, axis=1)\n    X_reshaped = X_reshaped.reshape(X_scaled.shape[0], desired_size, desired_size, num_channels)\n\n    print(\"Shape of X_reshaped:\", X_reshaped.shape)\n    \n    desired_size = dim\n    # Create a new array of zeros with the desired shape\n    new_shape = (X_reshaped.shape[0], desired_size, desired_size, X_reshaped.shape[3])\n    X_reshaped_padded = np.zeros(new_shape)\n\n    # Calculate the starting indices to copy the original data into the padded array\n    start_row = (desired_size - X_reshaped.shape[1]) // 2\n    start_col = (desired_size - X_reshaped.shape[2]) // 2\n\n    # Copy the original data into the padded array\n    X_reshaped_padded[:, start_row:start_row+X_reshaped.shape[1], start_col:start_col+X_reshaped.shape[2], :] = X_reshaped\n\n    print(\"Shape of X_reshaped_padded:\", X_reshaped_padded.shape)\n\n    # Split the reshaped and scaled data into training and testing sets\n    X_train_final, X_test_final, y_train, y_test = train_test_split(\n        X_reshaped_padded, y, test_size=0.2, random_state=42\n    )\n\n    print(\"Shape of X_train_final:\", X_train_final.shape)\n    print(\"Shape of X_test_final:\", X_test_final.shape)\n    print(\"Shape of y_train:\", y_train.shape)\n    print(\"Shape of y_test:\", y_test.shape)\n    \n    return X_train_final, X_test_final, y_train, y_test\n    ","metadata":{"execution":{"iopub.status.busy":"2024-05-30T06:42:31.169934Z","iopub.execute_input":"2024-05-30T06:42:31.170342Z","iopub.status.idle":"2024-05-30T06:42:31.180482Z","shell.execute_reply.started":"2024-05-30T06:42:31.170311Z","shell.execute_reply":"2024-05-30T06:42:31.179216Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_final, X_test_final, y_train, y_test = reshape_split(X, y, 75)","metadata":{"execution":{"iopub.status.busy":"2024-05-30T04:14:06.142762Z","iopub.execute_input":"2024-05-30T04:14:06.143138Z","iopub.status.idle":"2024-05-30T04:14:06.192614Z","shell.execute_reply.started":"2024-05-30T04:14:06.143110Z","shell.execute_reply":"2024-05-30T04:14:06.191449Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def f1(p, r):\n    return (2 * p * r) / (p+r)","metadata":{"execution":{"iopub.status.busy":"2024-05-30T06:42:34.113145Z","iopub.execute_input":"2024-05-30T06:42:34.114187Z","iopub.status.idle":"2024-05-30T06:42:34.118575Z","shell.execute_reply.started":"2024-05-30T06:42:34.114150Z","shell.execute_reply":"2024-05-30T06:42:34.117530Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import time\nstart = time.time()\nend = time.time()\nprint(f\"Computational time {end - start} seconds\")","metadata":{"execution":{"iopub.status.busy":"2024-05-30T06:41:07.108342Z","iopub.execute_input":"2024-05-30T06:41:07.108767Z","iopub.status.idle":"2024-05-30T06:41:07.115464Z","shell.execute_reply.started":"2024-05-30T06:41:07.108736Z","shell.execute_reply":"2024-05-30T06:41:07.114205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras.applications import VGG16\nfrom tensorflow.keras.layers import Dense, GlobalAveragePooling2D\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.optimizers import Adam\nstart = time.time()\n\n# Load the pre-trained VGG16 model (excluding the top layers)\nbase_model = VGG16(weights='imagenet', include_top=False, input_shape=(75, 75, 3))\n\n# Freeze the base model layers\nbase_model.trainable = False\n\n# Build the binary classification model on top of the base model\nmodel = Sequential([\n    base_model,\n    GlobalAveragePooling2D(),\n    Dense(16, activation='relu'),\n    Dense(4, activation='relu'),\n    Dense(1, activation='sigmoid')  # Output layer for binary classification\n])\n\n# Define the desired learning rate (e.g., 0.01)\nlearning_rate = 0.01\n\n# Compile the model with the specified learning rate and binary_crossentropy loss\noptimizer = Adam(learning_rate=learning_rate)\nmodel.compile(\n    optimizer=optimizer,\n    loss='binary_crossentropy',\n    metrics=[\n        'accuracy',\n        tf.keras.metrics.Precision(name='precision'),\n        tf.keras.metrics.Recall(name='recall'),\n        tf.keras.metrics.AUC(name='auc')\n    ]\n)\n# Display a summary of the model architecture\nmodel.summary()\n\n# Train the model\nhistory = model.fit(X_train_final, y_train, epochs=8, batch_size=32, validation_split=0.1)\n\n# Evaluate the model on the test set\nloss, accuracy, precision, recall, auc = model.evaluate(X_test_final, y_test)\nprint(\"Loss on Test Set:\", loss)\nprint(\"Accuracy on Test Set:\", accuracy)\nprint(\"precision on Test Set:\", precision)\nprint(\"recall on Test Set:\", recall)\nprint(\"f1 score on Test Set:\", f1(precision, recall))\nprint(\"auc on Test Set:\", auc)\n\nprint(\"Error rate on Test Set:\", 1 -accuracy)\nend = time.time()\nprint(f\"Computational time {end - start} seconds\")","metadata":{"execution":{"iopub.status.busy":"2024-05-30T06:43:09.032929Z","iopub.execute_input":"2024-05-30T06:43:09.033356Z","iopub.status.idle":"2024-05-30T06:43:50.800375Z","shell.execute_reply.started":"2024-05-30T06:43:09.033324Z","shell.execute_reply":"2024-05-30T06:43:50.799189Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras.applications import MobileNetV2\nfrom tensorflow.keras.layers import Dense, GlobalAveragePooling2D\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.optimizers import Adam\nstart = time.time()\n\nbase_model = MobileNetV2(weights='imagenet', include_top=False, input_shape=(75, 75, 3))\nbase_model.trainable = False\n\nmodel = Sequential([\n    base_model,\n    GlobalAveragePooling2D(),\n    Dense(16, activation='relu'),\n    Dense(4, activation='relu'),\n    Dense(1, activation='sigmoid')\n])\n\nlearning_rate = 0.01\noptimizer = Adam(learning_rate=learning_rate)\nmodel.compile(optimizer=optimizer, loss='binary_crossentropy', metrics=['accuracy'])\n\nmodel.summary()\n\nhistory = model.fit(X_train_final, y_train, epochs=8, batch_size=32, validation_split=0.1)\nloss, accuracy = model.evaluate(X_test_final, y_test)\nprint(\"Loss on Test Set:\", loss)\nprint(\"Accuracy on Test Set:\", accuracy)\n\nprint(\"Error rate on Test Set:\", 1 -accuracy)\nend = time.time()\nprint(f\"Computational time {end - start} seconds\")","metadata":{"execution":{"iopub.status.busy":"2024-05-30T06:44:14.084028Z","iopub.execute_input":"2024-05-30T06:44:14.084413Z","iopub.status.idle":"2024-05-30T06:44:27.297578Z","shell.execute_reply.started":"2024-05-30T06:44:14.084385Z","shell.execute_reply":"2024-05-30T06:44:27.296397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras.applications import InceptionV3\nfrom tensorflow.keras.layers import Dense, GlobalAveragePooling2D\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.optimizers import Adam\nstart = time.time()\n\nbase_model = InceptionV3(weights='imagenet', include_top=False, input_shape=(75, 75, 3))\nbase_model.trainable = False\n# Build the binary classification model on top of the base model\nmodel = Sequential([\n    base_model,\n    GlobalAveragePooling2D(),\n    Dense(16, activation='relu'),\n    Dense(4, activation='relu'),\n    Dense(1, activation='sigmoid')  # Output layer for binary classification\n])\n\n# Define the desired learning rate (e.g., 0.01)\nlearning_rate = 0.01\n\n# Compile the model with the specified learning rate and binary_crossentropy loss\noptimizer = Adam(learning_rate=learning_rate)\nmodel.compile(\n    optimizer=optimizer,\n    loss='binary_crossentropy',\n    metrics=[\n        'accuracy',\n        tf.keras.metrics.Precision(name='precision'),\n        tf.keras.metrics.Recall(name='recall'),\n        tf.keras.metrics.AUC(name='auc')\n    ]\n)\n# Display a summary of the model architecture\nmodel.summary()\n\n# Train the model\nhistory = model.fit(X_train_final, y_train, epochs=8, batch_size=32, validation_split=0.1)\n\n# Evaluate the model on the test set\nloss, accuracy, precision, recall, auc = model.evaluate(X_test_final, y_test)\nprint(\"Loss on Test Set:\", loss)\nprint(\"Accuracy on Test Set:\", accuracy)\nprint(\"precision on Test Set:\", precision)\nprint(\"recall on Test Set:\", recall)\nprint(\"f1 score on Test Set:\", f1(precision, recall))\nprint(\"auc on Test Set:\", auc)\n\nprint(\"Error rate on Test Set:\", 1 -accuracy)\nend = time.time()\nprint(f\"Computational time {end - start} seconds\")","metadata":{"execution":{"iopub.status.busy":"2024-05-28T15:21:53.477447Z","iopub.execute_input":"2024-05-28T15:21:53.478350Z","iopub.status.idle":"2024-05-28T15:22:15.989167Z","shell.execute_reply.started":"2024-05-28T15:21:53.478307Z","shell.execute_reply":"2024-05-28T15:22:15.988306Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras.applications import EfficientNetB0\nfrom tensorflow.keras.layers import Dense, GlobalAveragePooling2D\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.optimizers import Adam\nstart = time.time()\n\nbase_model = EfficientNetB0(weights='imagenet', include_top=False, input_shape=(75, 75, 3))\nbase_model.trainable = False\n# Build the binary classification model on top of the base model\nmodel = Sequential([\n    base_model,\n    GlobalAveragePooling2D(),\n    Dense(16, activation='relu'),\n    Dense(4, activation='relu'),\n    Dense(1, activation='sigmoid')  # Output layer for binary classification\n])\n\n# Define the desired learning rate (e.g., 0.01)\nlearning_rate = 0.01\n\n# Compile the model with the specified learning rate and binary_crossentropy loss\noptimizer = Adam(learning_rate=learning_rate)\nmodel.compile(\n    optimizer=optimizer,\n    loss='binary_crossentropy',\n    metrics=[\n        'accuracy',\n        tf.keras.metrics.Precision(name='precision'),\n        tf.keras.metrics.Recall(name='recall'),\n        tf.keras.metrics.AUC(name='auc')\n    ]\n)\n# Display a summary of the model architecture\nmodel.summary()\n\n# Train the model\nhistory = model.fit(X_train_final, y_train, epochs=8, batch_size=32, validation_split=0.1)\n\n# Evaluate the model on the test set\nloss, accuracy, precision, recall, auc = model.evaluate(X_test_final, y_test)\nprint(\"Loss on Test Set:\", loss)\nprint(\"Accuracy on Test Set:\", accuracy)\nprint(\"precision on Test Set:\", precision)\nprint(\"recall on Test Set:\", recall)\nprint(\"f1 score on Test Set:\", f1(precision, recall))\nprint(\"auc on Test Set:\", auc)\n\n\nprint(\"Error rate on Test Set:\", 1 -accuracy)\nend = time.time()\nprint(f\"Computational time {end - start} seconds\")","metadata":{"execution":{"iopub.status.busy":"2024-05-28T15:39:24.061482Z","iopub.execute_input":"2024-05-28T15:39:24.061886Z","iopub.status.idle":"2024-05-28T15:39:52.136060Z","shell.execute_reply.started":"2024-05-28T15:39:24.061845Z","shell.execute_reply":"2024-05-28T15:39:52.134878Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras.applications import Xception\nfrom tensorflow.keras.layers import Dense, GlobalAveragePooling2D\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.optimizers import Adam\nstart = time.time()\n\nbase_model = Xception(weights='imagenet', include_top=False, input_shape=(75, 75, 3))\nbase_model.trainable = False\n# Build the binary classification model on top of the base model\nmodel = Sequential([\n    base_model,\n    GlobalAveragePooling2D(),\n    Dense(16, activation='relu'),\n    Dense(4, activation='relu'),\n    Dense(1, activation='sigmoid')  # Output layer for binary classification\n])\n\n# Define the desired learning rate (e.g., 0.01)\nlearning_rate = 0.01\n\n# Compile the model with the specified learning rate and binary_crossentropy loss\noptimizer = Adam(learning_rate=learning_rate)\nmodel.compile(\n    optimizer=optimizer,\n    loss='binary_crossentropy',\n    metrics=[\n        'accuracy',\n        tf.keras.metrics.Precision(name='precision'),\n        tf.keras.metrics.Recall(name='recall'),\n        tf.keras.metrics.AUC(name='auc')\n    ]\n)\n# Display a summary of the model architecture\nmodel.summary()\n\n# Train the model\nhistory = model.fit(X_train_final, y_train, epochs=8, batch_size=32, validation_split=0.1)\n\n# Evaluate the model on the test set\nloss, accuracy, precision, recall, auc = model.evaluate(X_test_final, y_test)\nprint(\"Loss on Test Set:\", loss)\nprint(\"Accuracy on Test Set:\", accuracy)\nprint(\"precision on Test Set:\", precision)\nprint(\"recall on Test Set:\", recall)\nprint(\"f1 score on Test Set:\", f1(precision, recall))\nprint(\"auc on Test Set:\", auc)\n\n\nprint(\"Error rate on Test Set:\", 1 -accuracy)\nend = time.time()\nprint(f\"Computational time {end - start} seconds\")","metadata":{"execution":{"iopub.status.busy":"2024-05-28T15:23:05.739384Z","iopub.execute_input":"2024-05-28T15:23:05.739847Z","iopub.status.idle":"2024-05-28T15:23:34.139193Z","shell.execute_reply.started":"2024-05-28T15:23:05.739809Z","shell.execute_reply":"2024-05-28T15:23:34.137998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras.applications import NASNetLarge\nfrom tensorflow.keras.layers import Dense, GlobalAveragePooling2D\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.optimizers import Adam\nstart = time.time()\n\nbase_model = NASNetLarge(weights='imagenet', include_top=False, input_shape=(75, 75, 3))\nbase_model.trainable = False\n# Build the binary classification model on top of the base model\nmodel = Sequential([\n    base_model,\n    GlobalAveragePooling2D(),\n    Dense(16, activation='relu'),\n    Dense(4, activation='relu'),\n    Dense(1, activation='sigmoid')  # Output layer for binary classification\n])\n\n# Define the desired learning rate (e.g., 0.01)\nlearning_rate = 0.01\n\n# Compile the model with the specified learning rate and binary_crossentropy loss\noptimizer = Adam(learning_rate=learning_rate)\nmodel.compile(\n    optimizer=optimizer,\n    loss='binary_crossentropy',\n    metrics=[\n        'accuracy',\n        tf.keras.metrics.Precision(name='precision'),\n        tf.keras.metrics.Recall(name='recall'),\n        tf.keras.metrics.AUC(name='auc')\n    ]\n)\n# Display a summary of the model architecture\nmodel.summary()\n\n# Train the model\nhistory = model.fit(X_train_final, y_train, epochs=8, batch_size=32, validation_split=0.1)\n\n# Evaluate the model on the test set\nloss, accuracy, precision, recall, auc = model.evaluate(X_test_final, y_test)\nprint(\"Loss on Test Set:\", loss)\nprint(\"Accuracy on Test Set:\", accuracy)\nprint(\"precision on Test Set:\", precision)\nprint(\"recall on Test Set:\", recall)\nprint(\"f1 score on Test Set:\", f1(precision, recall))\nprint(\"auc on Test Set:\", auc)\n\n\nprint(\"Error rate on Test Set:\", 1 -accuracy)\nend = time.time()\nprint(f\"Computational time {end - start} seconds\")","metadata":{"execution":{"iopub.status.busy":"2024-05-28T15:23:56.462106Z","iopub.execute_input":"2024-05-28T15:23:56.463197Z","iopub.status.idle":"2024-05-28T15:25:42.084955Z","shell.execute_reply.started":"2024-05-28T15:23:56.463155Z","shell.execute_reply":"2024-05-28T15:25:42.083805Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras.applications import DenseNet201\nfrom tensorflow.keras.layers import Dense, GlobalAveragePooling2D\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.optimizers import Adam\nstart = time.time()\n\nbase_model = DenseNet201(weights='imagenet', include_top=False, input_shape=(75, 75, 3))\nbase_model.trainable = False\n# Build the binary classification model on top of the base model\nmodel = Sequential([\n    base_model,\n    GlobalAveragePooling2D(),\n    Dense(16, activation='relu'),\n    Dense(4, activation='relu'),\n    Dense(1, activation='sigmoid')  # Output layer for binary classification\n])\n\n# Define the desired learning rate (e.g., 0.01)\nlearning_rate = 0.01\n\n# Compile the model with the specified learning rate and binary_crossentropy loss\noptimizer = Adam(learning_rate=learning_rate)\nmodel.compile(\n    optimizer=optimizer,\n    loss='binary_crossentropy',\n    metrics=[\n        'accuracy',\n        tf.keras.metrics.Precision(name='precision'),\n        tf.keras.metrics.Recall(name='recall'),\n        tf.keras.metrics.AUC(name='auc')\n    ]\n)\n# Display a summary of the model architecture\nmodel.summary()\n\n# Train the model\nhistory = model.fit(X_train_final, y_train, epochs=8, batch_size=32, validation_split=0.1)\n\n# Evaluate the model on the test set\nloss, accuracy, precision, recall, auc = model.evaluate(X_test_final, y_test)\nprint(\"Loss on Test Set:\", loss)\nprint(\"Accuracy on Test Set:\", accuracy)\nprint(\"precision on Test Set:\", precision)\nprint(\"recall on Test Set:\", recall)\nprint(\"f1 score on Test Set:\", f1(precision, recall))\nprint(\"auc on Test Set:\", auc)\n\n\nprint(\"Error rate on Test Set:\", 1 -accuracy)\nend = time.time()\nprint(f\"Computational time {end - start} seconds\")","metadata":{"execution":{"iopub.status.busy":"2024-05-28T15:43:03.364056Z","iopub.execute_input":"2024-05-28T15:43:03.364493Z","iopub.status.idle":"2024-05-28T15:44:01.489941Z","shell.execute_reply.started":"2024-05-28T15:43:03.364458Z","shell.execute_reply":"2024-05-28T15:44:01.489137Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras.applications import DenseNet121\nfrom tensorflow.keras.layers import Dense, GlobalAveragePooling2D\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.optimizers import Adam\nstart = time.time()\n\nbase_model = DenseNet121(weights='imagenet', include_top=False, input_shape=(75, 75, 3))\nbase_model.trainable = False\n# Build the binary classification model on top of the base model\nmodel = Sequential([\n    base_model,\n    GlobalAveragePooling2D(),\n    Dense(16, activation='relu'),\n    Dense(4, activation='relu'),\n    Dense(1, activation='sigmoid')  # Output layer for binary classification\n])\n\n# Define the desired learning rate (e.g., 0.01)\nlearning_rate = 0.01\n\n# Compile the model with the specified learning rate and binary_crossentropy loss\noptimizer = Adam(learning_rate=learning_rate)\nmodel.compile(\n    optimizer=optimizer,\n    loss='binary_crossentropy',\n    metrics=[\n        'accuracy',\n        tf.keras.metrics.Precision(name='precision'),\n        tf.keras.metrics.Recall(name='recall'),\n        tf.keras.metrics.AUC(name='auc')\n    ]\n)\n# Display a summary of the model architecture\nmodel.summary()\n\n# Train the model\nhistory = model.fit(X_train_final, y_train, epochs=8, batch_size=32, validation_split=0.1)\n\n# Evaluate the model on the test set\nloss, accuracy, precision, recall, auc = model.evaluate(X_test_final, y_test)\nprint(\"Loss on Test Set:\", loss)\nprint(\"Accuracy on Test Set:\", accuracy)\nprint(\"precision on Test Set:\", precision)\nprint(\"recall on Test Set:\", recall)\nprint(\"f1 score on Test Set:\", f1(precision, recall))\nprint(\"auc on Test Set:\", auc)\n\n\nprint(\"Error rate on Test Set:\", 1 -accuracy)\nend = time.time()\nprint(f\"Computational time {end - start} seconds\")","metadata":{"execution":{"iopub.status.busy":"2024-05-28T15:49:35.439690Z","iopub.execute_input":"2024-05-28T15:49:35.440069Z","iopub.status.idle":"2024-05-28T15:50:15.769306Z","shell.execute_reply.started":"2024-05-28T15:49:35.440042Z","shell.execute_reply":"2024-05-28T15:50:15.767860Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras.applications import ResNet50\nfrom tensorflow.keras.layers import Dense, GlobalAveragePooling2D\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.optimizers import Adam\nstart = time.time()\n\nbase_model = ResNet50(weights='imagenet', include_top=False, input_shape=(75, 75, 3))\nbase_model.trainable = False\n# Build the binary classification model on top of the base model\nmodel = Sequential([\n    base_model,\n    GlobalAveragePooling2D(),\n    Dense(16, activation='relu'),\n    Dense(4, activation='relu'),\n    Dense(1, activation='sigmoid')  # Output layer for binary classification\n])\n\n# Define the desired learning rate (e.g., 0.01)\nlearning_rate = 0.01\n\n# Compile the model with the specified learning rate and binary_crossentropy loss\noptimizer = Adam(learning_rate=learning_rate)\nmodel.compile(\n    optimizer=optimizer,\n    loss='binary_crossentropy',\n    metrics=[\n        'accuracy',\n        tf.keras.metrics.Precision(name='precision'),\n        tf.keras.metrics.Recall(name='recall'),\n        tf.keras.metrics.AUC(name='auc')\n    ]\n)\n# Display a summary of the model architecture\nmodel.summary()\n\n# Train the model\nhistory = model.fit(X_train_final, y_train, epochs=8, batch_size=32, validation_split=0.1)\n\n# Evaluate the model on the test set\nloss, accuracy, precision, recall, auc = model.evaluate(X_test_final, y_test)\nprint(\"Loss on Test Set:\", loss)\nprint(\"Accuracy on Test Set:\", accuracy)\nprint(\"precision on Test Set:\", precision)\nprint(\"recall on Test Set:\", recall)\nprint(\"f1 score on Test Set:\", f1(precision, recall))\nprint(\"auc on Test Set:\", auc)\n\n\nprint(\"Error rate on Test Set:\", 1 -accuracy)\nend = time.time()\nprint(f\"Computational time {end - start} seconds\")","metadata":{"execution":{"iopub.status.busy":"2024-05-28T15:50:37.857553Z","iopub.execute_input":"2024-05-28T15:50:37.858013Z","iopub.status.idle":"2024-05-28T15:51:04.246435Z","shell.execute_reply.started":"2024-05-28T15:50:37.857983Z","shell.execute_reply":"2024-05-28T15:51:04.245533Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras.applications import EfficientNetB3\nfrom tensorflow.keras.layers import Dense, GlobalAveragePooling2D\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.optimizers import Adam\nstart = time.time()\n\nbase_model = EfficientNetB3(weights='imagenet', include_top=False, input_shape=(75, 75, 3))\nbase_model.trainable = False\n# Build the binary classification model on top of the base model\nmodel = Sequential([\n    base_model,\n    GlobalAveragePooling2D(),\n    Dense(16, activation='relu'),\n    Dense(4, activation='relu'),\n    Dense(1, activation='sigmoid')  # Output layer for binary classification\n])\n\n# Define the desired learning rate (e.g., 0.01)\nlearning_rate = 0.01\n\n# Compile the model with the specified learning rate and binary_crossentropy loss\noptimizer = Adam(learning_rate=learning_rate)\nmodel.compile(\n    optimizer=optimizer,\n    loss='binary_crossentropy',\n    metrics=[\n        'accuracy',\n        tf.keras.metrics.Precision(name='precision'),\n        tf.keras.metrics.Recall(name='recall'),\n        tf.keras.metrics.AUC(name='auc')\n    ]\n)\n# Display a summary of the model architecture\nmodel.summary()\n\n# Train the model\nhistory = model.fit(X_train_final, y_train, epochs=8, batch_size=32, validation_split=0.1)\n\n# Evaluate the model on the test set\nloss, accuracy, precision, recall, auc = model.evaluate(X_test_final, y_test)\nprint(\"Loss on Test Set:\", loss)\nprint(\"Accuracy on Test Set:\", accuracy)\nprint(\"precision on Test Set:\", precision)\nprint(\"recall on Test Set:\", recall)\nprint(\"f1 score on Test Set:\", f1(precision, recall))\nprint(\"auc on Test Set:\", auc)\n\n\nprint(\"Error rate on Test Set:\", 1 -accuracy)\nend = time.time()\nprint(f\"Computational time {end - start} seconds\")","metadata":{"execution":{"iopub.status.busy":"2024-05-28T15:51:14.941632Z","iopub.execute_input":"2024-05-28T15:51:14.942038Z","iopub.status.idle":"2024-05-28T15:52:03.727629Z","shell.execute_reply.started":"2024-05-28T15:51:14.942004Z","shell.execute_reply":"2024-05-28T15:52:03.726555Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras.applications import ResNet101\nfrom tensorflow.keras.layers import Dense, GlobalAveragePooling2D\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.optimizers import Adam\nstart = time.time()\n\nbase_model = ResNet101(weights='imagenet', include_top=False, input_shape=(75, 75, 3))\nbase_model.trainable = False\n# Build the binary classification model on top of the base model\nmodel = Sequential([\n    base_model,\n    GlobalAveragePooling2D(),\n    Dense(16, activation='relu'),\n    Dense(4, activation='relu'),\n    Dense(1, activation='sigmoid')  # Output layer for binary classification\n])\n\n# Define the desired learning rate (e.g., 0.01)\nlearning_rate = 0.01\n\n# Compile the model with the specified learning rate and binary_crossentropy loss\noptimizer = Adam(learning_rate=learning_rate)\nmodel.compile(\n    optimizer=optimizer,\n    loss='binary_crossentropy',\n    metrics=[\n        'accuracy',\n        tf.keras.metrics.Precision(name='precision'),\n        tf.keras.metrics.Recall(name='recall'),\n        tf.keras.metrics.AUC(name='auc')\n    ]\n)\n# Display a summary of the model architecture\nmodel.summary()\n\n# Train the model\nhistory = model.fit(X_train_final, y_train, epochs=8, batch_size=32, validation_split=0.1)\n\n# Evaluate the model on the test set\nloss, accuracy, precision, recall, auc = model.evaluate(X_test_final, y_test)\nprint(\"Loss on Test Set:\", loss)\nprint(\"Accuracy on Test Set:\", accuracy)\nprint(\"precision on Test Set:\", precision)\nprint(\"recall on Test Set:\", recall)\nprint(\"f1 score on Test Set:\", f1(precision, recall))\nprint(\"auc on Test Set:\", auc)\n\n\nprint(\"Error rate on Test Set:\", 1 -accuracy)\nend = time.time()\nprint(f\"Computational time {end - start} seconds\")","metadata":{"execution":{"iopub.status.busy":"2024-05-28T15:52:03.729479Z","iopub.execute_input":"2024-05-28T15:52:03.729844Z","iopub.status.idle":"2024-05-28T15:52:56.074334Z","shell.execute_reply.started":"2024-05-28T15:52:03.729814Z","shell.execute_reply":"2024-05-28T15:52:56.073473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras.applications import ResNet152\nfrom tensorflow.keras.layers import Dense, GlobalAveragePooling2D\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.optimizers import Adam\nstart = time.time()\n\nbase_model = ResNet152(weights='imagenet', include_top=False, input_shape=(75, 75, 3))\nbase_model.trainable = False\n# Build the binary classification model on top of the base model\nmodel = Sequential([\n    base_model,\n    GlobalAveragePooling2D(),\n    Dense(16, activation='relu'),\n    Dense(4, activation='relu'),\n    Dense(1, activation='sigmoid')  # Output layer for binary classification\n])\n\n# Define the desired learning rate (e.g., 0.01)\nlearning_rate = 0.01\n\n# Compile the model with the specified learning rate and binary_crossentropy loss\noptimizer = Adam(learning_rate=learning_rate)\nmodel.compile(\n    optimizer=optimizer,\n    loss='binary_crossentropy',\n    metrics=[\n        'accuracy',\n        tf.keras.metrics.Precision(name='precision'),\n        tf.keras.metrics.Recall(name='recall'),\n        tf.keras.metrics.AUC(name='auc')\n    ]\n)\n# Display a summary of the model architecture\nmodel.summary()\n\n# Train the model\nhistory = model.fit(X_train_final, y_train, epochs=8, batch_size=32, validation_split=0.1)\n\n# Evaluate the model on the test set\nloss, accuracy, precision, recall, auc = model.evaluate(X_test_final, y_test)\nprint(\"Loss on Test Set:\", loss)\nprint(\"Accuracy on Test Set:\", accuracy)\nprint(\"precision on Test Set:\", precision)\nprint(\"recall on Test Set:\", recall)\nprint(\"f1 score on Test Set:\", f1(precision, recall))\nprint(\"auc on Test Set:\", auc)\n\n\nprint(\"Error rate on Test Set:\", 1 -accuracy)\nend = time.time()\nprint(f\"Computational time {end - start} seconds\")","metadata":{"execution":{"iopub.status.busy":"2024-05-28T15:52:56.075913Z","iopub.execute_input":"2024-05-28T15:52:56.076800Z","iopub.status.idle":"2024-05-28T15:54:20.674141Z","shell.execute_reply.started":"2024-05-28T15:52:56.076769Z","shell.execute_reply":"2024-05-28T15:54:20.673350Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras.applications import EfficientNetB1\nfrom tensorflow.keras.layers import Dense, GlobalAveragePooling2D\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.optimizers import Adam\nstart = time.time()\n\nbase_model = EfficientNetB1(weights='imagenet', include_top=False, input_shape=(75, 75, 3))\nbase_model.trainable = False\n# Build the binary classification model on top of the base model\nmodel = Sequential([\n    base_model,\n    GlobalAveragePooling2D(),\n    Dense(16, activation='relu'),\n    Dense(4, activation='relu'),\n    Dense(1, activation='sigmoid')  # Output layer for binary classification\n])\n\n# Define the desired learning rate (e.g., 0.01)\nlearning_rate = 0.01\n\n# Compile the model with the specified learning rate and binary_crossentropy loss\noptimizer = Adam(learning_rate=learning_rate)\nmodel.compile(\n    optimizer=optimizer,\n    loss='binary_crossentropy',\n    metrics=[\n        'accuracy',\n        tf.keras.metrics.Precision(name='precision'),\n        tf.keras.metrics.Recall(name='recall'),\n        tf.keras.metrics.AUC(name='auc')\n    ]\n)\n# Display a summary of the model architecture\nmodel.summary()\n\n# Train the model\nhistory = model.fit(X_train_final, y_train, epochs=8, batch_size=32, validation_split=0.1)\n\n# Evaluate the model on the test set\nloss, accuracy, precision, recall, auc = model.evaluate(X_test_final, y_test)\nprint(\"Loss on Test Set:\", loss)\nprint(\"Accuracy on Test Set:\", accuracy)\nprint(\"precision on Test Set:\", precision)\nprint(\"recall on Test Set:\", recall)\nprint(\"f1 score on Test Set:\", f1(precision, recall))\nprint(\"auc on Test Set:\", auc)\n\n\nprint(\"Error rate on Test Set:\", 1 -accuracy)\nend = time.time()\nprint(f\"Computational time {end - start} seconds\")","metadata":{"execution":{"iopub.status.busy":"2024-05-28T15:54:43.723128Z","iopub.execute_input":"2024-05-28T15:54:43.723559Z","iopub.status.idle":"2024-05-28T15:55:15.220839Z","shell.execute_reply.started":"2024-05-28T15:54:43.723529Z","shell.execute_reply":"2024-05-28T15:55:15.220051Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras.applications import MobileNetV3Small\nfrom tensorflow.keras.layers import Dense, GlobalAveragePooling2D\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.optimizers import Adam\nstart = time.time()\n\nbase_model = MobileNetV3Small(weights='imagenet', include_top=False, input_shape=(75, 75, 3))\nbase_model.trainable = False\n# Build the binary classification model on top of the base model\nmodel = Sequential([\n    base_model,\n    GlobalAveragePooling2D(),\n    Dense(16, activation='relu'),\n    Dense(4, activation='relu'),\n    Dense(1, activation='sigmoid')  # Output layer for binary classification\n])\n\n# Define the desired learning rate (e.g., 0.01)\nlearning_rate = 0.01\n\n# Compile the model with the specified learning rate and binary_crossentropy loss\noptimizer = Adam(learning_rate=learning_rate)\nmodel.compile(\n    optimizer=optimizer,\n    loss='binary_crossentropy',\n    metrics=[\n        'accuracy',\n        tf.keras.metrics.Precision(name='precision'),\n        tf.keras.metrics.Recall(name='recall'),\n        tf.keras.metrics.AUC(name='auc')\n    ]\n)\n# Display a summary of the model architecture\nmodel.summary()\n\n# Train the model\nhistory = model.fit(X_train_final, y_train, epochs=8, batch_size=32, validation_split=0.1)\n\n# Evaluate the model on the test set\nloss, accuracy, precision, recall, auc = model.evaluate(X_test_final, y_test)\nprint(\"Loss on Test Set:\", loss)\nprint(\"Accuracy on Test Set:\", accuracy)\nprint(\"precision on Test Set:\", precision)\nprint(\"recall on Test Set:\", recall)\nprint(\"f1 score on Test Set:\", f1(precision, recall))\nprint(\"auc on Test Set:\", auc)\n\n\nprint(\"Error rate on Test Set:\", 1 -accuracy)\nend = time.time()\nprint(f\"Computational time {end - start} seconds\")","metadata":{"execution":{"iopub.status.busy":"2024-05-28T15:55:15.222332Z","iopub.execute_input":"2024-05-28T15:55:15.223253Z","iopub.status.idle":"2024-05-28T15:55:27.034310Z","shell.execute_reply.started":"2024-05-28T15:55:15.223223Z","shell.execute_reply":"2024-05-28T15:55:27.032918Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}