{ "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "name": "python3", "language": "python" }, "language_info": { "name": "python", "version": "3.10.14", "mimetype": "text/x-python", "codemirror_mode": { "name": "ipython", "version": 3 }, "pygments_lexer": "ipython3", "nbconvert_exporter": "python", "file_extension": ".py" }, "kaggle": { "accelerator": "none", "dataSources": [ { "sourceId": 9725208, "sourceType": "datasetVersion", "datasetId": 5950719 }, { "sourceId": 9730815, "sourceType": "datasetVersion", "datasetId": 5954901 } ], "dockerImageVersionId": 30787, "isInternetEnabled": true, "language": "python", "sourceType": "notebook", "isGpuEnabled": false }, "colab": { "provenance": [], "gpuType": "A100" }, "accelerator": "GPU" }, "nbformat_minor": 0, "nbformat": 4, "cells": [ { "cell_type": "markdown", "source": [ "# Analisi e Previsione della Produzione di Olio d'Oliva\n", "\n", "Questo notebook esplora la relazione tra i dati meteorologici e la produzione annuale di olio d'oliva, con l'obiettivo di creare un modello predittivo." ], "metadata": { "id": "vwMqHwWTthA4" } }, { "metadata": { "ExecuteTime": { "end_time": "2024-10-29T15:15:51.992629Z", "start_time": "2024-10-29T15:15:51.940019Z" } }, "cell_type": "code", "source": [ "!pip install tensorflow\n", "!pip install numpy\n", "!pip install pandas\n", "\n", "!pip install keras\n", "!pip install scikit-learn\n", "!pip install matplotlib\n", "!pip install joblib\n", "!pip install pyarrow\n", "!pip install fastparquet\n", "!pip install scipy\n", "!pip install seaborn\n", "!pip install tqdm" ], "outputs": [ { "ename": "NameError", "evalue": "name 'tensorflow' is not defined", "output_type": "error", "traceback": [ "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", "\u001B[0;31mNameError\u001B[0m Traceback (most recent call last)", "Cell \u001B[0;32mIn[1], line 1\u001B[0m\n\u001B[0;32m----> 1\u001B[0m \u001B[43mtensorflow\u001B[49m\n", "\u001B[0;31mNameError\u001B[0m: name 'tensorflow' is not defined" ] } ], "execution_count": 1 }, { "cell_type": "code", "source": [ "import tensorflow as tf\n", "import keras\n", "\n", "print(f\"Keras version: {keras.__version__}\")\n", "print(f\"TensorFlow version: {tf.__version__}\")\n", "print(f\"TensorFlow version: {tf.__version__}\")\n", "print(f\"CUDA available: {tf.test.is_built_with_cuda()}\")\n", "print(f\"GPU devices: {tf.config.list_physical_devices('GPU')}\")\n", "\n", "# GPU configuration\n", "gpus = tf.config.experimental.list_physical_devices('GPU')\n", "if gpus:\n", " try:\n", " for gpu in gpus:\n", " tf.config.experimental.set_memory_growth(gpu, True)\n", " logical_gpus = tf.config.experimental.list_logical_devices('GPU')\n", " print(len(gpus), \"Physical GPUs,\", len(logical_gpus), \"Logical GPUs\")\n", " except RuntimeError as e:\n", " print(e)" ], "metadata": { "ExecuteTime": { "end_time": "2024-10-25T21:05:00.337046Z", "start_time": "2024-10-25T21:04:03.960543Z" }, "execution": { "iopub.status.busy": "2024-10-29T02:13:42.081902Z", "iopub.execute_input": "2024-10-29T02:13:42.082325Z", "iopub.status.idle": "2024-10-29T02:13:42.090811Z", "shell.execute_reply.started": "2024-10-29T02:13:42.082286Z", "shell.execute_reply": "2024-10-29T02:13:42.089748Z" }, "trusted": true, "colab": { "base_uri": "https://localhost:8080/" }, "id": "VqHdVCiJthA6", "outputId": "d8f830c1-5342-4e11-ac3c-96c535aad5fd" }, "execution_count": 3, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Keras version: 3.4.1\n", "TensorFlow version: 2.17.0\n", "TensorFlow version: 2.17.0\n", "CUDA available: True\n", "GPU devices: [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]\n", "1 Physical GPUs, 1 Logical GPUs\n" ] } ] }, { "cell_type": "code", "source": [ "# Test semplice per verificare che la GPU funzioni\n", "def test_gpu():\n", " print(\"TensorFlow version:\", tf.__version__)\n", " print(\"\\nDispositivi disponibili:\")\n", " print(tf.config.list_physical_devices())\n", "\n", " # Creiamo e moltiplichiamo due tensori sulla GPU\n", " with tf.device('/GPU:0'):\n", " a = tf.random.normal([10000, 10000])\n", " b = tf.random.normal([10000, 10000])\n", " c = tf.matmul(a, b)\n", "\n", " print(\"\\nShape del risultato:\", c.shape)\n", " print(\"Device del tensore:\", c.device)\n", " return \"Test completato con successo!\"\n", "\n", "\n", "test_gpu()" ], "metadata": { "ExecuteTime": { "end_time": "2024-10-25T21:05:14.642072Z", "start_time": "2024-10-25T21:05:11.794331Z" }, "execution": { "iopub.status.busy": "2024-10-29T02:13:42.096582Z", "iopub.execute_input": "2024-10-29T02:13:42.096984Z", "iopub.status.idle": "2024-10-29T02:13:42.111695Z", "shell.execute_reply.started": "2024-10-29T02:13:42.096942Z", "shell.execute_reply": "2024-10-29T02:13:42.110489Z" }, "trusted": true, "colab": { "base_uri": "https://localhost:8080/", "height": 160 }, "id": "cz0NU95IthA7", "outputId": "eaf1939a-7708-49ad-adc9-bac4e2448e10" }, "execution_count": 4, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "TensorFlow version: 2.17.0\n", "\n", "Dispositivi disponibili:\n", "[PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU'), PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]\n", "\n", "Shape del risultato: (10000, 10000)\n", "Device del tensore: /job:localhost/replica:0/task:0/device:GPU:0\n" ] }, { "output_type": "execute_result", "data": { "text/plain": [ "'Test completato con successo!'" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "string" } }, "metadata": {}, "execution_count": 4 } ] }, { "cell_type": "code", "source": [ "import pandas as pd\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import seaborn as sns\n", "from sklearn.model_selection import train_test_split\n", "from sklearn.preprocessing import MinMaxScaler, StandardScaler\n", "from tensorflow.keras.layers import Input, Dense, Dropout, Bidirectional, LSTM, LayerNormalization, Add, Activation, BatchNormalization, MultiHeadAttention, MaxPooling1D, Conv1D, GlobalMaxPooling1D, GlobalAveragePooling1D, Concatenate, ZeroPadding1D, Lambda\n", "from tensorflow.keras.models import Model\n", "from tensorflow.keras.regularizers import l2\n", "from tensorflow.keras.optimizers import Adam\n", "from tensorflow.keras.callbacks import EarlyStopping, ReduceLROnPlateau\n", "from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score\n", "from datetime import datetime\n", "import os\n", "import json\n", "import joblib\n", "import re\n", "import pyarrow as pa\n", "import pyarrow.parquet as pq\n", "from tqdm import tqdm\n", "\n", "random_state_value = 42" ], "metadata": { "ExecuteTime": { "end_time": "2024-10-25T21:05:34.177059Z", "start_time": "2024-10-25T21:05:34.012517Z" }, "execution": { "iopub.status.busy": "2024-10-29T02:13:42.125629Z", "iopub.execute_input": "2024-10-29T02:13:42.126383Z", "iopub.status.idle": "2024-10-29T02:13:42.135764Z", "shell.execute_reply.started": "2024-10-29T02:13:42.126325Z", "shell.execute_reply": "2024-10-29T02:13:42.134585Z" }, "trusted": true, "id": "VYNuYASythA8" }, "execution_count": 21, "outputs": [] }, { "cell_type": "markdown", "source": [ "## Funzioni di Plot" ], "metadata": { "id": "uHKkULSNthA8" } }, { "cell_type": "code", "source": [ "def save_plot(plt, title, output_dir='./kaggle/working/plots'):\n", " os.makedirs(output_dir, exist_ok=True)\n", " filename = \"\".join(x for x in title if x.isalnum() or x in [' ', '-', '_']).rstrip()\n", " filename = filename.replace(' ', '_').lower()\n", " filepath = os.path.join(output_dir, f\"{filename}.png\")\n", " plt.savefig(filepath, bbox_inches='tight', dpi=300)\n", " print(f\"Plot salvato come: {filepath}\")" ], "metadata": { "execution": { "iopub.status.busy": "2024-10-29T02:13:42.140387Z", "iopub.execute_input": "2024-10-29T02:13:42.140754Z", "iopub.status.idle": "2024-10-29T02:13:42.148616Z", "shell.execute_reply.started": "2024-10-29T02:13:42.140717Z", "shell.execute_reply": "2024-10-29T02:13:42.147739Z" }, "trusted": true, "id": "gzvYVaBPthA8" }, "execution_count": 6, "outputs": [] }, { "cell_type": "markdown", "source": [ "## 1. Caricamento e preparazione dei Dati Meteo" ], "metadata": { "id": "lhipxRbMthA8" } }, { "cell_type": "code", "source": [ "# Function to convert csv to parquet\n", "def csv_to_parquet(csv_file, parquet_file, chunksize=100000):\n", " writer = None\n", "\n", " for chunk in pd.read_csv(csv_file, chunksize=chunksize):\n", " if writer is None:\n", "\n", " table = pa.Table.from_pandas(chunk)\n", " writer = pq.ParquetWriter(parquet_file, table.schema)\n", " else:\n", " table = pa.Table.from_pandas(chunk)\n", "\n", " writer.write_table(table)\n", "\n", " if writer:\n", " writer.close()\n", "\n", " print(f\"File conversion completed : {csv_file} -> {parquet_file}\")\n", "\n", "\n", "def read_json_files(folder_path):\n", " all_data = []\n", "\n", " file_list = sorted(os.listdir(folder_path))\n", "\n", " for filename in file_list:\n", " if filename.endswith('.json'):\n", " file_path = os.path.join(folder_path, filename)\n", " try:\n", " with open(file_path, 'r') as file:\n", " data = json.load(file)\n", " all_data.extend(data['days'])\n", " except Exception as e:\n", " print(f\"Error processing file '{filename}': {str(e)}\")\n", "\n", " return all_data\n", "\n", "\n", "def create_weather_dataset(data):\n", " dataset = []\n", " seen_datetimes = set()\n", "\n", " for day in data:\n", " date = day['datetime']\n", " for hour in day['hours']:\n", " datetime_str = f\"{date} {hour['datetime']}\"\n", "\n", " # Verifico se questo datetime è già stato visto\n", " if datetime_str in seen_datetimes:\n", " continue\n", "\n", " seen_datetimes.add(datetime_str)\n", "\n", " if isinstance(hour['preciptype'], list):\n", " preciptype = \"__\".join(hour['preciptype'])\n", " else:\n", " preciptype = hour['preciptype'] if hour['preciptype'] else \"\"\n", "\n", " conditions = hour['conditions'].replace(', ', '__').replace(' ', '_').lower()\n", "\n", " row = {\n", " 'datetime': datetime_str,\n", " 'temp': hour['temp'],\n", " 'feelslike': hour['feelslike'],\n", " 'humidity': hour['humidity'],\n", " 'dew': hour['dew'],\n", " 'precip': hour['precip'],\n", " 'snow': hour['snow'],\n", " 'preciptype': preciptype.lower(),\n", " 'windspeed': hour['windspeed'],\n", " 'winddir': hour['winddir'],\n", " 'pressure': hour['pressure'],\n", " 'cloudcover': hour['cloudcover'],\n", " 'visibility': hour['visibility'],\n", " 'solarradiation': hour['solarradiation'],\n", " 'solarenergy': hour['solarenergy'],\n", " 'uvindex': hour['uvindex'],\n", " 'conditions': conditions,\n", " 'tempmax': day['tempmax'],\n", " 'tempmin': day['tempmin'],\n", " 'precipprob': day['precipprob'],\n", " 'precipcover': day['precipcover']\n", " }\n", " dataset.append(row)\n", "\n", " dataset.sort(key=lambda x: datetime.strptime(x['datetime'], \"%Y-%m-%d %H:%M:%S\"))\n", "\n", " return pd.DataFrame(dataset)\n", "\n", "\n", "folder_path = './data/weather'\n", "#raw_data = read_json_files(folder_path)\n", "#weather_data = create_weather_dataset(raw_data)\n", "#weather_data['datetime'] = pd.to_datetime(weather_data['datetime'], errors='coerce')\n", "#weather_data['date'] = weather_data['datetime'].dt.date\n", "#weather_data = weather_data.dropna(subset=['datetime'])\n", "#weather_data['datetime'] = pd.to_datetime(weather_data['datetime'])\n", "#weather_data['year'] = weather_data['datetime'].dt.year\n", "#weather_data['month'] = weather_data['datetime'].dt.month\n", "#weather_data['day'] = weather_data['datetime'].dt.day\n", "#weather_data.head()\n", "\n", "#weather_data.to_parquet('./data/weather_data.parquet')" ], "metadata": { "ExecuteTime": { "end_time": "2024-10-25T21:05:45.017577Z", "start_time": "2024-10-25T21:05:34.194467Z" }, "execution": { "iopub.status.busy": "2024-10-29T02:13:42.165137Z", "iopub.execute_input": "2024-10-29T02:13:42.165549Z", "iopub.status.idle": "2024-10-29T02:13:42.184279Z", "shell.execute_reply.started": "2024-10-29T02:13:42.165510Z", "shell.execute_reply": "2024-10-29T02:13:42.183118Z" }, "trusted": true, "id": "d_WHC4rJthA8" }, "execution_count": 7, "outputs": [] }, { "cell_type": "markdown", "source": [], "metadata": { "id": "NOFLn9dJthA9" } }, { "cell_type": "code", "source": [ "# Crea le sequenze per LSTM\n", "def create_sequences(timesteps, X, y=None):\n", " \"\"\"\n", " Crea sequenze temporali dai dati.\n", "\n", " Parameters:\n", " -----------\n", " X : array-like\n", " Dati di input\n", " timesteps : int\n", " Numero di timestep per ogni sequenza\n", " y : array-like, optional\n", " Target values. Se None, crea sequenze solo per X\n", "\n", " Returns:\n", " --------\n", " tuple o array\n", " Se y è fornito: (X_sequences, y_sequences)\n", " Se y è None: X_sequences\n", " \"\"\"\n", " Xs = []\n", " for i in range(len(X) - timesteps):\n", " Xs.append(X[i:i + timesteps])\n", "\n", " if y is not None:\n", " ys = []\n", " for i in range(len(X) - timesteps):\n", " ys.append(y[i + timesteps])\n", " return np.array(Xs), np.array(ys)\n", "\n", " return np.array(Xs)\n", "\n", "\n", "# Funzioni per costruire il modello LSTM avanzato\n", "def create_residual_lstm_layer(x, units, dropout_rate, l2_reg=0.01, return_sequences=True):\n", " residual = x\n", " x = Bidirectional(LSTM(units, return_sequences=return_sequences, kernel_regularizer=l2(l2_reg)))(x)\n", " x = LayerNormalization()(x)\n", " x = Dropout(dropout_rate)(x)\n", " # Adjust residual dimension and handle return_sequences\n", " if return_sequences:\n", " if int(residual.shape[-1]) != 2 * units:\n", " residual = Dense(2 * units, activation='linear')(residual)\n", " x = Add()([x, residual])\n", " return x\n", "\n", "\n", "def attention_block(x, units, num_heads=8):\n", " attention = MultiHeadAttention(num_heads=num_heads, key_dim=units)(x, x)\n", " x = Add()([x, attention])\n", " x = LayerNormalization()(x)\n", " return x\n", "\n", "\n", "def create_tcn_block(x, filters, kernel_size, dilation_rate, dropout_rate=0.1):\n", " # Usa ZeroPadding1D invece di tf.pad\n", " padding = (kernel_size - 1) * dilation_rate\n", " x_padded = ZeroPadding1D(padding=(padding, 0))(x)\n", "\n", " conv = Conv1D(\n", " filters=filters,\n", " kernel_size=kernel_size,\n", " dilation_rate=dilation_rate,\n", " padding='valid',\n", " kernel_initializer='he_normal',\n", " kernel_regularizer=l2(1e-4)\n", " )(x_padded)\n", "\n", " conv = BatchNormalization()(conv)\n", " conv = Activation('swish')(conv)\n", " conv = Dropout(dropout_rate)(conv)\n", "\n", " # Skip connection\n", " if x.shape[-1] != filters:\n", " x = Conv1D(filters, 1)(x)\n", "\n", " return Add()([x, conv])\n", "\n", "def transformer_block(x, num_heads, key_dim, ff_dim, dropout=0.1):\n", " attention = MultiHeadAttention(\n", " num_heads=num_heads,\n", " key_dim=key_dim,\n", " dropout=dropout\n", " )(x, x)\n", " x = Add()([x, attention])\n", " x = LayerNormalization()(x)\n", "\n", " ffn = Dense(ff_dim, activation='swish')(x)\n", " ffn = Dropout(dropout)(ffn)\n", " ffn = Dense(x.shape[-1])(ffn)\n", "\n", " x = Add()([x, ffn])\n", " x = LayerNormalization()(x)\n", "\n", " return x\n", "\n", "def build_hybrid_model_multitarget(input_shape, num_targets=3, l2_lambda=0.001):\n", " inputs = Input(shape=input_shape)\n", "\n", " # 1. Branch LSTM con residual connections\n", " lstm_branch = create_residual_lstm_layer(inputs, 128, 0.2, l2_lambda, return_sequences=True)\n", " lstm_branch = create_residual_lstm_layer(lstm_branch, 64, 0.2, l2_lambda, return_sequences=True)\n", "\n", " # 2. Branch TCN\n", " tcn_branch = Dense(128)(inputs)\n", " tcn_branch = create_tcn_block(tcn_branch, 128, kernel_size=3, dilation_rate=1)\n", " tcn_branch = create_tcn_block(tcn_branch, 128, kernel_size=3, dilation_rate=2)\n", " tcn_branch = create_tcn_block(tcn_branch, 128, kernel_size=3, dilation_rate=4)\n", "\n", " # 3. Fusione dei branch\n", " x = Concatenate()([lstm_branch, tcn_branch])\n", "\n", " # 4. Position encoding\n", " timesteps = input_shape[0]\n", " pos_encoding = tf.expand_dims(\n", " tf.cast(tf.range(timesteps, dtype=tf.float32), tf.float32),\n", " axis=-1\n", " )\n", " pos_encoding = Dense(x.shape[-1])(pos_encoding)\n", " pos_encoding = Lambda(lambda x: tf.expand_dims(x, axis=0))(pos_encoding)\n", " x = Add()([x, pos_encoding])\n", "\n", " # 5. Transformer blocks con attention\n", " x = transformer_block(x, num_heads=8, key_dim=32, ff_dim=256, dropout=0.1)\n", " x = transformer_block(x, num_heads=4, key_dim=32, ff_dim=128, dropout=0.1)\n", "\n", " # 6. Attention blocks\n", " x = attention_block(x, x.shape[-1], num_heads=8)\n", " x = attention_block(x, x.shape[-1], num_heads=4)\n", "\n", " # 7. Feature Pooling\n", " x_max = GlobalMaxPooling1D()(x)\n", " x_avg = GlobalAveragePooling1D()(x)\n", " x = Concatenate()([x_max, x_avg])\n", "\n", " # 8. Shared layers\n", " residual = x\n", " x = Dense(128, kernel_regularizer=l2(l2_lambda))(x)\n", " x = BatchNormalization()(x)\n", " x = Activation('swish')(x)\n", " x = Dropout(0.2)(x)\n", "\n", " if residual.shape[-1] != 128:\n", " residual = Dense(128)(residual)\n", " x = Add()([x, residual])\n", "\n", " # Branch specifiche per target con dimensioni diverse\n", " outputs = []\n", "\n", " # Branch più grande per solarradiation\n", " branch_0 = Dense(128, kernel_regularizer=l2(l2_lambda))(x)\n", " branch_0 = BatchNormalization()(branch_0)\n", " branch_0 = Activation('swish')(branch_0)\n", " branch_0 = Dropout(0.2)(branch_0)\n", "\n", " branch_0 = Dense(64, kernel_regularizer=l2(l2_lambda))(branch_0)\n", " branch_0 = BatchNormalization()(branch_0)\n", " branch_0 = Activation('swish')(branch_0)\n", " branch_0 = Dropout(0.15)(branch_0)\n", "\n", " output_0 = Dense(1, name='target_0', kernel_regularizer=l2(l2_lambda))(branch_0)\n", " outputs.append(output_0)\n", "\n", " # Branch per solarenergy e uvindex\n", " for i in range(1, num_targets):\n", " branch = Dense(64, kernel_regularizer=l2(l2_lambda))(x)\n", " branch = BatchNormalization()(branch)\n", " branch = Activation('swish')(branch)\n", " branch = Dropout(0.15)(branch)\n", "\n", " branch = Dense(32, kernel_regularizer=l2(l2_lambda))(branch)\n", " branch = BatchNormalization()(branch)\n", " branch = Activation('swish')(branch)\n", " branch = Dropout(0.1)(branch)\n", "\n", " output = Dense(1, name=f'target_{i}', kernel_regularizer=l2(l2_lambda))(branch)\n", " outputs.append(output)\n", "\n", " model = Model(inputs=inputs, outputs=outputs)\n", " return model\n", "\n", "\n", "def get_season(date):\n", " month = date.month\n", " day = date.day\n", " if (month == 12 and day >= 21) or (month <= 3 and day < 20):\n", " return 'Winter'\n", " elif (month == 3 and day >= 20) or (month <= 6 and day < 21):\n", " return 'Spring'\n", " elif (month == 6 and day >= 21) or (month <= 9 and day < 23):\n", " return 'Summer'\n", " elif (month == 9 and day >= 23) or (month <= 12 and day < 21):\n", " return 'Autumn'\n", " else:\n", " return 'Unknown'\n", "\n", "\n", "def get_time_period(hour):\n", " if 5 <= hour < 12:\n", " return 'Morning'\n", " elif 12 <= hour < 17:\n", " return 'Afternoon'\n", " elif 17 <= hour < 21:\n", " return 'Evening'\n", " else:\n", " return 'Night'\n", "\n", "\n", "def add_time_features(df):\n", " df['datetime'] = pd.to_datetime(df['datetime'])\n", " df['timestamp'] = df['datetime'].astype(np.int64) // 10 ** 9\n", " df['year'] = df['datetime'].dt.year\n", " df['month'] = df['datetime'].dt.month\n", " df['day'] = df['datetime'].dt.day\n", " df['hour'] = df['datetime'].dt.hour\n", " df['minute'] = df['datetime'].dt.minute\n", " df['hour_sin'] = np.sin(df['hour'] * (2 * np.pi / 24))\n", " df['hour_cos'] = np.cos(df['hour'] * (2 * np.pi / 24))\n", " df['day_of_week'] = df['datetime'].dt.dayofweek\n", " df['day_of_year'] = df['datetime'].dt.dayofyear\n", " df['week_of_year'] = df['datetime'].dt.isocalendar().week.astype(int)\n", " df['quarter'] = df['datetime'].dt.quarter\n", " df['is_month_end'] = df['datetime'].dt.is_month_end.astype(int)\n", " df['is_quarter_end'] = df['datetime'].dt.is_quarter_end.astype(int)\n", " df['is_year_end'] = df['datetime'].dt.is_year_end.astype(int)\n", " df['month_sin'] = np.sin(df['month'] * (2 * np.pi / 12))\n", " df['month_cos'] = np.cos(df['month'] * (2 * np.pi / 12))\n", " df['day_of_year_sin'] = np.sin(df['day_of_year'] * (2 * np.pi / 365.25))\n", " df['day_of_year_cos'] = np.cos(df['day_of_year'] * (2 * np.pi / 365.25))\n", " df['season'] = df['datetime'].apply(get_season)\n", " df['time_period'] = df['hour'].apply(get_time_period)\n", " return df\n", "\n", "def add_solar_features(df):\n", " # Calcolo dell'angolo solare\n", " df['solar_angle'] = np.sin(df['day_of_year'] * (2 * np.pi / 365.25)) * np.sin(df['hour'] * (2 * np.pi / 24))\n", "\n", " # Interazioni tra features rilevanti\n", " df['cloud_temp_interaction'] = df['cloudcover'] * df['temp']\n", " df['visibility_cloud_interaction'] = df['visibility'] * (100 - df['cloudcover'])\n", "\n", " # Feature derivate\n", " df['clear_sky_index'] = (100 - df['cloudcover']) / 100\n", " df['temp_gradient'] = df['temp'] - df['tempmin']\n", "\n", " return df\n", "\n", "def add_solar_specific_features(df):\n", " # Angolo solare e durata del giorno\n", " df['day_length'] = 12 + 3 * np.sin(2 * np.pi * (df['day_of_year'] - 81) / 365.25)\n", " df['solar_noon'] = 12 - df['hour']\n", " df['solar_elevation'] = np.sin(2 * np.pi * df['day_of_year'] / 365.25) * np.cos(2 * np.pi * df['solar_noon'] / 24)\n", "\n", " # Interazioni\n", " df['cloud_elevation'] = df['cloudcover'] * df['solar_elevation']\n", " df['visibility_elevation'] = df['visibility'] * df['solar_elevation']\n", "\n", " # Rolling features con finestre più ampie\n", " df['cloud_rolling_12h'] = df['cloudcover'].rolling(window=12).mean()\n", " df['temp_rolling_12h'] = df['temp'].rolling(window=12).mean()\n", "\n", " return df\n", "\n", "def add_advanced_features(df):\n", " # Features esistenti\n", " df = add_time_features(df)\n", " df = add_solar_features(df)\n", " df = add_solar_specific_features(df)\n", "\n", " # Aggiungi interazioni tra variabili meteorologiche\n", " df['temp_humidity'] = df['temp'] * df['humidity']\n", " df['temp_cloudcover'] = df['temp'] * df['cloudcover']\n", " df['visibility_cloudcover'] = df['visibility'] * df['cloudcover']\n", "\n", " # Features derivate per la radiazione solare\n", " df['clear_sky_factor'] = (100 - df['cloudcover']) / 100\n", " df['day_length'] = np.sin(df['day_of_year_sin']) * 12 + 12 # approssimazione della durata del giorno\n", "\n", " # Lag features\n", " df['temp_1h_lag'] = df['temp'].shift(1)\n", " df['cloudcover_1h_lag'] = df['cloudcover'].shift(1)\n", " df['humidity_1h_lag'] = df['humidity'].shift(1)\n", "\n", " # Rolling means\n", " df['temp_rolling_mean_6h'] = df['temp'].rolling(window=6).mean()\n", " df['cloudcover_rolling_mean_6h'] = df['cloudcover'].rolling(window=6).mean()\n", "\n", " return df\n", "\n", "\n", "\n", "# Carica il dataset\n", "weather_data = pd.read_parquet('./kaggle/input/olive-oil/weather_data.parquet')\n", "\n", "# Aggiungi le caratteristiche temporali\n", "weather_data = add_advanced_features(weather_data)\n", "\n", "# Encoding delle variabili categoriali\n", "weather_data = pd.get_dummies(weather_data, columns=['season', 'time_period'], drop_first=True)\n", "\n", "weather_data.to_parquet('./kaggle/working/weather_data_extended.parquet')\n", "\n", "# Dividi i dati in quelli dopo il 2010 e quelli prima del 2010\n", "data_after_2010 = weather_data[weather_data['year'] >= 2010].copy()\n", "data_before_2010 = weather_data[weather_data['year'] < 2010].copy()\n", "\n", "# Aggiorna le target variables se necessario\n", "target_variables = ['solarradiation', 'solarenergy', 'uvindex']\n", "\n", "# Seleziona le features\n", "features = [\n", " 'temp', 'tempmin', 'tempmax', 'humidity', 'cloudcover', 'windspeed', 'pressure', 'visibility',\n", " 'hour_sin', 'hour_cos', 'month_sin', 'month_cos', 'day_of_year_sin', 'day_of_year_cos','temp_humidity','temp_cloudcover','visibility_cloudcover',\n", " 'clear_sky_factor', 'day_length', 'temp_1h_lag', 'cloudcover_1h_lag', 'humidity_1h_lag',\n", " 'temp_rolling_mean_6h', 'cloudcover_rolling_mean_6h',\n", " ] + [col for col in weather_data.columns if 'season_' in col or 'time_period_' in col]\n", "\n", "# Prepara data_after_2010\n", "data_after_2010 = data_after_2010.sort_values('datetime')\n", "data_after_2010.set_index('datetime', inplace=True)\n", "\n", "# Interpola eventuali valori mancanti nelle variabili target\n", "columns_to_interpolate = target_variables\n", "for column in columns_to_interpolate:\n", " data_after_2010[column] = data_after_2010[column].interpolate(method='time')\n", "\n", "# Rimuovi eventuali valori mancanti residui\n", "data_after_2010.dropna(subset=features + target_variables, inplace=True)\n", "\n", "# Crea X e y\n", "X = data_after_2010[features].values\n", "y = data_after_2010[target_variables].values\n", "\n", "# Normalizza le features\n", "scaler_X = MinMaxScaler()\n", "X_scaled = scaler_X.fit_transform(X)\n", "\n", "\n", "def prepare_multi_target_datasets(X_scaled, y, target_variables):\n", " \"\"\"\n", " Prepara dataset separati per ogni target variable e restituisce anche gli scaler\n", " per un uso successivo in fase di predizione.\n", "\n", " Parameters:\n", " -----------\n", " X_scaled : numpy.ndarray\n", " Features già scalate\n", " y : numpy.ndarray\n", " Target variables (matrice con una colonna per ogni target)\n", " target_variables : list\n", " Lista dei nomi delle variabili target\n", "\n", " Returns:\n", " --------\n", " tuple (dict, dict)\n", " - Primo dict: contiene i dataset per ogni target\n", " - Secondo dict: contiene gli scaler per ogni target\n", " \"\"\"\n", "\n", " # Inizializza i dizionari per contenere i dataset e gli scaler\n", " train_datasets = {}\n", " scalers_dict = {}\n", "\n", " # Scala e splitta i dati per ogni target\n", " for i, target in enumerate(target_variables):\n", " # Scala il target corrente\n", " scaler = MinMaxScaler()\n", " y_scaled_current = scaler.fit_transform(y[:, i].reshape(-1, 1)).flatten()\n", " scalers_dict[target] = scaler\n", "\n", " # Split dei dati per il target corrente\n", " X_train_full, X_test, y_train_full, y_test = train_test_split(\n", " X_scaled,\n", " y_scaled_current,\n", " test_size=0.2,\n", " shuffle=False\n", " )\n", "\n", " # Ulteriore split per validation\n", " X_train, X_val, y_train, y_val = train_test_split(\n", " X_train_full,\n", " y_train_full,\n", " test_size=0.2,\n", " shuffle=False\n", " )\n", "\n", " # Salva i dataset per questo target\n", " train_datasets[target] = {\n", " 'X_train': X_train,\n", " 'X_val': X_val,\n", " 'X_test': X_test,\n", " 'y_train': y_train.reshape(-1, 1),\n", " 'y_val': y_val.reshape(-1, 1),\n", " 'y_test': y_test.reshape(-1, 1)\n", " }\n", "\n", " return train_datasets, scalers_dict\n", "\n", "\n", "datasets, scalers = prepare_multi_target_datasets(X_scaled, y, target_variables)" ], "metadata": { "ExecuteTime": { "end_time": "2024-10-26T05:43:32.169183Z", "start_time": "2024-10-26T05:43:29.609044Z" }, "execution": { "iopub.status.busy": "2024-10-29T02:13:42.195101Z", "iopub.execute_input": "2024-10-29T02:13:42.195484Z", "iopub.status.idle": "2024-10-29T02:13:45.718109Z", "shell.execute_reply.started": "2024-10-29T02:13:42.195446Z", "shell.execute_reply": "2024-10-29T02:13:45.717046Z" }, "trusted": true, "id": "uvIOrixethA9" }, "execution_count": 23, "outputs": [] }, { "cell_type": "code", "source": [ "class WarmUpLearningRateSchedule(tf.keras.optimizers.schedules.LearningRateSchedule):\n", " def __init__(self, initial_learning_rate=1e-3, warmup_steps=1000, decay_steps=10000):\n", " super().__init__()\n", " self.initial_learning_rate = initial_learning_rate\n", " self.warmup_steps = warmup_steps\n", " self.decay_steps = decay_steps\n", "\n", " def __call__(self, step):\n", " warmup_pct = tf.cast(step, tf.float32) / self.warmup_steps\n", " warmup_lr = self.initial_learning_rate * warmup_pct\n", "\n", " decay_factor = tf.pow(0.1, tf.cast(step, tf.float32) / self.decay_steps)\n", " decayed_lr = self.initial_learning_rate * decay_factor\n", "\n", " final_lr = tf.where(step < self.warmup_steps, warmup_lr, decayed_lr)\n", " return final_lr\n", "\n", " def get_config(self):\n", " return {\n", " 'initial_learning_rate': self.initial_learning_rate,\n", " 'warmup_steps': self.warmup_steps,\n", " 'decay_steps': self.decay_steps\n", " }\n", "\n", "# numero di timesteps (utilizziamo le ultime 24 ore)\n", "timesteps = 24\n", "\n", "# Prepara i dati in formato multi-target\n", "def prepare_multitarget_sequences(X_scaled, y, timesteps):\n", " \"\"\"\n", " Prepara i dati per il training multi-target\n", " \"\"\"\n", " # Split dei dati\n", " X_train_full, X_test, y_train_full, y_test = train_test_split(\n", " X_scaled, y, test_size=0.2, shuffle=False\n", " )\n", "\n", " X_train, X_val, y_train, y_val = train_test_split(\n", " X_train_full, y_train_full, test_size=0.2, shuffle=False\n", " )\n", "\n", " # Crea le sequenze\n", " X_train_seq, y_train_seq = create_sequences(timesteps, X_train, y_train)\n", " X_val_seq, y_val_seq = create_sequences(timesteps, X_val, y_val)\n", " X_test_seq, y_test_seq = create_sequences(timesteps, X_test, y_test)\n", "\n", " # Scaling dei target\n", " scalers = {}\n", " y_train_scaled = np.zeros_like(y_train_seq)\n", " y_val_scaled = np.zeros_like(y_val_seq)\n", " y_test_scaled = np.zeros_like(y_test_seq)\n", "\n", " for i in range(y.shape[1]):\n", " scaler = MinMaxScaler()\n", " y_train_scaled[:, i] = scaler.fit_transform(y_train_seq[:, i].reshape(-1, 1)).ravel()\n", " y_val_scaled[:, i] = scaler.transform(y_val_seq[:, i].reshape(-1, 1)).ravel()\n", " y_test_scaled[:, i] = scaler.transform(y_test_seq[:, i].reshape(-1, 1)).ravel()\n", " scalers[target_variables[i]] = scaler\n", "\n", " return {\n", " 'X_train': X_train_seq,\n", " 'y_train': y_train_scaled,\n", " 'X_val': X_val_seq,\n", " 'y_val': y_val_scaled,\n", " 'X_test': X_test_seq,\n", " 'y_test': y_test_scaled,\n", " 'scalers': scalers\n", " }\n", "\n", "# Prepara i dati\n", "data = prepare_multitarget_sequences(X_scaled, y, timesteps)\n", "\n", "# Crea il modello multi-target\n", "print(\"Addestramento del modello multi-target\")\n", "model = build_hybrid_model_multitarget(\n", " input_shape=(timesteps, X_scaled.shape[1]),\n", " num_targets=len(target_variables),\n", " l2_lambda=0.001\n", ")\n", "\n", "lr_schedule = WarmUpLearningRateSchedule(\n", " initial_learning_rate=1e-3,\n", " warmup_steps=500,\n", " decay_steps=10000\n", ")\n", "\n", "def weighted_huber_loss(y_true, y_pred):\n", " error = y_true - y_pred\n", " is_small_error = tf.abs(error) <= 1\n", " squared_loss = 0.5 * tf.square(error)\n", " linear_loss = tf.abs(error) - 0.5\n", "\n", " # Pesi maggiori per gli errori più grandi\n", " weights = tf.where(is_small_error, 1.0, 2.0)\n", "\n", " return tf.reduce_mean(tf.where(is_small_error, squared_loss, linear_loss) * weights)\n", "\n", "# Usa la custom loss nella compilazione\n", "model.compile(\n", " optimizer=tf.keras.optimizers.AdamW(\n", " learning_rate=lr_schedule,\n", " weight_decay=0.01\n", " ),\n", " loss={\n", " 'target_0': weighted_huber_loss, # solarradiation\n", " 'target_1': 'huber', # solarenergy\n", " 'target_2': 'huber' # uvindex\n", " },\n", " loss_weights={f'target_{i}': 1.0 for i in range(len(target_variables))},\n", " metrics={f'target_{i}': ['mae', 'mse'] for i in range(len(target_variables))}\n", ")\n", "model.summary()\n", "\n", "# Callbacks\n", "early_stopping = EarlyStopping(\n", " monitor='val_loss',\n", " patience=15,\n", " restore_best_weights=True,\n", " mode='min'\n", ")\n", "\n", "# Crea le directory per i modelli e i log\n", "model_dir = './kaggle/working/models/multitarget'\n", "log_dir = f'{model_dir}/logs'\n", "os.makedirs(model_dir, exist_ok=True)\n", "os.makedirs(log_dir, exist_ok=True)\n", "\n", "# Training\n", "history = model.fit(\n", " data['X_train'],\n", " {f'target_{i}': data['y_train'][:, i] for i in range(len(target_variables))},\n", " validation_data=(\n", " data['X_val'],\n", " {f'target_{i}': data['y_val'][:, i] for i in range(len(target_variables))}\n", " ),\n", " epochs=100,\n", " batch_size=256,\n", " callbacks=[\n", " early_stopping,\n", " tf.keras.callbacks.ModelCheckpoint(\n", " filepath=os.path.join(model_dir, 'best_model_{epoch:02d}_{val_loss:.4f}.keras'),\n", " monitor='val_loss',\n", " save_best_only=True,\n", " mode='min'\n", " ),\n", " tf.keras.callbacks.TensorBoard(\n", " log_dir=log_dir,\n", " histogram_freq=1,\n", " write_graph=True,\n", " update_freq='epoch'\n", " )\n", " ],\n", " verbose=1\n", ")" ], "metadata": { "jupyter": { "is_executing": true }, "ExecuteTime": { "start_time": "2024-10-26T05:43:33.294101Z" }, "execution": { "iopub.status.busy": "2024-10-29T02:13:45.719999Z", "iopub.execute_input": "2024-10-29T02:13:45.720423Z", "iopub.status.idle": "2024-10-29T02:51:32.283254Z", "shell.execute_reply.started": "2024-10-29T02:13:45.720381Z", "shell.execute_reply": "2024-10-29T02:51:32.282161Z" }, "trusted": true, "id": "7qF_3gVpthA9", "outputId": "0de98483-956b-45e2-f9f3-8410f79cd307", "colab": { "base_uri": "https://localhost:8080/", "height": 1000 } }, "execution_count": null, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Addestramento del modello multi-target\n" ] }, { "output_type": "display_data", "data": { "text/plain": [ "\u001B[1mModel: \"functional_5\"\u001B[0m\n" ], "text/html": [ "
Model: \"functional_5\"\n",
"\n"
]
},
"metadata": {}
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓\n",
"┃\u001B[1m \u001B[0m\u001B[1mLayer (type) \u001B[0m\u001B[1m \u001B[0m┃\u001B[1m \u001B[0m\u001B[1mOutput Shape \u001B[0m\u001B[1m \u001B[0m┃\u001B[1m \u001B[0m\u001B[1m Param #\u001B[0m\u001B[1m \u001B[0m┃\u001B[1m \u001B[0m\u001B[1mConnected to \u001B[0m\u001B[1m \u001B[0m┃\n",
"┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩\n",
"│ input_layer_7 │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m31\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ - │\n",
"│ (\u001B[38;5;33mInputLayer\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_61 (\u001B[38;5;33mDense\u001B[0m) │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m4,096\u001B[0m │ input_layer_7[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ zero_padding1d_6 │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m26\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ dense_61[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"│ (\u001B[38;5;33mZeroPadding1D\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv1d_6 (\u001B[38;5;33mConv1D\u001B[0m) │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m49,280\u001B[0m │ zero_padding1d_6[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_29 │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m512\u001B[0m │ conv1d_6[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"│ (\u001B[38;5;33mBatchNormalization\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_29 │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ batch_normalization_2… │\n",
"│ (\u001B[38;5;33mActivation\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_69 (\u001B[38;5;33mDropout\u001B[0m) │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ activation_29[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_47 (\u001B[38;5;33mAdd\u001B[0m) │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ dense_61[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m], │\n",
"│ │ │ │ dropout_69[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ zero_padding1d_7 │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m28\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ add_47[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"│ (\u001B[38;5;33mZeroPadding1D\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv1d_7 (\u001B[38;5;33mConv1D\u001B[0m) │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m49,280\u001B[0m │ zero_padding1d_7[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_30 │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m512\u001B[0m │ conv1d_7[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"│ (\u001B[38;5;33mBatchNormalization\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_30 │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ batch_normalization_3… │\n",
"│ (\u001B[38;5;33mActivation\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ bidirectional_20 │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m163,840\u001B[0m │ input_layer_7[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"│ (\u001B[38;5;33mBidirectional\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_70 (\u001B[38;5;33mDropout\u001B[0m) │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ activation_30[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ layer_normalization_38 │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m512\u001B[0m │ bidirectional_20[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"│ (\u001B[38;5;33mLayerNormalization\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_48 (\u001B[38;5;33mAdd\u001B[0m) │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ add_47[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m], │\n",
"│ │ │ │ dropout_70[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_67 (\u001B[38;5;33mDropout\u001B[0m) │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ layer_normalization_3… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_59 (\u001B[38;5;33mDense\u001B[0m) │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m8,192\u001B[0m │ input_layer_7[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ zero_padding1d_8 │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m32\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ add_48[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"│ (\u001B[38;5;33mZeroPadding1D\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_45 (\u001B[38;5;33mAdd\u001B[0m) │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ dropout_67[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m], │\n",
"│ │ │ │ dense_59[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv1d_8 (\u001B[38;5;33mConv1D\u001B[0m) │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m49,280\u001B[0m │ zero_padding1d_8[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ bidirectional_21 │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m164,352\u001B[0m │ add_45[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"│ (\u001B[38;5;33mBidirectional\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_31 │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m512\u001B[0m │ conv1d_8[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"│ (\u001B[38;5;33mBatchNormalization\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ layer_normalization_39 │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m256\u001B[0m │ bidirectional_21[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"│ (\u001B[38;5;33mLayerNormalization\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_31 │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ batch_normalization_3… │\n",
"│ (\u001B[38;5;33mActivation\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_68 (\u001B[38;5;33mDropout\u001B[0m) │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ layer_normalization_3… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_60 (\u001B[38;5;33mDense\u001B[0m) │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m32,896\u001B[0m │ add_45[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_71 (\u001B[38;5;33mDropout\u001B[0m) │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ activation_31[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_46 (\u001B[38;5;33mAdd\u001B[0m) │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ dropout_68[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m], │\n",
"│ │ │ │ dense_60[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_49 (\u001B[38;5;33mAdd\u001B[0m) │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ add_48[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m], │\n",
"│ │ │ │ dropout_71[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ concatenate_4 │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ add_46[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m], │\n",
"│ (\u001B[38;5;33mConcatenate\u001B[0m) │ │ │ add_49[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_50 (\u001B[38;5;33mAdd\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ concatenate_4[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ multi_head_attention_14 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m263,168\u001B[0m │ add_50[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m], │\n",
"│ (\u001B[38;5;33mMultiHeadAttention\u001B[0m) │ │ │ add_50[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_51 (\u001B[38;5;33mAdd\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ add_50[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m], │\n",
"│ │ │ │ multi_head_attention_… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ layer_normalization_40 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m512\u001B[0m │ add_51[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"│ (\u001B[38;5;33mLayerNormalization\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_63 (\u001B[38;5;33mDense\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m65,792\u001B[0m │ layer_normalization_4… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_73 (\u001B[38;5;33mDropout\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ dense_63[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_64 (\u001B[38;5;33mDense\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m65,792\u001B[0m │ dropout_73[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_52 (\u001B[38;5;33mAdd\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ layer_normalization_4… │\n",
"│ │ │ │ dense_64[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ layer_normalization_41 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m512\u001B[0m │ add_52[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"│ (\u001B[38;5;33mLayerNormalization\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ multi_head_attention_15 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m131,712\u001B[0m │ layer_normalization_4… │\n",
"│ (\u001B[38;5;33mMultiHeadAttention\u001B[0m) │ │ │ layer_normalization_4… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_53 (\u001B[38;5;33mAdd\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ layer_normalization_4… │\n",
"│ │ │ │ multi_head_attention_… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ layer_normalization_42 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m512\u001B[0m │ add_53[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"│ (\u001B[38;5;33mLayerNormalization\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_65 (\u001B[38;5;33mDense\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m32,896\u001B[0m │ layer_normalization_4… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_75 (\u001B[38;5;33mDropout\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ dense_65[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_66 (\u001B[38;5;33mDense\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m33,024\u001B[0m │ dropout_75[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_54 (\u001B[38;5;33mAdd\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ layer_normalization_4… │\n",
"│ │ │ │ dense_66[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ layer_normalization_43 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m512\u001B[0m │ add_54[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"│ (\u001B[38;5;33mLayerNormalization\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ multi_head_attention_16 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m2,103,552\u001B[0m │ layer_normalization_4… │\n",
"│ (\u001B[38;5;33mMultiHeadAttention\u001B[0m) │ │ │ layer_normalization_4… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_55 (\u001B[38;5;33mAdd\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ layer_normalization_4… │\n",
"│ │ │ │ multi_head_attention_… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ layer_normalization_44 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m512\u001B[0m │ add_55[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"│ (\u001B[38;5;33mLayerNormalization\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ multi_head_attention_17 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m1,051,904\u001B[0m │ layer_normalization_4… │\n",
"│ (\u001B[38;5;33mMultiHeadAttention\u001B[0m) │ │ │ layer_normalization_4… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_56 (\u001B[38;5;33mAdd\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ layer_normalization_4… │\n",
"│ │ │ │ multi_head_attention_… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ layer_normalization_45 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m24\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m512\u001B[0m │ add_56[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"│ (\u001B[38;5;33mLayerNormalization\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ global_max_pooling1d_2 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ layer_normalization_4… │\n",
"│ (\u001B[38;5;33mGlobalMaxPooling1D\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ global_average_pooling1d… │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ layer_normalization_4… │\n",
"│ (\u001B[38;5;33mGlobalAveragePooling1D\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ concatenate_5 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m512\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ global_max_pooling1d_… │\n",
"│ (\u001B[38;5;33mConcatenate\u001B[0m) │ │ │ global_average_poolin… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_67 (\u001B[38;5;33mDense\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m65,664\u001B[0m │ concatenate_5[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_32 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m512\u001B[0m │ dense_67[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"│ (\u001B[38;5;33mBatchNormalization\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_32 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ batch_normalization_3… │\n",
"│ (\u001B[38;5;33mActivation\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_78 (\u001B[38;5;33mDropout\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ activation_32[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_68 (\u001B[38;5;33mDense\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m65,664\u001B[0m │ concatenate_5[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_57 (\u001B[38;5;33mAdd\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ dropout_78[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m], │\n",
"│ │ │ │ dense_68[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_69 (\u001B[38;5;33mDense\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m16,512\u001B[0m │ add_57[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_71 (\u001B[38;5;33mDense\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m64\u001B[0m) │ \u001B[38;5;34m8,256\u001B[0m │ add_57[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_73 (\u001B[38;5;33mDense\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m64\u001B[0m) │ \u001B[38;5;34m8,256\u001B[0m │ add_57[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_33 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m512\u001B[0m │ dense_69[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"│ (\u001B[38;5;33mBatchNormalization\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_35 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m64\u001B[0m) │ \u001B[38;5;34m256\u001B[0m │ dense_71[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"│ (\u001B[38;5;33mBatchNormalization\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_37 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m64\u001B[0m) │ \u001B[38;5;34m256\u001B[0m │ dense_73[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"│ (\u001B[38;5;33mBatchNormalization\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_33 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ batch_normalization_3… │\n",
"│ (\u001B[38;5;33mActivation\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_35 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m64\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ batch_normalization_3… │\n",
"│ (\u001B[38;5;33mActivation\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_37 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m64\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ batch_normalization_3… │\n",
"│ (\u001B[38;5;33mActivation\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_79 (\u001B[38;5;33mDropout\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ activation_33[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_81 (\u001B[38;5;33mDropout\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m64\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ activation_35[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_83 (\u001B[38;5;33mDropout\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m64\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ activation_37[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_70 (\u001B[38;5;33mDense\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m64\u001B[0m) │ \u001B[38;5;34m8,256\u001B[0m │ dropout_79[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_72 (\u001B[38;5;33mDense\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m32\u001B[0m) │ \u001B[38;5;34m2,080\u001B[0m │ dropout_81[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_74 (\u001B[38;5;33mDense\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m32\u001B[0m) │ \u001B[38;5;34m2,080\u001B[0m │ dropout_83[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_34 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m64\u001B[0m) │ \u001B[38;5;34m256\u001B[0m │ dense_70[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"│ (\u001B[38;5;33mBatchNormalization\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_36 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m32\u001B[0m) │ \u001B[38;5;34m128\u001B[0m │ dense_72[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"│ (\u001B[38;5;33mBatchNormalization\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_38 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m32\u001B[0m) │ \u001B[38;5;34m128\u001B[0m │ dense_74[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"│ (\u001B[38;5;33mBatchNormalization\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_34 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m64\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ batch_normalization_3… │\n",
"│ (\u001B[38;5;33mActivation\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_36 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m32\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ batch_normalization_3… │\n",
"│ (\u001B[38;5;33mActivation\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_38 │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m32\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ batch_normalization_3… │\n",
"│ (\u001B[38;5;33mActivation\u001B[0m) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_80 (\u001B[38;5;33mDropout\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m64\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ activation_34[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_82 (\u001B[38;5;33mDropout\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m32\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ activation_36[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_84 (\u001B[38;5;33mDropout\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m32\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ activation_38[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ target_0 (\u001B[38;5;33mDense\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m1\u001B[0m) │ \u001B[38;5;34m65\u001B[0m │ dropout_80[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ target_1 (\u001B[38;5;33mDense\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m1\u001B[0m) │ \u001B[38;5;34m33\u001B[0m │ dropout_82[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ target_2 (\u001B[38;5;33mDense\u001B[0m) │ (\u001B[38;5;34m1\u001B[0m, \u001B[38;5;34m1\u001B[0m) │ \u001B[38;5;34m33\u001B[0m │ dropout_84[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n",
"└───────────────────────────┴────────────────────────┴────────────────┴────────────────────────┘\n"
],
"text/html": [
"┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓\n",
"┃ Layer (type) ┃ Output Shape ┃ Param # ┃ Connected to ┃\n",
"┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩\n",
"│ input_layer_7 │ (None, 24, 31) │ 0 │ - │\n",
"│ (InputLayer) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_61 (Dense) │ (None, 24, 128) │ 4,096 │ input_layer_7[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ zero_padding1d_6 │ (None, 26, 128) │ 0 │ dense_61[0][0] │\n",
"│ (ZeroPadding1D) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv1d_6 (Conv1D) │ (None, 24, 128) │ 49,280 │ zero_padding1d_6[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_29 │ (None, 24, 128) │ 512 │ conv1d_6[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_29 │ (None, 24, 128) │ 0 │ batch_normalization_2… │\n",
"│ (Activation) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_69 (Dropout) │ (None, 24, 128) │ 0 │ activation_29[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_47 (Add) │ (None, 24, 128) │ 0 │ dense_61[0][0], │\n",
"│ │ │ │ dropout_69[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ zero_padding1d_7 │ (None, 28, 128) │ 0 │ add_47[0][0] │\n",
"│ (ZeroPadding1D) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv1d_7 (Conv1D) │ (None, 24, 128) │ 49,280 │ zero_padding1d_7[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_30 │ (None, 24, 128) │ 512 │ conv1d_7[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_30 │ (None, 24, 128) │ 0 │ batch_normalization_3… │\n",
"│ (Activation) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ bidirectional_20 │ (None, 24, 256) │ 163,840 │ input_layer_7[0][0] │\n",
"│ (Bidirectional) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_70 (Dropout) │ (None, 24, 128) │ 0 │ activation_30[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ layer_normalization_38 │ (None, 24, 256) │ 512 │ bidirectional_20[0][0] │\n",
"│ (LayerNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_48 (Add) │ (None, 24, 128) │ 0 │ add_47[0][0], │\n",
"│ │ │ │ dropout_70[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_67 (Dropout) │ (None, 24, 256) │ 0 │ layer_normalization_3… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_59 (Dense) │ (None, 24, 256) │ 8,192 │ input_layer_7[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ zero_padding1d_8 │ (None, 32, 128) │ 0 │ add_48[0][0] │\n",
"│ (ZeroPadding1D) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_45 (Add) │ (None, 24, 256) │ 0 │ dropout_67[0][0], │\n",
"│ │ │ │ dense_59[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ conv1d_8 (Conv1D) │ (None, 24, 128) │ 49,280 │ zero_padding1d_8[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ bidirectional_21 │ (None, 24, 128) │ 164,352 │ add_45[0][0] │\n",
"│ (Bidirectional) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_31 │ (None, 24, 128) │ 512 │ conv1d_8[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ layer_normalization_39 │ (None, 24, 128) │ 256 │ bidirectional_21[0][0] │\n",
"│ (LayerNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_31 │ (None, 24, 128) │ 0 │ batch_normalization_3… │\n",
"│ (Activation) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_68 (Dropout) │ (None, 24, 128) │ 0 │ layer_normalization_3… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_60 (Dense) │ (None, 24, 128) │ 32,896 │ add_45[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_71 (Dropout) │ (None, 24, 128) │ 0 │ activation_31[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_46 (Add) │ (None, 24, 128) │ 0 │ dropout_68[0][0], │\n",
"│ │ │ │ dense_60[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_49 (Add) │ (None, 24, 128) │ 0 │ add_48[0][0], │\n",
"│ │ │ │ dropout_71[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ concatenate_4 │ (None, 24, 256) │ 0 │ add_46[0][0], │\n",
"│ (Concatenate) │ │ │ add_49[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_50 (Add) │ (1, 24, 256) │ 0 │ concatenate_4[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ multi_head_attention_14 │ (1, 24, 256) │ 263,168 │ add_50[0][0], │\n",
"│ (MultiHeadAttention) │ │ │ add_50[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_51 (Add) │ (1, 24, 256) │ 0 │ add_50[0][0], │\n",
"│ │ │ │ multi_head_attention_… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ layer_normalization_40 │ (1, 24, 256) │ 512 │ add_51[0][0] │\n",
"│ (LayerNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_63 (Dense) │ (1, 24, 256) │ 65,792 │ layer_normalization_4… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_73 (Dropout) │ (1, 24, 256) │ 0 │ dense_63[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_64 (Dense) │ (1, 24, 256) │ 65,792 │ dropout_73[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_52 (Add) │ (1, 24, 256) │ 0 │ layer_normalization_4… │\n",
"│ │ │ │ dense_64[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ layer_normalization_41 │ (1, 24, 256) │ 512 │ add_52[0][0] │\n",
"│ (LayerNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ multi_head_attention_15 │ (1, 24, 256) │ 131,712 │ layer_normalization_4… │\n",
"│ (MultiHeadAttention) │ │ │ layer_normalization_4… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_53 (Add) │ (1, 24, 256) │ 0 │ layer_normalization_4… │\n",
"│ │ │ │ multi_head_attention_… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ layer_normalization_42 │ (1, 24, 256) │ 512 │ add_53[0][0] │\n",
"│ (LayerNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_65 (Dense) │ (1, 24, 128) │ 32,896 │ layer_normalization_4… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_75 (Dropout) │ (1, 24, 128) │ 0 │ dense_65[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_66 (Dense) │ (1, 24, 256) │ 33,024 │ dropout_75[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_54 (Add) │ (1, 24, 256) │ 0 │ layer_normalization_4… │\n",
"│ │ │ │ dense_66[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ layer_normalization_43 │ (1, 24, 256) │ 512 │ add_54[0][0] │\n",
"│ (LayerNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ multi_head_attention_16 │ (1, 24, 256) │ 2,103,552 │ layer_normalization_4… │\n",
"│ (MultiHeadAttention) │ │ │ layer_normalization_4… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_55 (Add) │ (1, 24, 256) │ 0 │ layer_normalization_4… │\n",
"│ │ │ │ multi_head_attention_… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ layer_normalization_44 │ (1, 24, 256) │ 512 │ add_55[0][0] │\n",
"│ (LayerNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ multi_head_attention_17 │ (1, 24, 256) │ 1,051,904 │ layer_normalization_4… │\n",
"│ (MultiHeadAttention) │ │ │ layer_normalization_4… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_56 (Add) │ (1, 24, 256) │ 0 │ layer_normalization_4… │\n",
"│ │ │ │ multi_head_attention_… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ layer_normalization_45 │ (1, 24, 256) │ 512 │ add_56[0][0] │\n",
"│ (LayerNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ global_max_pooling1d_2 │ (1, 256) │ 0 │ layer_normalization_4… │\n",
"│ (GlobalMaxPooling1D) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ global_average_pooling1d… │ (1, 256) │ 0 │ layer_normalization_4… │\n",
"│ (GlobalAveragePooling1D) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ concatenate_5 │ (1, 512) │ 0 │ global_max_pooling1d_… │\n",
"│ (Concatenate) │ │ │ global_average_poolin… │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_67 (Dense) │ (1, 128) │ 65,664 │ concatenate_5[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_32 │ (1, 128) │ 512 │ dense_67[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_32 │ (1, 128) │ 0 │ batch_normalization_3… │\n",
"│ (Activation) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_78 (Dropout) │ (1, 128) │ 0 │ activation_32[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_68 (Dense) │ (1, 128) │ 65,664 │ concatenate_5[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ add_57 (Add) │ (1, 128) │ 0 │ dropout_78[0][0], │\n",
"│ │ │ │ dense_68[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_69 (Dense) │ (1, 128) │ 16,512 │ add_57[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_71 (Dense) │ (1, 64) │ 8,256 │ add_57[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_73 (Dense) │ (1, 64) │ 8,256 │ add_57[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_33 │ (1, 128) │ 512 │ dense_69[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_35 │ (1, 64) │ 256 │ dense_71[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_37 │ (1, 64) │ 256 │ dense_73[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_33 │ (1, 128) │ 0 │ batch_normalization_3… │\n",
"│ (Activation) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_35 │ (1, 64) │ 0 │ batch_normalization_3… │\n",
"│ (Activation) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_37 │ (1, 64) │ 0 │ batch_normalization_3… │\n",
"│ (Activation) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_79 (Dropout) │ (1, 128) │ 0 │ activation_33[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_81 (Dropout) │ (1, 64) │ 0 │ activation_35[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_83 (Dropout) │ (1, 64) │ 0 │ activation_37[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_70 (Dense) │ (1, 64) │ 8,256 │ dropout_79[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_72 (Dense) │ (1, 32) │ 2,080 │ dropout_81[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dense_74 (Dense) │ (1, 32) │ 2,080 │ dropout_83[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_34 │ (1, 64) │ 256 │ dense_70[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_36 │ (1, 32) │ 128 │ dense_72[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ batch_normalization_38 │ (1, 32) │ 128 │ dense_74[0][0] │\n",
"│ (BatchNormalization) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_34 │ (1, 64) │ 0 │ batch_normalization_3… │\n",
"│ (Activation) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_36 │ (1, 32) │ 0 │ batch_normalization_3… │\n",
"│ (Activation) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ activation_38 │ (1, 32) │ 0 │ batch_normalization_3… │\n",
"│ (Activation) │ │ │ │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_80 (Dropout) │ (1, 64) │ 0 │ activation_34[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_82 (Dropout) │ (1, 32) │ 0 │ activation_36[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ dropout_84 (Dropout) │ (1, 32) │ 0 │ activation_38[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ target_0 (Dense) │ (1, 1) │ 65 │ dropout_80[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ target_1 (Dense) │ (1, 1) │ 33 │ dropout_82[0][0] │\n",
"├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤\n",
"│ target_2 (Dense) │ (1, 1) │ 33 │ dropout_84[0][0] │\n",
"└───────────────────────────┴────────────────────────┴────────────────┴────────────────────────┘\n",
"\n"
]
},
"metadata": {}
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"\u001B[1m Total params: \u001B[0m\u001B[38;5;34m4,453,379\u001B[0m (16.99 MB)\n"
],
"text/html": [
"Total params: 4,453,379 (16.99 MB)\n", "\n" ] }, "metadata": {} }, { "output_type": "display_data", "data": { "text/plain": [ "\u001B[1m Trainable params: \u001B[0m\u001B[38;5;34m4,451,587\u001B[0m (16.98 MB)\n" ], "text/html": [ "
Trainable params: 4,451,587 (16.98 MB)\n", "\n" ] }, "metadata": {} }, { "output_type": "display_data", "data": { "text/plain": [ "\u001B[1m Non-trainable params: \u001B[0m\u001B[38;5;34m1,792\u001B[0m (7.00 KB)\n" ], "text/html": [ "
Non-trainable params: 1,792 (7.00 KB)\n", "\n" ] }, "metadata": {} }, { "output_type": "stream", "name": "stdout", "text": [ "Epoch 1/100\n", "\u001B[1m325/325\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m54s\u001B[0m 82ms/step - loss: 2.1962 - target_0_mae: 0.6480 - target_0_mse: 0.6923 - target_1_mae: 0.4789 - target_1_mse: 0.4465 - target_2_mae: 0.4036 - target_2_mse: 0.3105 - val_loss: 1.0617 - val_target_0_mae: 0.0896 - val_target_0_mse: 0.0156 - val_target_1_mae: 0.1105 - val_target_1_mse: 0.0196 - val_target_2_mae: 0.1146 - val_target_2_mse: 0.0224\n", "Epoch 2/100\n", "\u001B[1m325/325\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m25s\u001B[0m 77ms/step - loss: 0.9524 - target_0_mae: 0.2070 - target_0_mse: 0.0713 - target_1_mae: 0.1703 - target_1_mse: 0.0496 - target_2_mae: 0.1501 - target_2_mse: 0.0389 - val_loss: 0.5013 - val_target_0_mae: 0.0791 - val_target_0_mse: 0.0110 - val_target_1_mae: 0.0771 - val_target_1_mse: 0.0100 - val_target_2_mae: 0.0696 - val_target_2_mse: 0.0102\n", "Epoch 3/100\n", "\u001B[1m325/325\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m25s\u001B[0m 78ms/step - loss: 0.4457 - target_0_mae: 0.1223 - target_0_mse: 0.0261 - target_1_mae: 0.1026 - target_1_mse: 0.0190 - target_2_mae: 0.0939 - target_2_mse: 0.0159 - val_loss: 0.2845 - val_target_0_mae: 0.0883 - val_target_0_mse: 0.0160 - val_target_1_mae: 0.0915 - val_target_1_mse: 0.0166 - val_target_2_mae: 0.1009 - val_target_2_mse: 0.0217\n", "Epoch 4/100\n", "\u001B[1m186/325\u001B[0m \u001B[32m━━━━━━━━━━━\u001B[0m\u001B[37m━━━━━━━━━\u001B[0m \u001B[1m9s\u001B[0m 68ms/step - loss: 0.2635 - target_0_mae: 0.0972 - target_0_mse: 0.0176 - target_1_mae: 0.0953 - target_1_mse: 0.0174 - target_2_mae: 0.0852 - target_2_mse: 0.0144" ] } ] }, { "cell_type": "code", "source": [ "def calculate_real_error_multitarget(model, data, target_variables):\n", " \"\"\"\n", " Calcola gli errori reali per il modello multi-target\n", "\n", " Args:\n", " model: modello multi-target addestrato\n", " data: dizionario contenente i dati e gli scaler\n", " target_variables: lista dei nomi delle variabili target\n", " \"\"\"\n", "\n", " # Fare predizioni\n", " predictions = model.predict(data['X_test'])\n", "\n", " for i, target in enumerate(target_variables):\n", " print(f\"\\nAnalisi errori per {target}:\")\n", " print(\"-\" * 50)\n", "\n", " # Ottieni lo scaler per questo target\n", " scaler = data['scalers'][target]\n", "\n", " # Denormalizzare predizioni e target\n", " predictions_real = scaler.inverse_transform(predictions[i].reshape(-1, 1))\n", " targets_real = scaler.inverse_transform(data['y_test'][:, i].reshape(-1, 1))\n", "\n", " # Calcolare gli errori\n", " mae = np.mean(np.abs(predictions_real - targets_real))\n", "\n", " # Gestire il caso di valori target = 0 per evitare divisione per zero nel MAPE\n", " mask = targets_real != 0\n", " mape = np.mean(np.abs((predictions_real[mask] - targets_real[mask]) / targets_real[mask])) * 100\n", "\n", " # Calcolare R2 score\n", " r2 = r2_score(targets_real, predictions_real)\n", "\n", " # Stampare i risultati\n", " print(f\"MAE assoluto: {mae:.2f}\")\n", " print(f\"Errore percentuale medio (MAPE): {mape:.2f}%\")\n", " print(f\"Precisione: {100 - mape:.2f}%\")\n", " print(f\"R² Score: {r2:.4f}\")\n", " print(\"-\" * 50)\n", "\n", " # Visualizza un grafico delle predizioni vs realtà\n", " plt.figure(figsize=(15, 6))\n", "\n", " # Subplot 1: Time series\n", " plt.subplot(1, 2, 1)\n", " plt.plot(targets_real[:100], label='Valori reali', alpha=0.7)\n", " plt.plot(predictions_real[:100], label='Predizioni', alpha=0.7)\n", " plt.title(f'Predizioni vs Valori Reali - {target}\\n(primi 100 campioni)')\n", " plt.legend()\n", " plt.grid(True)\n", "\n", " # Subplot 2: Scatter plot\n", " plt.subplot(1, 2, 2)\n", " plt.scatter(targets_real, predictions_real, alpha=0.5)\n", " plt.plot([targets_real.min(), targets_real.max()],\n", " [targets_real.min(), targets_real.max()],\n", " 'r--', lw=2)\n", " plt.xlabel('Valori Reali')\n", " plt.ylabel('Predizioni')\n", " plt.title(f'Scatter Plot - {target}\\nR² = {r2:.4f}')\n", " plt.grid(True)\n", "\n", " plt.tight_layout()\n", " plt.show()\n", "\n", " # Calcola e visualizza la distribuzione degli errori\n", " errors = predictions_real - targets_real\n", " plt.figure(figsize=(10, 5))\n", " sns.histplot(errors, bins=50, kde=True)\n", " plt.title(f'Distribuzione degli Errori - {target}')\n", " plt.xlabel('Errore')\n", " plt.ylabel('Frequenza')\n", " plt.grid(True)\n", " plt.show()\n", "\n", "# Utilizzare la funzione\n", "calculate_real_error_multitarget(model, data, target_variables)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 1000 }, "id": "dOy10JTYwrXb", "outputId": "46a8e5d4-b327-4479-a1d2-c4e45ee62a34" }, "execution_count": 22, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "\u001B[1m810/810\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m5s\u001B[0m 7ms/step\n", "\n", "Analisi errori per solarradiation:\n", "--------------------------------------------------\n", "MAE assoluto: 42.80\n", "Errore percentuale medio (MAPE): 69.34%\n", "Precisione: 30.66%\n", "R² Score: 0.8933\n", "--------------------------------------------------\n" ] }, { "output_type": "display_data", "data": { "text/plain": [ "
Model: \"functional_21\"\n\n"
},
"metadata": {}
},
{
"output_type": "display_data",
"data": {
"text/plain": "┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┓\n┃\u001B[1m \u001B[0m\u001B[1mLayer (type) \u001B[0m\u001B[1m \u001B[0m┃\u001B[1m \u001B[0m\u001B[1mOutput Shape \u001B[0m\u001B[1m \u001B[0m┃\u001B[1m \u001B[0m\u001B[1m Param #\u001B[0m\u001B[1m \u001B[0m┃\u001B[1m \u001B[0m\u001B[1mConnected to \u001B[0m\u001B[1m \u001B[0m┃\n┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━┩\n│ temporal_input │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m41\u001B[0m, \u001B[38;5;34m3\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ - │\n│ (\u001B[38;5;33mInputLayer\u001B[0m) │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ layer_normalizatio… │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m41\u001B[0m, \u001B[38;5;34m3\u001B[0m) │ \u001B[38;5;34m6\u001B[0m │ temporal_input[\u001B[38;5;34m0\u001B[0m… │\n│ (\u001B[38;5;33mLayerNormalizatio…\u001B[0m │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ temporal_augmentat… │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m41\u001B[0m, \u001B[38;5;34m3\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ layer_normalizat… │\n│ (\u001B[38;5;33mTemporalAugmentat…\u001B[0m │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ sequential │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m41\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m8,576\u001B[0m │ temporal_augment… │\n│ (\u001B[38;5;33mSequential\u001B[0m) │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ positional_encoding │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m41\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ sequential[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n│ (\u001B[38;5;33mPositionalEncodin…\u001B[0m │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ enhanced_transform… │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m41\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m148,992\u001B[0m │ positional_encod… │\n│ (\u001B[38;5;33mEnhancedTransform…\u001B[0m │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ enhanced_transform… │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m41\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m148,992\u001B[0m │ enhanced_transfo… │\n│ (\u001B[38;5;33mEnhancedTransform…\u001B[0m │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ enhanced_transform… │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m41\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m148,992\u001B[0m │ enhanced_transfo… │\n│ (\u001B[38;5;33mEnhancedTransform…\u001B[0m │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ enhanced_transform… │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m41\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m148,992\u001B[0m │ enhanced_transfo… │\n│ (\u001B[38;5;33mEnhancedTransform…\u001B[0m │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ static_input │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m113\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ - │\n│ (\u001B[38;5;33mInputLayer\u001B[0m) │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ add_21 (\u001B[38;5;33mAdd\u001B[0m) │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m41\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ enhanced_transfo… │\n│ │ │ │ positional_encod… │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ layer_normalizatio… │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m113\u001B[0m) │ \u001B[38;5;34m226\u001B[0m │ static_input[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m…\u001B[0m │\n│ (\u001B[38;5;33mLayerNormalizatio…\u001B[0m │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ temporal_pooling_l… │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m384\u001B[0m) │ \u001B[38;5;34m131,968\u001B[0m │ add_21[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n│ (\u001B[38;5;33mTemporalPoolingLa…\u001B[0m │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ sequential_5 │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m64\u001B[0m) │ \u001B[38;5;34m70,336\u001B[0m │ layer_normalizat… │\n│ (\u001B[38;5;33mSequential\u001B[0m) │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ concatenate_1 │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m448\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ temporal_pooling… │\n│ (\u001B[38;5;33mConcatenate\u001B[0m) │ │ │ sequential_5[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m…\u001B[0m │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ batch_normalizatio… │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m448\u001B[0m) │ \u001B[38;5;34m1,792\u001B[0m │ concatenate_1[\u001B[38;5;34m0\u001B[0m]… │\n│ (\u001B[38;5;33mBatchNormalizatio…\u001B[0m │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dense_52 (\u001B[38;5;33mDense\u001B[0m) │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m114,944\u001B[0m │ batch_normalizat… │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dropout_60 │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ dense_52[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n│ (\u001B[38;5;33mDropout\u001B[0m) │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ batch_normalizatio… │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m256\u001B[0m) │ \u001B[38;5;34m1,024\u001B[0m │ dropout_60[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n│ (\u001B[38;5;33mBatchNormalizatio…\u001B[0m │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dense_53 (\u001B[38;5;33mDense\u001B[0m) │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m32,896\u001B[0m │ batch_normalizat… │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dropout_61 │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ dense_53[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n│ (\u001B[38;5;33mDropout\u001B[0m) │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ batch_normalizatio… │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m128\u001B[0m) │ \u001B[38;5;34m512\u001B[0m │ dropout_61[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n│ (\u001B[38;5;33mBatchNormalizatio…\u001B[0m │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dense_54 (\u001B[38;5;33mDense\u001B[0m) │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m64\u001B[0m) │ \u001B[38;5;34m8,256\u001B[0m │ batch_normalizat… │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dropout_62 │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m64\u001B[0m) │ \u001B[38;5;34m0\u001B[0m │ dense_54[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n│ (\u001B[38;5;33mDropout\u001B[0m) │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dense_55 (\u001B[38;5;33mDense\u001B[0m) │ (\u001B[38;5;45mNone\u001B[0m, \u001B[38;5;34m5\u001B[0m) │ \u001B[38;5;34m325\u001B[0m │ dropout_62[\u001B[38;5;34m0\u001B[0m][\u001B[38;5;34m0\u001B[0m] │\n└─────────────────────┴───────────────────┴────────────┴───────────────────┘\n",
"text/html": "┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┓\n┃ Layer (type) ┃ Output Shape ┃ Param # ┃ Connected to ┃\n┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━┩\n│ temporal_input │ (None, 41, 3) │ 0 │ - │\n│ (InputLayer) │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ layer_normalizatio… │ (None, 41, 3) │ 6 │ temporal_input[0… │\n│ (LayerNormalizatio… │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ temporal_augmentat… │ (None, 41, 3) │ 0 │ layer_normalizat… │\n│ (TemporalAugmentat… │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ sequential │ (None, 41, 128) │ 8,576 │ temporal_augment… │\n│ (Sequential) │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ positional_encoding │ (None, 41, 128) │ 0 │ sequential[0][0] │\n│ (PositionalEncodin… │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ enhanced_transform… │ (None, 41, 128) │ 148,992 │ positional_encod… │\n│ (EnhancedTransform… │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ enhanced_transform… │ (None, 41, 128) │ 148,992 │ enhanced_transfo… │\n│ (EnhancedTransform… │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ enhanced_transform… │ (None, 41, 128) │ 148,992 │ enhanced_transfo… │\n│ (EnhancedTransform… │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ enhanced_transform… │ (None, 41, 128) │ 148,992 │ enhanced_transfo… │\n│ (EnhancedTransform… │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ static_input │ (None, 113) │ 0 │ - │\n│ (InputLayer) │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ add_21 (Add) │ (None, 41, 128) │ 0 │ enhanced_transfo… │\n│ │ │ │ positional_encod… │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ layer_normalizatio… │ (None, 113) │ 226 │ static_input[0][… │\n│ (LayerNormalizatio… │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ temporal_pooling_l… │ (None, 384) │ 131,968 │ add_21[0][0] │\n│ (TemporalPoolingLa… │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ sequential_5 │ (None, 64) │ 70,336 │ layer_normalizat… │\n│ (Sequential) │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ concatenate_1 │ (None, 448) │ 0 │ temporal_pooling… │\n│ (Concatenate) │ │ │ sequential_5[0][… │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ batch_normalizatio… │ (None, 448) │ 1,792 │ concatenate_1[0]… │\n│ (BatchNormalizatio… │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dense_52 (Dense) │ (None, 256) │ 114,944 │ batch_normalizat… │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dropout_60 │ (None, 256) │ 0 │ dense_52[0][0] │\n│ (Dropout) │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ batch_normalizatio… │ (None, 256) │ 1,024 │ dropout_60[0][0] │\n│ (BatchNormalizatio… │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dense_53 (Dense) │ (None, 128) │ 32,896 │ batch_normalizat… │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dropout_61 │ (None, 128) │ 0 │ dense_53[0][0] │\n│ (Dropout) │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ batch_normalizatio… │ (None, 128) │ 512 │ dropout_61[0][0] │\n│ (BatchNormalizatio… │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dense_54 (Dense) │ (None, 64) │ 8,256 │ batch_normalizat… │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dropout_62 │ (None, 64) │ 0 │ dense_54[0][0] │\n│ (Dropout) │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dense_55 (Dense) │ (None, 5) │ 325 │ dropout_62[0][0] │\n└─────────────────────┴───────────────────┴────────────┴───────────────────┘\n\n" }, "metadata": {} }, { "output_type": "display_data", "data": { "text/plain": "\u001B[1m Total params: \u001B[0m\u001B[38;5;34m966,829\u001B[0m (3.69 MB)\n", "text/html": "
Total params: 966,829 (3.69 MB)\n\n" }, "metadata": {} }, { "output_type": "display_data", "data": { "text/plain": "\u001B[1m Trainable params: \u001B[0m\u001B[38;5;34m965,165\u001B[0m (3.68 MB)\n", "text/html": "
Trainable params: 965,165 (3.68 MB)\n\n" }, "metadata": {} }, { "output_type": "display_data", "data": { "text/plain": "\u001B[1m Non-trainable params: \u001B[0m\u001B[38;5;34m1,664\u001B[0m (6.50 KB)\n", "text/html": "
Non-trainable params: 1,664 (6.50 KB)\n\n" }, "metadata": {} } ] }, { "cell_type": "markdown", "source": [ "## Model Training" ], "metadata": { "id": "aytSjU1UthBB" } }, { "cell_type": "code", "source": [ "# Esegui il training\n", "history = model.fit(\n", " x=train_data,\n", " y=train_targets,\n", " validation_data=(val_data, val_targets),\n", " epochs=150,\n", " batch_size=64,\n", " callbacks=callbacks,\n", " verbose=1,\n", " shuffle=True\n", ")" ], "metadata": { "ExecuteTime": { "end_time": "2024-10-24T09:33:43.625381Z", "start_time": "2024-10-24T09:33:34.088970Z" }, "execution": { "iopub.status.busy": "2024-10-29T05:48:10.768511Z", "iopub.execute_input": "2024-10-29T05:48:10.768892Z", "iopub.status.idle": "2024-10-29T06:58:21.708828Z", "shell.execute_reply.started": "2024-10-29T05:48:10.768857Z", "shell.execute_reply": "2024-10-29T06:58:21.707766Z" }, "trusted": true, "id": "xE3iTWonthBB", "outputId": "a784254e-deea-4fd3-8578-6a0dbbd45bd7" }, "execution_count": null, "outputs": [ { "name": "stdout", "text": "Epoch 1/150\n", "output_type": "stream" }, { "name": "stderr", "text": "WARNING: All log messages before absl::InitializeLog() is called are written to STDERR\nI0000 00:00:1730180910.444957 107 service.cc:145] XLA service 0x7e5089fc0b10 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:\nI0000 00:00:1730180910.445031 107 service.cc:153] StreamExecutor device (0): Tesla P100-PCIE-16GB, Compute Capability 6.0\nI0000 00:00:1730180949.773589 107 device_compiler.h:188] Compiled cluster using XLA! This line is logged at most once for the lifetime of the process.\n", "output_type": "stream" }, { "name": "stdout", "text": "\u001B[1m6000/6000\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m16s\u001B[0m 2ms/step\n\u001B[1m9750/9750\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m238s\u001B[0m 18ms/step - loss: 0.1411 - mae: 0.3464 - val_loss: 0.0220 - val_mae: 0.1212 - val_olive_prod_mae: 0.1281 - val_min_oil_prod_mae: 0.1257 - val_max_oil_prod_mae: 0.1235 - val_avg_oil_prod_mae: 0.1212 - val_total_water_need_mae: 0.1074\nEpoch 2/150\n\u001B[1m6000/6000\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m15s\u001B[0m 2ms/step\n\u001B[1m9750/9750\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m181s\u001B[0m 19ms/step - loss: 0.0345 - mae: 0.1696 - val_loss: 0.0212 - val_mae: 0.1170 - val_olive_prod_mae: 0.1247 - val_min_oil_prod_mae: 0.1212 - val_max_oil_prod_mae: 0.1202 - val_avg_oil_prod_mae: 0.1172 - val_total_water_need_mae: 0.1017\nEpoch 3/150\n\u001B[1m6000/6000\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m14s\u001B[0m 2ms/step\n\u001B[1m9750/9750\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m176s\u001B[0m 18ms/step - loss: 0.0343 - mae: 0.1692 - val_loss: 0.0214 - val_mae: 0.1183 - val_olive_prod_mae: 0.1270 - val_min_oil_prod_mae: 0.1223 - val_max_oil_prod_mae: 0.1217 - val_avg_oil_prod_mae: 0.1186 - val_total_water_need_mae: 0.1022\nEpoch 4/150\n\u001B[1m6000/6000\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m14s\u001B[0m 2ms/step\n\u001B[1m9750/9750\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m172s\u001B[0m 18ms/step - loss: 0.0341 - mae: 0.1690 - val_loss: 0.0207 - val_mae: 0.1149 - val_olive_prod_mae: 0.1238 - val_min_oil_prod_mae: 0.1188 - val_max_oil_prod_mae: 0.1177 - val_avg_oil_prod_mae: 0.1145 - val_total_water_need_mae: 0.0998\nEpoch 5/150\n\u001B[1m6000/6000\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m14s\u001B[0m 2ms/step\n\u001B[1m9750/9750\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m170s\u001B[0m 17ms/step - loss: 0.0343 - mae: 0.1692 - val_loss: 0.0207 - val_mae: 0.1149 - val_olive_prod_mae: 0.1224 - val_min_oil_prod_mae: 0.1188 - val_max_oil_prod_mae: 0.1175 - val_avg_oil_prod_mae: 0.1144 - val_total_water_need_mae: 0.1015\nEpoch 6/150\n\u001B[1m6000/6000\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m14s\u001B[0m 2ms/step\n\u001B[1m9750/9750\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m169s\u001B[0m 17ms/step - loss: 0.0342 - mae: 0.1690 - val_loss: 0.0212 - val_mae: 0.1169 - val_olive_prod_mae: 0.1244 - val_min_oil_prod_mae: 0.1213 - val_max_oil_prod_mae: 0.1202 - val_avg_oil_prod_mae: 0.1172 - val_total_water_need_mae: 0.1012\nEpoch 7/150\n\u001B[1m6000/6000\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m14s\u001B[0m 2ms/step\n\u001B[1m9750/9750\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m172s\u001B[0m 18ms/step - loss: 0.0341 - mae: 0.1688 - val_loss: 0.0214 - val_mae: 0.1188 - val_olive_prod_mae: 0.1265 - val_min_oil_prod_mae: 0.1229 - val_max_oil_prod_mae: 0.1218 - val_avg_oil_prod_mae: 0.1188 - val_total_water_need_mae: 0.1037\nEpoch 8/150\n\u001B[1m6000/6000\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m15s\u001B[0m 2ms/step\n\u001B[1m9750/9750\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m170s\u001B[0m 17ms/step - loss: 0.0343 - mae: 0.1690 - val_loss: 0.0209 - val_mae: 0.1153 - val_olive_prod_mae: 0.1224 - val_min_oil_prod_mae: 0.1195 - val_max_oil_prod_mae: 0.1182 - val_avg_oil_prod_mae: 0.1151 - val_total_water_need_mae: 0.1013\nEpoch 9/150\n\u001B[1m6000/6000\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m14s\u001B[0m 2ms/step\n\u001B[1m9750/9750\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m171s\u001B[0m 18ms/step - loss: 0.0341 - mae: 0.1685 - val_loss: 0.0209 - val_mae: 0.1157 - val_olive_prod_mae: 0.1235 - val_min_oil_prod_mae: 0.1199 - val_max_oil_prod_mae: 0.1188 - val_avg_oil_prod_mae: 0.1157 - val_total_water_need_mae: 0.1008\nEpoch 10/150\n\u001B[1m6000/6000\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m15s\u001B[0m 2ms/step\n\u001B[1m9750/9750\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m173s\u001B[0m 18ms/step - loss: 0.0343 - mae: 0.1693 - val_loss: 0.0213 - val_mae: 0.1175 - val_olive_prod_mae: 0.1240 - val_min_oil_prod_mae: 0.1213 - val_max_oil_prod_mae: 0.1201 - val_avg_oil_prod_mae: 0.1172 - val_total_water_need_mae: 0.1051\nEpoch 11/150\n\u001B[1m6000/6000\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m13s\u001B[0m 2ms/step\n\u001B[1m9750/9750\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m174s\u001B[0m 18ms/step - loss: 0.0341 - mae: 0.1687 - val_loss: 0.0209 - val_mae: 0.1156 - val_olive_prod_mae: 0.1229 - val_min_oil_prod_mae: 0.1195 - val_max_oil_prod_mae: 0.1184 - val_avg_oil_prod_mae: 0.1154 - val_total_water_need_mae: 0.1016\nEpoch 12/150\n\u001B[1m6000/6000\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m13s\u001B[0m 2ms/step\n\u001B[1m9750/9750\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m170s\u001B[0m 17ms/step - loss: 0.0342 - mae: 0.1688 - val_loss: 0.0213 - val_mae: 0.1174 - val_olive_prod_mae: 0.1262 - val_min_oil_prod_mae: 0.1217 - val_max_oil_prod_mae: 0.1208 - val_avg_oil_prod_mae: 0.1177 - val_total_water_need_mae: 0.1005\nEpoch 13/150\n\u001B[1m6000/6000\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m13s\u001B[0m 2ms/step\n\u001B[1m9750/9750\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m171s\u001B[0m 18ms/step - loss: 0.0343 - mae: 0.1693 - val_loss: 0.0212 - val_mae: 0.1168 - val_olive_prod_mae: 0.1248 - val_min_oil_prod_mae: 0.1209 - val_max_oil_prod_mae: 0.1203 - val_avg_oil_prod_mae: 0.1171 - val_total_water_need_mae: 0.1008\nEpoch 14/150\n\u001B[1m6000/6000\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m14s\u001B[0m 2ms/step\n\u001B[1m9750/9750\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m169s\u001B[0m 17ms/step - loss: 0.0341 - mae: 0.1687 - val_loss: 0.0216 - val_mae: 0.1192 - val_olive_prod_mae: 0.1264 - val_min_oil_prod_mae: 0.1233 - val_max_oil_prod_mae: 0.1223 - val_avg_oil_prod_mae: 0.1194 - val_total_water_need_mae: 0.1048\nEpoch 15/150\n\u001B[1m6000/6000\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m15s\u001B[0m 2ms/step\n\u001B[1m9750/9750\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m171s\u001B[0m 18ms/step - loss: 0.0343 - mae: 0.1693 - val_loss: 0.0209 - val_mae: 0.1153 - val_olive_prod_mae: 0.1233 - val_min_oil_prod_mae: 0.1194 - val_max_oil_prod_mae: 0.1183 - val_avg_oil_prod_mae: 0.1152 - val_total_water_need_mae: 0.1001\nEpoch 16/150\n\u001B[1m6000/6000\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m14s\u001B[0m 2ms/step\n\u001B[1m9750/9750\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m175s\u001B[0m 18ms/step - loss: 0.0342 - mae: 0.1691 - val_loss: 0.0211 - val_mae: 0.1166 - val_olive_prod_mae: 0.1254 - val_min_oil_prod_mae: 0.1214 - val_max_oil_prod_mae: 0.1206 - val_avg_oil_prod_mae: 0.1176 - val_total_water_need_mae: 0.0980\nEpoch 17/150\n\u001B[1m6000/6000\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m15s\u001B[0m 2ms/step\n\u001B[1m9750/9750\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m177s\u001B[0m 18ms/step - loss: 0.0340 - mae: 0.1687 - val_loss: 0.0211 - val_mae: 0.1163 - val_olive_prod_mae: 0.1245 - val_min_oil_prod_mae: 0.1207 - val_max_oil_prod_mae: 0.1199 - val_avg_oil_prod_mae: 0.1167 - val_total_water_need_mae: 0.0995\nEpoch 18/150\n\u001B[1m6000/6000\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m14s\u001B[0m 2ms/step\n\u001B[1m9750/9750\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m175s\u001B[0m 18ms/step - loss: 0.0342 - mae: 0.1689 - val_loss: 0.0211 - val_mae: 0.1168 - val_olive_prod_mae: 0.1245 - val_min_oil_prod_mae: 0.1208 - val_max_oil_prod_mae: 0.1197 - val_avg_oil_prod_mae: 0.1167 - val_total_water_need_mae: 0.1023\nEpoch 19/150\n\u001B[1m6000/6000\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m15s\u001B[0m 2ms/step\n\u001B[1m9750/9750\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m174s\u001B[0m 18ms/step - loss: 0.0342 - mae: 0.1689 - val_loss: 0.0208 - val_mae: 0.1152 - val_olive_prod_mae: 0.1221 - val_min_oil_prod_mae: 0.1192 - val_max_oil_prod_mae: 0.1179 - val_avg_oil_prod_mae: 0.1149 - val_total_water_need_mae: 0.1021\nEpoch 20/150\n\u001B[1m6000/6000\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m14s\u001B[0m 2ms/step\n\u001B[1m9750/9750\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m176s\u001B[0m 18ms/step - loss: 0.0344 - mae: 0.1693 - val_loss: 0.0212 - val_mae: 0.1168 - val_olive_prod_mae: 0.1246 - val_min_oil_prod_mae: 0.1211 - val_max_oil_prod_mae: 0.1201 - val_avg_oil_prod_mae: 0.1169 - val_total_water_need_mae: 0.1013\nEpoch 21/150\n\u001B[1m6000/6000\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m14s\u001B[0m 2ms/step\n\u001B[1m9750/9750\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m174s\u001B[0m 18ms/step - loss: 0.0344 - mae: 0.1693 - val_loss: 0.0210 - val_mae: 0.1161 - val_olive_prod_mae: 0.1239 - val_min_oil_prod_mae: 0.1202 - val_max_oil_prod_mae: 0.1190 - val_avg_oil_prod_mae: 0.1159 - val_total_water_need_mae: 0.1014\nEpoch 22/150\n\u001B[1m6000/6000\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m14s\u001B[0m 2ms/step\n\u001B[1m9750/9750\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m175s\u001B[0m 18ms/step - loss: 0.0344 - mae: 0.1696 - val_loss: 0.0219 - val_mae: 0.1201 - val_olive_prod_mae: 0.1271 - val_min_oil_prod_mae: 0.1241 - val_max_oil_prod_mae: 0.1233 - val_avg_oil_prod_mae: 0.1203 - val_total_water_need_mae: 0.1055\nEpoch 23/150\n\u001B[1m6000/6000\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m14s\u001B[0m 2ms/step\n\u001B[1m9750/9750\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m167s\u001B[0m 17ms/step - loss: 0.0343 - mae: 0.1693 - val_loss: 0.0211 - val_mae: 0.1169 - val_olive_prod_mae: 0.1256 - val_min_oil_prod_mae: 0.1214 - val_max_oil_prod_mae: 0.1204 - val_avg_oil_prod_mae: 0.1174 - val_total_water_need_mae: 0.0997\nEpoch 24/150\n\u001B[1m6000/6000\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m14s\u001B[0m 2ms/step\n\u001B[1m9750/9750\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m168s\u001B[0m 17ms/step - loss: 0.0342 - mae: 0.1689 - val_loss: 0.0210 - val_mae: 0.1157 - val_olive_prod_mae: 0.1232 - val_min_oil_prod_mae: 0.1196 - val_max_oil_prod_mae: 0.1185 - val_avg_oil_prod_mae: 0.1154 - val_total_water_need_mae: 0.1018\n", "output_type": "stream" } ] }, { "cell_type": "code", "source": [ "# Per denormalizzare e calcolare l'errore reale\n", "def calculate_real_error(model, test_data, test_targets, scaler_y):\n", " # Fare predizioni\n", " predictions = model.predict(test_data)\n", "\n", " # Denormalizzare predizioni e target\n", " predictions_real = scaler_y.inverse_transform(predictions)\n", " targets_real = scaler_y.inverse_transform(test_targets)\n", "\n", " # Calcolare errore percentuale per ogni target\n", " percentage_errors = []\n", " absolute_errors = []\n", "\n", " for i in range(predictions_real.shape[1]):\n", " mae = np.mean(np.abs(predictions_real[:, i] - targets_real[:, i]))\n", " mape = np.mean(np.abs((predictions_real[:, i] - targets_real[:, i]) / targets_real[:, i])) * 100\n", " percentage_errors.append(mape)\n", " absolute_errors.append(mae)\n", "\n", " # Stampa risultati per ogni target\n", " target_names = ['olive_prod', 'min_oil_prod', 'max_oil_prod', 'avg_oil_prod', 'total_water_need']\n", "\n", " print(\"\\nErrori per target:\")\n", " print(\"-\" * 50)\n", " for i, target in enumerate(target_names):\n", " print(f\"{target}:\")\n", " print(f\"MAE assoluto: {absolute_errors[i]:.2f}\")\n", " print(f\"Errore percentuale medio: {percentage_errors[i]:.2f}%\")\n", " print(f\"Precisione: {100 - percentage_errors[i]:.2f}%\")\n", " print(\"-\" * 50)\n", "\n", " return percentage_errors, absolute_errors\n", "\n", "# Calcola gli errori reali\n", "percentage_errors, absolute_errors = calculate_real_error(model, val_data, val_targets, scaler_y)" ], "metadata": { "execution": { "iopub.status.busy": "2024-10-29T06:58:21.710575Z", "iopub.execute_input": "2024-10-29T06:58:21.711507Z", "iopub.status.idle": "2024-10-29T06:58:37.909471Z", "shell.execute_reply.started": "2024-10-29T06:58:21.711457Z", "shell.execute_reply": "2024-10-29T06:58:37.908487Z" }, "trusted": true, "id": "hPPbvFYmthBB", "outputId": "e6570501-00e1-4dde-81e2-4712652a46b3" }, "execution_count": null, "outputs": [ { "name": "stdout", "text": "\u001B[1m6000/6000\u001B[0m \u001B[32m━━━━━━━━━━━━━━━━━━━━\u001B[0m\u001B[37m\u001B[0m \u001B[1m14s\u001B[0m 2ms/step\n\nErrori per target:\n--------------------------------------------------\nolive_prod:\nMAE assoluto: 2033.71\nErrore percentuale medio: 9.31%\nPrecisione: 90.69%\n--------------------------------------------------\nmin_oil_prod:\nMAE assoluto: 405.14\nErrore percentuale medio: 9.12%\nPrecisione: 90.88%\n--------------------------------------------------\nmax_oil_prod:\nMAE assoluto: 486.69\nErrore percentuale medio: 8.97%\nPrecisione: 91.03%\n--------------------------------------------------\navg_oil_prod:\nMAE assoluto: 431.48\nErrore percentuale medio: 8.79%\nPrecisione: 91.21%\n--------------------------------------------------\ntotal_water_need:\nMAE assoluto: 2964.00\nErrore percentuale medio: 6.80%\nPrecisione: 93.20%\n--------------------------------------------------\n", "output_type": "stream" } ] }, { "cell_type": "code", "source": [ "def save_transformer_model(model, scaler_temporal, scaler_static, scaler_y, base_path='./kaggle/working/models/oil_transformer'):\n", " \"\"\"\n", " Salva il modello transformer e i suoi scaler.\n", "\n", " Parameters:\n", " -----------\n", " model : OliveOilTransformer\n", " Il modello transformer\n", " scaler_temporal : StandardScaler\n", " Scaler per i dati temporali\n", " scaler_static : StandardScaler\n", " Scaler per i dati statici\n", " scaler_y : StandardScaler\n", " Scaler per i target\n", " base_path : str\n", " Percorso base dove salvare il modello e gli scaler\n", " \"\"\"\n", " # Crea la cartella se non esiste\n", " os.makedirs(base_path, exist_ok=True)\n", "\n", " # Salva il modello\n", " model_path = os.path.join(base_path, 'olive_transformer.keras')\n", " model.save(model_path)\n", "\n", " # Salva gli scaler\n", " joblib.dump(scaler_temporal, os.path.join(base_path, 'scaler_temporal.joblib'))\n", " joblib.dump(scaler_static, os.path.join(base_path, 'scaler_static.joblib'))\n", " joblib.dump(scaler_y, os.path.join(base_path, 'scaler_y.joblib'))\n", "\n", " print(f\"Modello transformer e scaler salvati in: {base_path}\")\n", "\n", "def load_transformer_model(base_path='./kaggle/working/models/oil_transformer'):\n", " \"\"\"\n", " Carica il modello transformer e i suoi scaler.\n", "\n", " Parameters:\n", " -----------\n", " base_path : str\n", " Percorso dove sono salvati il modello e gli scaler\n", "\n", " Returns:\n", " --------\n", " tuple\n", " (model, scaler_temporal, scaler_static, scaler_y)\n", " \"\"\"\n", " # Carica il modello\n", " model_path = os.path.join(base_path, 'olive_transformer.keras')\n", " model = tf.keras.models.load_model(model_path, custom_objects={\n", " 'WarmUpLearningRateSchedule': WarmUpLearningRateSchedule\n", " })\n", "\n", " # Carica gli scaler\n", " scaler_temporal = joblib.load(os.path.join(base_path, 'scaler_temporal.joblib'))\n", " scaler_static = joblib.load(os.path.join(base_path, 'scaler_static.joblib'))\n", " scaler_y = joblib.load(os.path.join(base_path, 'scaler_y.joblib'))\n", "\n", " print(f\"Modello transformer e scaler caricati da: {base_path}\")\n", " return model, scaler_temporal, scaler_static, scaler_y\n", "\n", "# Esempio di utilizzo:\n", "\n", "# Per salvare:\n", "save_transformer_model(\n", " model=model,\n", " scaler_temporal=scaler_temporal,\n", " scaler_static=scaler_static,\n", " scaler_y=scaler_y,\n", ")\n", "\n", "# Per caricare:\n", "#model, scaler_temporal, scaler_static, scaler_y = load_transformer_model()\n" ], "metadata": { "execution": { "iopub.status.busy": "2024-10-29T06:58:37.911060Z", "iopub.execute_input": "2024-10-29T06:58:37.911464Z", "iopub.status.idle": "2024-10-29T06:58:38.201779Z", "shell.execute_reply.started": "2024-10-29T06:58:37.911417Z", "shell.execute_reply": "2024-10-29T06:58:38.200839Z" }, "trusted": true, "id": "dS1z60w1thBC", "outputId": "ccd58af4-a8bf-4503-c161-88d4ee054968" }, "execution_count": null, "outputs": [ { "name": "stdout", "text": "Modello transformer e scaler salvati in: /kaggle/working/models/oil_transformer\n", "output_type": "stream" } ] }, { "cell_type": "markdown", "source": [ "## 8. Conclusioni e Prossimi Passi\n", "\n", "In questo notebook, abbiamo:\n", "1. Caricato e analizzato i dati meteorologici\n", "2. Simulato la produzione annuale di olive basata sui dati meteo\n", "3. Esplorato le relazioni tra variabili meteorologiche e produzione di olive\n", "4. Creato e valutato un modello di machine learning per prevedere la produzione\n", "5. Utilizzato ARIMA per fare previsioni meteo\n", "6. Previsto la produzione di olive per il prossimo anno\n", "\n", "Prossimi passi:\n", "- Raccogliere dati reali sulla produzione di olive per sostituire i dati simulati\n", "- Esplorare modelli più avanzati, come le reti neurali o i modelli di ensemble\n", "- Incorporare altri fattori che potrebbero influenzare la produzione, come le pratiche agricole o l'età degli alberi\n", "- Sviluppare una dashboard interattiva basata su questo modello" ], "metadata": { "id": "4BAI1zsJthBC" } } ] }