SwathiManikya commited on
Commit
bef06a1
·
verified ·
1 Parent(s): 6bb25a7

Upload Baseline_XGBoost_Resource_Estimation.ipynb

Browse files
Baseline_XGBoost_Resource_Estimation.ipynb ADDED
@@ -0,0 +1,1527 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {
6
+ "id": "e5e0f994"
7
+ },
8
+ "source": [
9
+ "# 🚀 Baseline XGBoost for Resource Estimation of CNNs (Keras Applications)\n",
10
+ "This notebook demonstrates how to use XGBoost for predicting resource usage (like fit time) of CNN models based on dataset features."
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "markdown",
15
+ "metadata": {
16
+ "id": "275c013b"
17
+ },
18
+ "source": [
19
+ "## 1️⃣ Setup and Installation\n",
20
+ "Ensure required libraries are installed."
21
+ ]
22
+ },
23
+ {
24
+ "cell_type": "code",
25
+ "execution_count": 1,
26
+ "metadata": {
27
+ "colab": {
28
+ "base_uri": "https://localhost:8080/"
29
+ },
30
+ "id": "DPbLUZKvRtwx",
31
+ "outputId": "d65bcfd7-a615-4b74-feb6-757456f42581"
32
+ },
33
+ "outputs": [
34
+ {
35
+ "output_type": "stream",
36
+ "name": "stdout",
37
+ "text": [
38
+ "Found existing installation: scikit-learn 1.6.1\n",
39
+ "Uninstalling scikit-learn-1.6.1:\n",
40
+ " Successfully uninstalled scikit-learn-1.6.1\n",
41
+ "Collecting scikit-learn==1.5.2\n",
42
+ " Downloading scikit_learn-1.5.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (13 kB)\n",
43
+ "Requirement already satisfied: numpy>=1.19.5 in /usr/local/lib/python3.11/dist-packages (from scikit-learn==1.5.2) (2.0.2)\n",
44
+ "Requirement already satisfied: scipy>=1.6.0 in /usr/local/lib/python3.11/dist-packages (from scikit-learn==1.5.2) (1.14.1)\n",
45
+ "Requirement already satisfied: joblib>=1.2.0 in /usr/local/lib/python3.11/dist-packages (from scikit-learn==1.5.2) (1.4.2)\n",
46
+ "Requirement already satisfied: threadpoolctl>=3.1.0 in /usr/local/lib/python3.11/dist-packages (from scikit-learn==1.5.2) (3.6.0)\n",
47
+ "Downloading scikit_learn-1.5.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.3 MB)\n",
48
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m13.3/13.3 MB\u001b[0m \u001b[31m34.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
49
+ "\u001b[?25hInstalling collected packages: scikit-learn\n",
50
+ "Successfully installed scikit-learn-1.5.2\n"
51
+ ]
52
+ }
53
+ ],
54
+ "source": [
55
+ "!pip uninstall -y scikit-learn\n",
56
+ "!pip install scikit-learn==1.5.2"
57
+ ]
58
+ },
59
+ {
60
+ "cell_type": "markdown",
61
+ "metadata": {
62
+ "id": "48b0b5f0"
63
+ },
64
+ "source": [
65
+ "## 2️⃣ Import Libraries\n",
66
+ "Import all necessary Python libraries for data handling, modeling, and visualization."
67
+ ]
68
+ },
69
+ {
70
+ "cell_type": "code",
71
+ "execution_count": 2,
72
+ "metadata": {
73
+ "id": "V23vhp8o9YHM"
74
+ },
75
+ "outputs": [],
76
+ "source": [
77
+ "import pandas as pd\n",
78
+ "import numpy as np\n",
79
+ "from sklearn.model_selection import train_test_split\n",
80
+ "from sklearn.metrics import mean_squared_error\n",
81
+ "from xgboost import XGBRegressor\n",
82
+ "import joblib"
83
+ ]
84
+ },
85
+ {
86
+ "cell_type": "markdown",
87
+ "metadata": {
88
+ "id": "107733d4"
89
+ },
90
+ "source": [
91
+ "## 3️⃣ Data Loading & Preprocessing\n",
92
+ "Load the dataset and perform basic preprocessing to prepare for modeling."
93
+ ]
94
+ },
95
+ {
96
+ "cell_type": "code",
97
+ "execution_count": 3,
98
+ "metadata": {
99
+ "id": "UoYmjX7NGVVD"
100
+ },
101
+ "outputs": [],
102
+ "source": [
103
+ "def calculate_mspe_rmspe(y_true, y_pred):\n",
104
+ " mape = np.mean(np.abs((y_true - y_pred) / (y_true)), axis=0) * 100\n",
105
+ " mspe = np.mean(((y_true - y_pred) / y_true) ** 2, axis=0) * 100 # MSPE for each column\n",
106
+ " rmspe = np.sqrt(mspe) # RMSPE for each column\n",
107
+ " return mape, mspe, rmspe\n",
108
+ "\n"
109
+ ]
110
+ },
111
+ {
112
+ "cell_type": "code",
113
+ "execution_count": 7,
114
+ "metadata": {
115
+ "colab": {
116
+ "base_uri": "https://localhost:8080/"
117
+ },
118
+ "id": "CmmE7SNz-KXJ",
119
+ "outputId": "dc55b8bf-2000-4954-b231-664d715851de"
120
+ },
121
+ "outputs": [
122
+ {
123
+ "output_type": "execute_result",
124
+ "data": {
125
+ "text/plain": [
126
+ "Index(['name', 'samples', 'input_dim_w', 'input_dim_h', 'input_dim_c',\n",
127
+ " 'output_dim', 'optimizer', 'epochs', 'batch', 'learn_rate',\n",
128
+ " 'tf_version', 'cuda_version', 'batch_time', 'epoch_time', 'fit_time',\n",
129
+ " 'npz_path', 'gpu_make', 'gpu_name', 'gpu_arch', 'gpu_cc',\n",
130
+ " 'gpu_core_count', 'gpu_sm_count', 'gpu_memory_size', 'gpu_memory_type',\n",
131
+ " 'gpu_memory_bw', 'gpu_tensor_core_count', 'max_memory_util',\n",
132
+ " 'avg_memory_util', 'max_gpu_util', 'avg_gpu_util', 'max_gpu_temp',\n",
133
+ " 'avg_gpu_temp'],\n",
134
+ " dtype='object')"
135
+ ]
136
+ },
137
+ "metadata": {},
138
+ "execution_count": 7
139
+ }
140
+ ],
141
+ "source": [
142
+ "# Load data\n",
143
+ "# Assuming the data is in a CSV file with the target column 'fit_time_in_TF'\n",
144
+ "data_path = 'dataset-new.csv' # Replace with the actual path to your dataset\n",
145
+ "df = pd.read_csv(data_path)\n",
146
+ "df.columns"
147
+ ]
148
+ },
149
+ {
150
+ "cell_type": "markdown",
151
+ "metadata": {
152
+ "id": "962d5030"
153
+ },
154
+ "source": [
155
+ "## 4️⃣ Feature Engineering\n",
156
+ "Extract relevant features and clean the dataset."
157
+ ]
158
+ },
159
+ {
160
+ "cell_type": "code",
161
+ "execution_count": 8,
162
+ "metadata": {
163
+ "colab": {
164
+ "base_uri": "https://localhost:8080/"
165
+ },
166
+ "id": "OGzq5lrIHh2R",
167
+ "outputId": "9ee9eabd-7363-451a-b379-013b1aa7688d"
168
+ },
169
+ "outputs": [
170
+ {
171
+ "output_type": "stream",
172
+ "name": "stdout",
173
+ "text": [
174
+ " name unit_name\n",
175
+ "0 MobileNet_architecture_optadam_s1_ipd224x224x3... MobileNet\n",
176
+ "1 MobileNet_architecture_optadam_s1_ipd224x224x3... MobileNet\n",
177
+ "2 MobileNet_architecture_optadam_s1_ipd224x224x3... MobileNet\n",
178
+ "3 MobileNet_architecture_optadam_s1_ipd224x224x3... MobileNet\n",
179
+ "4 MobileNet_architecture_optadam_s1_ipd224x224x3... MobileNet\n"
180
+ ]
181
+ }
182
+ ],
183
+ "source": [
184
+ "# Extract substring before the first underscore\n",
185
+ "df['unit_name'] = df['name'].str.split('_').str[0]\n",
186
+ "\n",
187
+ "# Display the updated DataFrame\n",
188
+ "print(df[['name', 'unit_name']].head())"
189
+ ]
190
+ },
191
+ {
192
+ "cell_type": "code",
193
+ "execution_count": 9,
194
+ "metadata": {
195
+ "colab": {
196
+ "base_uri": "https://localhost:8080/"
197
+ },
198
+ "id": "mw1fY7vM-fCw",
199
+ "outputId": "a8903a63-83f3-4b6f-b061-4a4bb900cd1d"
200
+ },
201
+ "outputs": [
202
+ {
203
+ "output_type": "stream",
204
+ "name": "stdout",
205
+ "text": [
206
+ "\n",
207
+ "Label Mapping: {'DenseNet121': 0, 'DenseNet169': 1, 'DenseNet201': 2, 'EfficientNetB0': 3, 'EfficientNetB1': 4, 'EfficientNetB7': 5, 'InceptionV3': 6, 'MobileNet': 7, 'MobileNetV2': 8, 'NASNetLarge': 9, 'NASNetMobile': 10, 'ResNet101': 11, 'ResNet152': 12, 'ResNet50': 13, 'VGG16': 14, 'VGG19': 15, 'Xception': 16}\n"
208
+ ]
209
+ }
210
+ ],
211
+ "source": [
212
+ "df = df.dropna() # Dropping rows with missing values (you can customize this)\n",
213
+ "\n",
214
+ "from sklearn.preprocessing import LabelEncoder\n",
215
+ "label_encoder = LabelEncoder()\n",
216
+ "# Transform the categorical column\n",
217
+ "df['unit_name_encoded'] = label_encoder.fit_transform(df['unit_name'])\n",
218
+ "# Optional: Mapping of encoded labels to original categories\n",
219
+ "mapping = dict(zip(label_encoder.classes_, range(len(label_encoder.classes_))))\n",
220
+ "print(\"\\nLabel Mapping:\", mapping)\n",
221
+ "\n",
222
+ "df = df.drop(columns=['name', 'npz_path', 'unit_name'])\n",
223
+ "# Convert categorical features to numeric (if any)\n",
224
+ "df = pd.get_dummies(df, drop_first=True)\n"
225
+ ]
226
+ },
227
+ {
228
+ "cell_type": "code",
229
+ "execution_count": 10,
230
+ "metadata": {
231
+ "colab": {
232
+ "base_uri": "https://localhost:8080/",
233
+ "height": 290
234
+ },
235
+ "id": "04XJeqln-g4n",
236
+ "outputId": "f63e3507-6770-41be-dc9c-b03a3cb232a6"
237
+ },
238
+ "outputs": [
239
+ {
240
+ "output_type": "execute_result",
241
+ "data": {
242
+ "text/plain": [
243
+ " samples input_dim_w input_dim_h input_dim_c output_dim epochs batch \\\n",
244
+ "0 1 224 224 3 10 1 1 \n",
245
+ "1 1 224 224 3 10 1 1 \n",
246
+ "2 1 224 224 3 10 1 1 \n",
247
+ "3 1 224 224 3 10 2 1 \n",
248
+ "4 1 224 224 3 10 2 1 \n",
249
+ "\n",
250
+ " learn_rate cuda_version batch_time ... max_gpu_util avg_gpu_util \\\n",
251
+ "0 0.0100 12.2 22.07 ... 13.0 0.51 \n",
252
+ "1 0.0010 12.2 18.44 ... 100.0 2.92 \n",
253
+ "2 0.0001 12.2 18.78 ... 26.0 0.86 \n",
254
+ "3 0.0100 12.2 9.38 ... 28.0 1.78 \n",
255
+ "4 0.0010 12.2 9.30 ... 100.0 3.41 \n",
256
+ "\n",
257
+ " max_gpu_temp avg_gpu_temp unit_name_encoded optimizer_sgd \\\n",
258
+ "0 25.0 25.00 7 False \n",
259
+ "1 26.0 25.84 7 False \n",
260
+ "2 26.0 26.00 7 False \n",
261
+ "3 27.0 26.04 7 False \n",
262
+ "4 27.0 26.55 7 False \n",
263
+ "\n",
264
+ " gpu_name_Tesla P100-PCIE-16GB gpu_name_Tesla V100S-PCIE-32GB \\\n",
265
+ "0 True False \n",
266
+ "1 True False \n",
267
+ "2 True False \n",
268
+ "3 True False \n",
269
+ "4 True False \n",
270
+ "\n",
271
+ " gpu_arch_Tesla gpu_memory_type_hbm2e \n",
272
+ "0 True False \n",
273
+ "1 True False \n",
274
+ "2 True False \n",
275
+ "3 True False \n",
276
+ "4 True False \n",
277
+ "\n",
278
+ "[5 rows x 30 columns]"
279
+ ],
280
+ "text/html": [
281
+ "\n",
282
+ " <div id=\"df-c1d454f0-1110-4414-b0fa-c9f3510b4a83\" class=\"colab-df-container\">\n",
283
+ " <div>\n",
284
+ "<style scoped>\n",
285
+ " .dataframe tbody tr th:only-of-type {\n",
286
+ " vertical-align: middle;\n",
287
+ " }\n",
288
+ "\n",
289
+ " .dataframe tbody tr th {\n",
290
+ " vertical-align: top;\n",
291
+ " }\n",
292
+ "\n",
293
+ " .dataframe thead th {\n",
294
+ " text-align: right;\n",
295
+ " }\n",
296
+ "</style>\n",
297
+ "<table border=\"1\" class=\"dataframe\">\n",
298
+ " <thead>\n",
299
+ " <tr style=\"text-align: right;\">\n",
300
+ " <th></th>\n",
301
+ " <th>samples</th>\n",
302
+ " <th>input_dim_w</th>\n",
303
+ " <th>input_dim_h</th>\n",
304
+ " <th>input_dim_c</th>\n",
305
+ " <th>output_dim</th>\n",
306
+ " <th>epochs</th>\n",
307
+ " <th>batch</th>\n",
308
+ " <th>learn_rate</th>\n",
309
+ " <th>cuda_version</th>\n",
310
+ " <th>batch_time</th>\n",
311
+ " <th>...</th>\n",
312
+ " <th>max_gpu_util</th>\n",
313
+ " <th>avg_gpu_util</th>\n",
314
+ " <th>max_gpu_temp</th>\n",
315
+ " <th>avg_gpu_temp</th>\n",
316
+ " <th>unit_name_encoded</th>\n",
317
+ " <th>optimizer_sgd</th>\n",
318
+ " <th>gpu_name_Tesla P100-PCIE-16GB</th>\n",
319
+ " <th>gpu_name_Tesla V100S-PCIE-32GB</th>\n",
320
+ " <th>gpu_arch_Tesla</th>\n",
321
+ " <th>gpu_memory_type_hbm2e</th>\n",
322
+ " </tr>\n",
323
+ " </thead>\n",
324
+ " <tbody>\n",
325
+ " <tr>\n",
326
+ " <th>0</th>\n",
327
+ " <td>1</td>\n",
328
+ " <td>224</td>\n",
329
+ " <td>224</td>\n",
330
+ " <td>3</td>\n",
331
+ " <td>10</td>\n",
332
+ " <td>1</td>\n",
333
+ " <td>1</td>\n",
334
+ " <td>0.0100</td>\n",
335
+ " <td>12.2</td>\n",
336
+ " <td>22.07</td>\n",
337
+ " <td>...</td>\n",
338
+ " <td>13.0</td>\n",
339
+ " <td>0.51</td>\n",
340
+ " <td>25.0</td>\n",
341
+ " <td>25.00</td>\n",
342
+ " <td>7</td>\n",
343
+ " <td>False</td>\n",
344
+ " <td>True</td>\n",
345
+ " <td>False</td>\n",
346
+ " <td>True</td>\n",
347
+ " <td>False</td>\n",
348
+ " </tr>\n",
349
+ " <tr>\n",
350
+ " <th>1</th>\n",
351
+ " <td>1</td>\n",
352
+ " <td>224</td>\n",
353
+ " <td>224</td>\n",
354
+ " <td>3</td>\n",
355
+ " <td>10</td>\n",
356
+ " <td>1</td>\n",
357
+ " <td>1</td>\n",
358
+ " <td>0.0010</td>\n",
359
+ " <td>12.2</td>\n",
360
+ " <td>18.44</td>\n",
361
+ " <td>...</td>\n",
362
+ " <td>100.0</td>\n",
363
+ " <td>2.92</td>\n",
364
+ " <td>26.0</td>\n",
365
+ " <td>25.84</td>\n",
366
+ " <td>7</td>\n",
367
+ " <td>False</td>\n",
368
+ " <td>True</td>\n",
369
+ " <td>False</td>\n",
370
+ " <td>True</td>\n",
371
+ " <td>False</td>\n",
372
+ " </tr>\n",
373
+ " <tr>\n",
374
+ " <th>2</th>\n",
375
+ " <td>1</td>\n",
376
+ " <td>224</td>\n",
377
+ " <td>224</td>\n",
378
+ " <td>3</td>\n",
379
+ " <td>10</td>\n",
380
+ " <td>1</td>\n",
381
+ " <td>1</td>\n",
382
+ " <td>0.0001</td>\n",
383
+ " <td>12.2</td>\n",
384
+ " <td>18.78</td>\n",
385
+ " <td>...</td>\n",
386
+ " <td>26.0</td>\n",
387
+ " <td>0.86</td>\n",
388
+ " <td>26.0</td>\n",
389
+ " <td>26.00</td>\n",
390
+ " <td>7</td>\n",
391
+ " <td>False</td>\n",
392
+ " <td>True</td>\n",
393
+ " <td>False</td>\n",
394
+ " <td>True</td>\n",
395
+ " <td>False</td>\n",
396
+ " </tr>\n",
397
+ " <tr>\n",
398
+ " <th>3</th>\n",
399
+ " <td>1</td>\n",
400
+ " <td>224</td>\n",
401
+ " <td>224</td>\n",
402
+ " <td>3</td>\n",
403
+ " <td>10</td>\n",
404
+ " <td>2</td>\n",
405
+ " <td>1</td>\n",
406
+ " <td>0.0100</td>\n",
407
+ " <td>12.2</td>\n",
408
+ " <td>9.38</td>\n",
409
+ " <td>...</td>\n",
410
+ " <td>28.0</td>\n",
411
+ " <td>1.78</td>\n",
412
+ " <td>27.0</td>\n",
413
+ " <td>26.04</td>\n",
414
+ " <td>7</td>\n",
415
+ " <td>False</td>\n",
416
+ " <td>True</td>\n",
417
+ " <td>False</td>\n",
418
+ " <td>True</td>\n",
419
+ " <td>False</td>\n",
420
+ " </tr>\n",
421
+ " <tr>\n",
422
+ " <th>4</th>\n",
423
+ " <td>1</td>\n",
424
+ " <td>224</td>\n",
425
+ " <td>224</td>\n",
426
+ " <td>3</td>\n",
427
+ " <td>10</td>\n",
428
+ " <td>2</td>\n",
429
+ " <td>1</td>\n",
430
+ " <td>0.0010</td>\n",
431
+ " <td>12.2</td>\n",
432
+ " <td>9.30</td>\n",
433
+ " <td>...</td>\n",
434
+ " <td>100.0</td>\n",
435
+ " <td>3.41</td>\n",
436
+ " <td>27.0</td>\n",
437
+ " <td>26.55</td>\n",
438
+ " <td>7</td>\n",
439
+ " <td>False</td>\n",
440
+ " <td>True</td>\n",
441
+ " <td>False</td>\n",
442
+ " <td>True</td>\n",
443
+ " <td>False</td>\n",
444
+ " </tr>\n",
445
+ " </tbody>\n",
446
+ "</table>\n",
447
+ "<p>5 rows × 30 columns</p>\n",
448
+ "</div>\n",
449
+ " <div class=\"colab-df-buttons\">\n",
450
+ "\n",
451
+ " <div class=\"colab-df-container\">\n",
452
+ " <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-c1d454f0-1110-4414-b0fa-c9f3510b4a83')\"\n",
453
+ " title=\"Convert this dataframe to an interactive table.\"\n",
454
+ " style=\"display:none;\">\n",
455
+ "\n",
456
+ " <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
457
+ " <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
458
+ " </svg>\n",
459
+ " </button>\n",
460
+ "\n",
461
+ " <style>\n",
462
+ " .colab-df-container {\n",
463
+ " display:flex;\n",
464
+ " gap: 12px;\n",
465
+ " }\n",
466
+ "\n",
467
+ " .colab-df-convert {\n",
468
+ " background-color: #E8F0FE;\n",
469
+ " border: none;\n",
470
+ " border-radius: 50%;\n",
471
+ " cursor: pointer;\n",
472
+ " display: none;\n",
473
+ " fill: #1967D2;\n",
474
+ " height: 32px;\n",
475
+ " padding: 0 0 0 0;\n",
476
+ " width: 32px;\n",
477
+ " }\n",
478
+ "\n",
479
+ " .colab-df-convert:hover {\n",
480
+ " background-color: #E2EBFA;\n",
481
+ " box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
482
+ " fill: #174EA6;\n",
483
+ " }\n",
484
+ "\n",
485
+ " .colab-df-buttons div {\n",
486
+ " margin-bottom: 4px;\n",
487
+ " }\n",
488
+ "\n",
489
+ " [theme=dark] .colab-df-convert {\n",
490
+ " background-color: #3B4455;\n",
491
+ " fill: #D2E3FC;\n",
492
+ " }\n",
493
+ "\n",
494
+ " [theme=dark] .colab-df-convert:hover {\n",
495
+ " background-color: #434B5C;\n",
496
+ " box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
497
+ " filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
498
+ " fill: #FFFFFF;\n",
499
+ " }\n",
500
+ " </style>\n",
501
+ "\n",
502
+ " <script>\n",
503
+ " const buttonEl =\n",
504
+ " document.querySelector('#df-c1d454f0-1110-4414-b0fa-c9f3510b4a83 button.colab-df-convert');\n",
505
+ " buttonEl.style.display =\n",
506
+ " google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
507
+ "\n",
508
+ " async function convertToInteractive(key) {\n",
509
+ " const element = document.querySelector('#df-c1d454f0-1110-4414-b0fa-c9f3510b4a83');\n",
510
+ " const dataTable =\n",
511
+ " await google.colab.kernel.invokeFunction('convertToInteractive',\n",
512
+ " [key], {});\n",
513
+ " if (!dataTable) return;\n",
514
+ "\n",
515
+ " const docLinkHtml = 'Like what you see? Visit the ' +\n",
516
+ " '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
517
+ " + ' to learn more about interactive tables.';\n",
518
+ " element.innerHTML = '';\n",
519
+ " dataTable['output_type'] = 'display_data';\n",
520
+ " await google.colab.output.renderOutput(dataTable, element);\n",
521
+ " const docLink = document.createElement('div');\n",
522
+ " docLink.innerHTML = docLinkHtml;\n",
523
+ " element.appendChild(docLink);\n",
524
+ " }\n",
525
+ " </script>\n",
526
+ " </div>\n",
527
+ "\n",
528
+ "\n",
529
+ "<div id=\"df-7fca458e-936c-4a6a-a0af-2f6ef67c3e8e\">\n",
530
+ " <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-7fca458e-936c-4a6a-a0af-2f6ef67c3e8e')\"\n",
531
+ " title=\"Suggest charts\"\n",
532
+ " style=\"display:none;\">\n",
533
+ "\n",
534
+ "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
535
+ " width=\"24px\">\n",
536
+ " <g>\n",
537
+ " <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
538
+ " </g>\n",
539
+ "</svg>\n",
540
+ " </button>\n",
541
+ "\n",
542
+ "<style>\n",
543
+ " .colab-df-quickchart {\n",
544
+ " --bg-color: #E8F0FE;\n",
545
+ " --fill-color: #1967D2;\n",
546
+ " --hover-bg-color: #E2EBFA;\n",
547
+ " --hover-fill-color: #174EA6;\n",
548
+ " --disabled-fill-color: #AAA;\n",
549
+ " --disabled-bg-color: #DDD;\n",
550
+ " }\n",
551
+ "\n",
552
+ " [theme=dark] .colab-df-quickchart {\n",
553
+ " --bg-color: #3B4455;\n",
554
+ " --fill-color: #D2E3FC;\n",
555
+ " --hover-bg-color: #434B5C;\n",
556
+ " --hover-fill-color: #FFFFFF;\n",
557
+ " --disabled-bg-color: #3B4455;\n",
558
+ " --disabled-fill-color: #666;\n",
559
+ " }\n",
560
+ "\n",
561
+ " .colab-df-quickchart {\n",
562
+ " background-color: var(--bg-color);\n",
563
+ " border: none;\n",
564
+ " border-radius: 50%;\n",
565
+ " cursor: pointer;\n",
566
+ " display: none;\n",
567
+ " fill: var(--fill-color);\n",
568
+ " height: 32px;\n",
569
+ " padding: 0;\n",
570
+ " width: 32px;\n",
571
+ " }\n",
572
+ "\n",
573
+ " .colab-df-quickchart:hover {\n",
574
+ " background-color: var(--hover-bg-color);\n",
575
+ " box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
576
+ " fill: var(--button-hover-fill-color);\n",
577
+ " }\n",
578
+ "\n",
579
+ " .colab-df-quickchart-complete:disabled,\n",
580
+ " .colab-df-quickchart-complete:disabled:hover {\n",
581
+ " background-color: var(--disabled-bg-color);\n",
582
+ " fill: var(--disabled-fill-color);\n",
583
+ " box-shadow: none;\n",
584
+ " }\n",
585
+ "\n",
586
+ " .colab-df-spinner {\n",
587
+ " border: 2px solid var(--fill-color);\n",
588
+ " border-color: transparent;\n",
589
+ " border-bottom-color: var(--fill-color);\n",
590
+ " animation:\n",
591
+ " spin 1s steps(1) infinite;\n",
592
+ " }\n",
593
+ "\n",
594
+ " @keyframes spin {\n",
595
+ " 0% {\n",
596
+ " border-color: transparent;\n",
597
+ " border-bottom-color: var(--fill-color);\n",
598
+ " border-left-color: var(--fill-color);\n",
599
+ " }\n",
600
+ " 20% {\n",
601
+ " border-color: transparent;\n",
602
+ " border-left-color: var(--fill-color);\n",
603
+ " border-top-color: var(--fill-color);\n",
604
+ " }\n",
605
+ " 30% {\n",
606
+ " border-color: transparent;\n",
607
+ " border-left-color: var(--fill-color);\n",
608
+ " border-top-color: var(--fill-color);\n",
609
+ " border-right-color: var(--fill-color);\n",
610
+ " }\n",
611
+ " 40% {\n",
612
+ " border-color: transparent;\n",
613
+ " border-right-color: var(--fill-color);\n",
614
+ " border-top-color: var(--fill-color);\n",
615
+ " }\n",
616
+ " 60% {\n",
617
+ " border-color: transparent;\n",
618
+ " border-right-color: var(--fill-color);\n",
619
+ " }\n",
620
+ " 80% {\n",
621
+ " border-color: transparent;\n",
622
+ " border-right-color: var(--fill-color);\n",
623
+ " border-bottom-color: var(--fill-color);\n",
624
+ " }\n",
625
+ " 90% {\n",
626
+ " border-color: transparent;\n",
627
+ " border-bottom-color: var(--fill-color);\n",
628
+ " }\n",
629
+ " }\n",
630
+ "</style>\n",
631
+ "\n",
632
+ " <script>\n",
633
+ " async function quickchart(key) {\n",
634
+ " const quickchartButtonEl =\n",
635
+ " document.querySelector('#' + key + ' button');\n",
636
+ " quickchartButtonEl.disabled = true; // To prevent multiple clicks.\n",
637
+ " quickchartButtonEl.classList.add('colab-df-spinner');\n",
638
+ " try {\n",
639
+ " const charts = await google.colab.kernel.invokeFunction(\n",
640
+ " 'suggestCharts', [key], {});\n",
641
+ " } catch (error) {\n",
642
+ " console.error('Error during call to suggestCharts:', error);\n",
643
+ " }\n",
644
+ " quickchartButtonEl.classList.remove('colab-df-spinner');\n",
645
+ " quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
646
+ " }\n",
647
+ " (() => {\n",
648
+ " let quickchartButtonEl =\n",
649
+ " document.querySelector('#df-7fca458e-936c-4a6a-a0af-2f6ef67c3e8e button');\n",
650
+ " quickchartButtonEl.style.display =\n",
651
+ " google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
652
+ " })();\n",
653
+ " </script>\n",
654
+ "</div>\n",
655
+ "\n",
656
+ " </div>\n",
657
+ " </div>\n"
658
+ ],
659
+ "application/vnd.google.colaboratory.intrinsic+json": {
660
+ "type": "dataframe",
661
+ "variable_name": "df"
662
+ }
663
+ },
664
+ "metadata": {},
665
+ "execution_count": 10
666
+ }
667
+ ],
668
+ "source": [
669
+ "df.head()"
670
+ ]
671
+ },
672
+ {
673
+ "cell_type": "markdown",
674
+ "metadata": {
675
+ "id": "83f8b988"
676
+ },
677
+ "source": [
678
+ "## 5️⃣ Train-Test Split\n",
679
+ "Split the dataset into training and testing sets."
680
+ ]
681
+ },
682
+ {
683
+ "cell_type": "code",
684
+ "execution_count": 11,
685
+ "metadata": {
686
+ "id": "m8xtdVgq_ZBt"
687
+ },
688
+ "outputs": [],
689
+ "source": [
690
+ "# Example: Split based on a numerical condition\n",
691
+ "train_data = df[df['unit_name_encoded'] >= 6]\n",
692
+ "test_data = df[df['unit_name_encoded'] < 6]\n",
693
+ "\n",
694
+ "train_data = train_data.sample(frac=0.2, random_state=42)\n",
695
+ "\n",
696
+ "# Separate features and target\n",
697
+ "\n",
698
+ "X_train = train_data.drop(columns=['max_memory_util',\t'avg_memory_util',\t'max_gpu_util',\t'avg_gpu_util',\t'max_gpu_temp',\t'avg_gpu_temp', 'epoch_time',\t'fit_time'])\n",
699
+ "y_train = train_data[['epoch_time', 'fit_time', 'max_memory_util', 'max_gpu_util']]\n",
700
+ "X_test = test_data.drop(columns=['max_memory_util',\t'avg_memory_util',\t'max_gpu_util',\t'avg_gpu_util',\t'max_gpu_temp',\t'avg_gpu_temp', 'epoch_time',\t'fit_time']) # Replace 'fit_time_in_TF' with your target column\n",
701
+ "y_test = test_data[['epoch_time', 'fit_time', 'max_memory_util', 'max_gpu_util']]"
702
+ ]
703
+ },
704
+ {
705
+ "cell_type": "code",
706
+ "execution_count": null,
707
+ "metadata": {
708
+ "colab": {
709
+ "base_uri": "https://localhost:8080/"
710
+ },
711
+ "id": "0B124aBf-i7l",
712
+ "outputId": "5de51f6b-fbc7-4bbe-8849-89b9667f3218"
713
+ },
714
+ "outputs": [
715
+ {
716
+ "data": {
717
+ "text/plain": [
718
+ "(1553, 27)"
719
+ ]
720
+ },
721
+ "execution_count": 10,
722
+ "metadata": {},
723
+ "output_type": "execute_result"
724
+ }
725
+ ],
726
+ "source": [
727
+ "train_data.shape"
728
+ ]
729
+ },
730
+ {
731
+ "cell_type": "markdown",
732
+ "metadata": {
733
+ "id": "3250bbd6"
734
+ },
735
+ "source": [
736
+ "## 6️⃣ Model Building with XGBoost\n",
737
+ "Define, train, and predict using the XGBoost Regressor."
738
+ ]
739
+ },
740
+ {
741
+ "cell_type": "code",
742
+ "execution_count": 12,
743
+ "metadata": {
744
+ "colab": {
745
+ "base_uri": "https://localhost:8080/",
746
+ "height": 253
747
+ },
748
+ "id": "yc6bxIBq_ZuP",
749
+ "outputId": "83fb3bd1-d5fa-48aa-dc23-5248667f2974"
750
+ },
751
+ "outputs": [
752
+ {
753
+ "output_type": "execute_result",
754
+ "data": {
755
+ "text/plain": [
756
+ "XGBRegressor(base_score=None, booster=None, callbacks=None,\n",
757
+ " colsample_bylevel=None, colsample_bynode=None,\n",
758
+ " colsample_bytree=None, device=None, early_stopping_rounds=None,\n",
759
+ " enable_categorical=False, eval_metric=None, feature_types=None,\n",
760
+ " gamma=None, grow_policy=None, importance_type=None,\n",
761
+ " interaction_constraints=None, learning_rate=0.1, max_bin=None,\n",
762
+ " max_cat_threshold=None, max_cat_to_onehot=None,\n",
763
+ " max_delta_step=None, max_depth=6, max_leaves=None,\n",
764
+ " min_child_weight=None, missing=nan, monotone_constraints=None,\n",
765
+ " multi_strategy=None, n_estimators=100, n_jobs=None,\n",
766
+ " num_parallel_tree=None, random_state=42, ...)"
767
+ ],
768
+ "text/html": [
769
+ "<style>#sk-container-id-1 {\n",
770
+ " /* Definition of color scheme common for light and dark mode */\n",
771
+ " --sklearn-color-text: black;\n",
772
+ " --sklearn-color-line: gray;\n",
773
+ " /* Definition of color scheme for unfitted estimators */\n",
774
+ " --sklearn-color-unfitted-level-0: #fff5e6;\n",
775
+ " --sklearn-color-unfitted-level-1: #f6e4d2;\n",
776
+ " --sklearn-color-unfitted-level-2: #ffe0b3;\n",
777
+ " --sklearn-color-unfitted-level-3: chocolate;\n",
778
+ " /* Definition of color scheme for fitted estimators */\n",
779
+ " --sklearn-color-fitted-level-0: #f0f8ff;\n",
780
+ " --sklearn-color-fitted-level-1: #d4ebff;\n",
781
+ " --sklearn-color-fitted-level-2: #b3dbfd;\n",
782
+ " --sklearn-color-fitted-level-3: cornflowerblue;\n",
783
+ "\n",
784
+ " /* Specific color for light theme */\n",
785
+ " --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
786
+ " --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, white)));\n",
787
+ " --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
788
+ " --sklearn-color-icon: #696969;\n",
789
+ "\n",
790
+ " @media (prefers-color-scheme: dark) {\n",
791
+ " /* Redefinition of color scheme for dark theme */\n",
792
+ " --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
793
+ " --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, #111)));\n",
794
+ " --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
795
+ " --sklearn-color-icon: #878787;\n",
796
+ " }\n",
797
+ "}\n",
798
+ "\n",
799
+ "#sk-container-id-1 {\n",
800
+ " color: var(--sklearn-color-text);\n",
801
+ "}\n",
802
+ "\n",
803
+ "#sk-container-id-1 pre {\n",
804
+ " padding: 0;\n",
805
+ "}\n",
806
+ "\n",
807
+ "#sk-container-id-1 input.sk-hidden--visually {\n",
808
+ " border: 0;\n",
809
+ " clip: rect(1px 1px 1px 1px);\n",
810
+ " clip: rect(1px, 1px, 1px, 1px);\n",
811
+ " height: 1px;\n",
812
+ " margin: -1px;\n",
813
+ " overflow: hidden;\n",
814
+ " padding: 0;\n",
815
+ " position: absolute;\n",
816
+ " width: 1px;\n",
817
+ "}\n",
818
+ "\n",
819
+ "#sk-container-id-1 div.sk-dashed-wrapped {\n",
820
+ " border: 1px dashed var(--sklearn-color-line);\n",
821
+ " margin: 0 0.4em 0.5em 0.4em;\n",
822
+ " box-sizing: border-box;\n",
823
+ " padding-bottom: 0.4em;\n",
824
+ " background-color: var(--sklearn-color-background);\n",
825
+ "}\n",
826
+ "\n",
827
+ "#sk-container-id-1 div.sk-container {\n",
828
+ " /* jupyter's `normalize.less` sets `[hidden] { display: none; }`\n",
829
+ " but bootstrap.min.css set `[hidden] { display: none !important; }`\n",
830
+ " so we also need the `!important` here to be able to override the\n",
831
+ " default hidden behavior on the sphinx rendered scikit-learn.org.\n",
832
+ " See: https://github.com/scikit-learn/scikit-learn/issues/21755 */\n",
833
+ " display: inline-block !important;\n",
834
+ " position: relative;\n",
835
+ "}\n",
836
+ "\n",
837
+ "#sk-container-id-1 div.sk-text-repr-fallback {\n",
838
+ " display: none;\n",
839
+ "}\n",
840
+ "\n",
841
+ "div.sk-parallel-item,\n",
842
+ "div.sk-serial,\n",
843
+ "div.sk-item {\n",
844
+ " /* draw centered vertical line to link estimators */\n",
845
+ " background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));\n",
846
+ " background-size: 2px 100%;\n",
847
+ " background-repeat: no-repeat;\n",
848
+ " background-position: center center;\n",
849
+ "}\n",
850
+ "\n",
851
+ "/* Parallel-specific style estimator block */\n",
852
+ "\n",
853
+ "#sk-container-id-1 div.sk-parallel-item::after {\n",
854
+ " content: \"\";\n",
855
+ " width: 100%;\n",
856
+ " border-bottom: 2px solid var(--sklearn-color-text-on-default-background);\n",
857
+ " flex-grow: 1;\n",
858
+ "}\n",
859
+ "\n",
860
+ "#sk-container-id-1 div.sk-parallel {\n",
861
+ " display: flex;\n",
862
+ " align-items: stretch;\n",
863
+ " justify-content: center;\n",
864
+ " background-color: var(--sklearn-color-background);\n",
865
+ " position: relative;\n",
866
+ "}\n",
867
+ "\n",
868
+ "#sk-container-id-1 div.sk-parallel-item {\n",
869
+ " display: flex;\n",
870
+ " flex-direction: column;\n",
871
+ "}\n",
872
+ "\n",
873
+ "#sk-container-id-1 div.sk-parallel-item:first-child::after {\n",
874
+ " align-self: flex-end;\n",
875
+ " width: 50%;\n",
876
+ "}\n",
877
+ "\n",
878
+ "#sk-container-id-1 div.sk-parallel-item:last-child::after {\n",
879
+ " align-self: flex-start;\n",
880
+ " width: 50%;\n",
881
+ "}\n",
882
+ "\n",
883
+ "#sk-container-id-1 div.sk-parallel-item:only-child::after {\n",
884
+ " width: 0;\n",
885
+ "}\n",
886
+ "\n",
887
+ "/* Serial-specific style estimator block */\n",
888
+ "\n",
889
+ "#sk-container-id-1 div.sk-serial {\n",
890
+ " display: flex;\n",
891
+ " flex-direction: column;\n",
892
+ " align-items: center;\n",
893
+ " background-color: var(--sklearn-color-background);\n",
894
+ " padding-right: 1em;\n",
895
+ " padding-left: 1em;\n",
896
+ "}\n",
897
+ "\n",
898
+ "\n",
899
+ "/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is\n",
900
+ "clickable and can be expanded/collapsed.\n",
901
+ "- Pipeline and ColumnTransformer use this feature and define the default style\n",
902
+ "- Estimators will overwrite some part of the style using the `sk-estimator` class\n",
903
+ "*/\n",
904
+ "\n",
905
+ "/* Pipeline and ColumnTransformer style (default) */\n",
906
+ "\n",
907
+ "#sk-container-id-1 div.sk-toggleable {\n",
908
+ " /* Default theme specific background. It is overwritten whether we have a\n",
909
+ " specific estimator or a Pipeline/ColumnTransformer */\n",
910
+ " background-color: var(--sklearn-color-background);\n",
911
+ "}\n",
912
+ "\n",
913
+ "/* Toggleable label */\n",
914
+ "#sk-container-id-1 label.sk-toggleable__label {\n",
915
+ " cursor: pointer;\n",
916
+ " display: block;\n",
917
+ " width: 100%;\n",
918
+ " margin-bottom: 0;\n",
919
+ " padding: 0.5em;\n",
920
+ " box-sizing: border-box;\n",
921
+ " text-align: center;\n",
922
+ "}\n",
923
+ "\n",
924
+ "#sk-container-id-1 label.sk-toggleable__label-arrow:before {\n",
925
+ " /* Arrow on the left of the label */\n",
926
+ " content: \"▸\";\n",
927
+ " float: left;\n",
928
+ " margin-right: 0.25em;\n",
929
+ " color: var(--sklearn-color-icon);\n",
930
+ "}\n",
931
+ "\n",
932
+ "#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {\n",
933
+ " color: var(--sklearn-color-text);\n",
934
+ "}\n",
935
+ "\n",
936
+ "/* Toggleable content - dropdown */\n",
937
+ "\n",
938
+ "#sk-container-id-1 div.sk-toggleable__content {\n",
939
+ " max-height: 0;\n",
940
+ " max-width: 0;\n",
941
+ " overflow: hidden;\n",
942
+ " text-align: left;\n",
943
+ " /* unfitted */\n",
944
+ " background-color: var(--sklearn-color-unfitted-level-0);\n",
945
+ "}\n",
946
+ "\n",
947
+ "#sk-container-id-1 div.sk-toggleable__content.fitted {\n",
948
+ " /* fitted */\n",
949
+ " background-color: var(--sklearn-color-fitted-level-0);\n",
950
+ "}\n",
951
+ "\n",
952
+ "#sk-container-id-1 div.sk-toggleable__content pre {\n",
953
+ " margin: 0.2em;\n",
954
+ " border-radius: 0.25em;\n",
955
+ " color: var(--sklearn-color-text);\n",
956
+ " /* unfitted */\n",
957
+ " background-color: var(--sklearn-color-unfitted-level-0);\n",
958
+ "}\n",
959
+ "\n",
960
+ "#sk-container-id-1 div.sk-toggleable__content.fitted pre {\n",
961
+ " /* unfitted */\n",
962
+ " background-color: var(--sklearn-color-fitted-level-0);\n",
963
+ "}\n",
964
+ "\n",
965
+ "#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {\n",
966
+ " /* Expand drop-down */\n",
967
+ " max-height: 200px;\n",
968
+ " max-width: 100%;\n",
969
+ " overflow: auto;\n",
970
+ "}\n",
971
+ "\n",
972
+ "#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n",
973
+ " content: \"▾\";\n",
974
+ "}\n",
975
+ "\n",
976
+ "/* Pipeline/ColumnTransformer-specific style */\n",
977
+ "\n",
978
+ "#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
979
+ " color: var(--sklearn-color-text);\n",
980
+ " background-color: var(--sklearn-color-unfitted-level-2);\n",
981
+ "}\n",
982
+ "\n",
983
+ "#sk-container-id-1 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
984
+ " background-color: var(--sklearn-color-fitted-level-2);\n",
985
+ "}\n",
986
+ "\n",
987
+ "/* Estimator-specific style */\n",
988
+ "\n",
989
+ "/* Colorize estimator box */\n",
990
+ "#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
991
+ " /* unfitted */\n",
992
+ " background-color: var(--sklearn-color-unfitted-level-2);\n",
993
+ "}\n",
994
+ "\n",
995
+ "#sk-container-id-1 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
996
+ " /* fitted */\n",
997
+ " background-color: var(--sklearn-color-fitted-level-2);\n",
998
+ "}\n",
999
+ "\n",
1000
+ "#sk-container-id-1 div.sk-label label.sk-toggleable__label,\n",
1001
+ "#sk-container-id-1 div.sk-label label {\n",
1002
+ " /* The background is the default theme color */\n",
1003
+ " color: var(--sklearn-color-text-on-default-background);\n",
1004
+ "}\n",
1005
+ "\n",
1006
+ "/* On hover, darken the color of the background */\n",
1007
+ "#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {\n",
1008
+ " color: var(--sklearn-color-text);\n",
1009
+ " background-color: var(--sklearn-color-unfitted-level-2);\n",
1010
+ "}\n",
1011
+ "\n",
1012
+ "/* Label box, darken color on hover, fitted */\n",
1013
+ "#sk-container-id-1 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {\n",
1014
+ " color: var(--sklearn-color-text);\n",
1015
+ " background-color: var(--sklearn-color-fitted-level-2);\n",
1016
+ "}\n",
1017
+ "\n",
1018
+ "/* Estimator label */\n",
1019
+ "\n",
1020
+ "#sk-container-id-1 div.sk-label label {\n",
1021
+ " font-family: monospace;\n",
1022
+ " font-weight: bold;\n",
1023
+ " display: inline-block;\n",
1024
+ " line-height: 1.2em;\n",
1025
+ "}\n",
1026
+ "\n",
1027
+ "#sk-container-id-1 div.sk-label-container {\n",
1028
+ " text-align: center;\n",
1029
+ "}\n",
1030
+ "\n",
1031
+ "/* Estimator-specific */\n",
1032
+ "#sk-container-id-1 div.sk-estimator {\n",
1033
+ " font-family: monospace;\n",
1034
+ " border: 1px dotted var(--sklearn-color-border-box);\n",
1035
+ " border-radius: 0.25em;\n",
1036
+ " box-sizing: border-box;\n",
1037
+ " margin-bottom: 0.5em;\n",
1038
+ " /* unfitted */\n",
1039
+ " background-color: var(--sklearn-color-unfitted-level-0);\n",
1040
+ "}\n",
1041
+ "\n",
1042
+ "#sk-container-id-1 div.sk-estimator.fitted {\n",
1043
+ " /* fitted */\n",
1044
+ " background-color: var(--sklearn-color-fitted-level-0);\n",
1045
+ "}\n",
1046
+ "\n",
1047
+ "/* on hover */\n",
1048
+ "#sk-container-id-1 div.sk-estimator:hover {\n",
1049
+ " /* unfitted */\n",
1050
+ " background-color: var(--sklearn-color-unfitted-level-2);\n",
1051
+ "}\n",
1052
+ "\n",
1053
+ "#sk-container-id-1 div.sk-estimator.fitted:hover {\n",
1054
+ " /* fitted */\n",
1055
+ " background-color: var(--sklearn-color-fitted-level-2);\n",
1056
+ "}\n",
1057
+ "\n",
1058
+ "/* Specification for estimator info (e.g. \"i\" and \"?\") */\n",
1059
+ "\n",
1060
+ "/* Common style for \"i\" and \"?\" */\n",
1061
+ "\n",
1062
+ ".sk-estimator-doc-link,\n",
1063
+ "a:link.sk-estimator-doc-link,\n",
1064
+ "a:visited.sk-estimator-doc-link {\n",
1065
+ " float: right;\n",
1066
+ " font-size: smaller;\n",
1067
+ " line-height: 1em;\n",
1068
+ " font-family: monospace;\n",
1069
+ " background-color: var(--sklearn-color-background);\n",
1070
+ " border-radius: 1em;\n",
1071
+ " height: 1em;\n",
1072
+ " width: 1em;\n",
1073
+ " text-decoration: none !important;\n",
1074
+ " margin-left: 1ex;\n",
1075
+ " /* unfitted */\n",
1076
+ " border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
1077
+ " color: var(--sklearn-color-unfitted-level-1);\n",
1078
+ "}\n",
1079
+ "\n",
1080
+ ".sk-estimator-doc-link.fitted,\n",
1081
+ "a:link.sk-estimator-doc-link.fitted,\n",
1082
+ "a:visited.sk-estimator-doc-link.fitted {\n",
1083
+ " /* fitted */\n",
1084
+ " border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
1085
+ " color: var(--sklearn-color-fitted-level-1);\n",
1086
+ "}\n",
1087
+ "\n",
1088
+ "/* On hover */\n",
1089
+ "div.sk-estimator:hover .sk-estimator-doc-link:hover,\n",
1090
+ ".sk-estimator-doc-link:hover,\n",
1091
+ "div.sk-label-container:hover .sk-estimator-doc-link:hover,\n",
1092
+ ".sk-estimator-doc-link:hover {\n",
1093
+ " /* unfitted */\n",
1094
+ " background-color: var(--sklearn-color-unfitted-level-3);\n",
1095
+ " color: var(--sklearn-color-background);\n",
1096
+ " text-decoration: none;\n",
1097
+ "}\n",
1098
+ "\n",
1099
+ "div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,\n",
1100
+ ".sk-estimator-doc-link.fitted:hover,\n",
1101
+ "div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,\n",
1102
+ ".sk-estimator-doc-link.fitted:hover {\n",
1103
+ " /* fitted */\n",
1104
+ " background-color: var(--sklearn-color-fitted-level-3);\n",
1105
+ " color: var(--sklearn-color-background);\n",
1106
+ " text-decoration: none;\n",
1107
+ "}\n",
1108
+ "\n",
1109
+ "/* Span, style for the box shown on hovering the info icon */\n",
1110
+ ".sk-estimator-doc-link span {\n",
1111
+ " display: none;\n",
1112
+ " z-index: 9999;\n",
1113
+ " position: relative;\n",
1114
+ " font-weight: normal;\n",
1115
+ " right: .2ex;\n",
1116
+ " padding: .5ex;\n",
1117
+ " margin: .5ex;\n",
1118
+ " width: min-content;\n",
1119
+ " min-width: 20ex;\n",
1120
+ " max-width: 50ex;\n",
1121
+ " color: var(--sklearn-color-text);\n",
1122
+ " box-shadow: 2pt 2pt 4pt #999;\n",
1123
+ " /* unfitted */\n",
1124
+ " background: var(--sklearn-color-unfitted-level-0);\n",
1125
+ " border: .5pt solid var(--sklearn-color-unfitted-level-3);\n",
1126
+ "}\n",
1127
+ "\n",
1128
+ ".sk-estimator-doc-link.fitted span {\n",
1129
+ " /* fitted */\n",
1130
+ " background: var(--sklearn-color-fitted-level-0);\n",
1131
+ " border: var(--sklearn-color-fitted-level-3);\n",
1132
+ "}\n",
1133
+ "\n",
1134
+ ".sk-estimator-doc-link:hover span {\n",
1135
+ " display: block;\n",
1136
+ "}\n",
1137
+ "\n",
1138
+ "/* \"?\"-specific style due to the `<a>` HTML tag */\n",
1139
+ "\n",
1140
+ "#sk-container-id-1 a.estimator_doc_link {\n",
1141
+ " float: right;\n",
1142
+ " font-size: 1rem;\n",
1143
+ " line-height: 1em;\n",
1144
+ " font-family: monospace;\n",
1145
+ " background-color: var(--sklearn-color-background);\n",
1146
+ " border-radius: 1rem;\n",
1147
+ " height: 1rem;\n",
1148
+ " width: 1rem;\n",
1149
+ " text-decoration: none;\n",
1150
+ " /* unfitted */\n",
1151
+ " color: var(--sklearn-color-unfitted-level-1);\n",
1152
+ " border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
1153
+ "}\n",
1154
+ "\n",
1155
+ "#sk-container-id-1 a.estimator_doc_link.fitted {\n",
1156
+ " /* fitted */\n",
1157
+ " border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
1158
+ " color: var(--sklearn-color-fitted-level-1);\n",
1159
+ "}\n",
1160
+ "\n",
1161
+ "/* On hover */\n",
1162
+ "#sk-container-id-1 a.estimator_doc_link:hover {\n",
1163
+ " /* unfitted */\n",
1164
+ " background-color: var(--sklearn-color-unfitted-level-3);\n",
1165
+ " color: var(--sklearn-color-background);\n",
1166
+ " text-decoration: none;\n",
1167
+ "}\n",
1168
+ "\n",
1169
+ "#sk-container-id-1 a.estimator_doc_link.fitted:hover {\n",
1170
+ " /* fitted */\n",
1171
+ " background-color: var(--sklearn-color-fitted-level-3);\n",
1172
+ "}\n",
1173
+ "</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>XGBRegressor(base_score=None, booster=None, callbacks=None,\n",
1174
+ " colsample_bylevel=None, colsample_bynode=None,\n",
1175
+ " colsample_bytree=None, device=None, early_stopping_rounds=None,\n",
1176
+ " enable_categorical=False, eval_metric=None, feature_types=None,\n",
1177
+ " gamma=None, grow_policy=None, importance_type=None,\n",
1178
+ " interaction_constraints=None, learning_rate=0.1, max_bin=None,\n",
1179
+ " max_cat_threshold=None, max_cat_to_onehot=None,\n",
1180
+ " max_delta_step=None, max_depth=6, max_leaves=None,\n",
1181
+ " min_child_weight=None, missing=nan, monotone_constraints=None,\n",
1182
+ " multi_strategy=None, n_estimators=100, n_jobs=None,\n",
1183
+ " num_parallel_tree=None, random_state=42, ...)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator fitted sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\" checked><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label fitted sk-toggleable__label-arrow fitted\">&nbsp;XGBRegressor<span class=\"sk-estimator-doc-link fitted\">i<span>Fitted</span></span></label><div class=\"sk-toggleable__content fitted\"><pre>XGBRegressor(base_score=None, booster=None, callbacks=None,\n",
1184
+ " colsample_bylevel=None, colsample_bynode=None,\n",
1185
+ " colsample_bytree=None, device=None, early_stopping_rounds=None,\n",
1186
+ " enable_categorical=False, eval_metric=None, feature_types=None,\n",
1187
+ " gamma=None, grow_policy=None, importance_type=None,\n",
1188
+ " interaction_constraints=None, learning_rate=0.1, max_bin=None,\n",
1189
+ " max_cat_threshold=None, max_cat_to_onehot=None,\n",
1190
+ " max_delta_step=None, max_depth=6, max_leaves=None,\n",
1191
+ " min_child_weight=None, missing=nan, monotone_constraints=None,\n",
1192
+ " multi_strategy=None, n_estimators=100, n_jobs=None,\n",
1193
+ " num_parallel_tree=None, random_state=42, ...)</pre></div> </div></div></div></div>"
1194
+ ]
1195
+ },
1196
+ "metadata": {},
1197
+ "execution_count": 12
1198
+ }
1199
+ ],
1200
+ "source": [
1201
+ "xgb_model = XGBRegressor(\n",
1202
+ " n_estimators=100,\n",
1203
+ " learning_rate=0.1,\n",
1204
+ " max_depth=6,\n",
1205
+ " random_state=42,\n",
1206
+ " verbosity=1\n",
1207
+ ")\n",
1208
+ "\n",
1209
+ "# Train the model\n",
1210
+ "xgb_model.fit(X_train, y_train)"
1211
+ ]
1212
+ },
1213
+ {
1214
+ "cell_type": "code",
1215
+ "execution_count": 14,
1216
+ "metadata": {
1217
+ "id": "4moppOvOFnZD"
1218
+ },
1219
+ "outputs": [],
1220
+ "source": [
1221
+ "# Predict on the test set\n",
1222
+ "y_pred = xgb_model.predict(X_test)"
1223
+ ]
1224
+ },
1225
+ {
1226
+ "cell_type": "code",
1227
+ "execution_count": 15,
1228
+ "metadata": {
1229
+ "colab": {
1230
+ "base_uri": "https://localhost:8080/"
1231
+ },
1232
+ "id": "xIwFbkEyNuby",
1233
+ "outputId": "2f9fb71f-b828-41b6-e9bb-2a5747a18444"
1234
+ },
1235
+ "outputs": [
1236
+ {
1237
+ "output_type": "execute_result",
1238
+ "data": {
1239
+ "text/plain": [
1240
+ "array([[21.514431 , 20.075377 , 5.7195935, 48.045883 ],\n",
1241
+ " [19.894218 , 19.883572 , 10.0262985, 69.34461 ],\n",
1242
+ " [20.112694 , 20.007633 , 11.493458 , 73.78841 ],\n",
1243
+ " [12.975633 , 18.08273 , 7.1654763, 45.41951 ],\n",
1244
+ " [12.418544 , 18.560135 , 8.162864 , 59.944546 ],\n",
1245
+ " [12.637019 , 18.684196 , 8.962711 , 67.1194 ],\n",
1246
+ " [ 6.4134297, 20.612186 , 10.105451 , 60.0018 ],\n",
1247
+ " [ 5.8482485, 21.089592 , 10.060244 , 67.4093 ],\n",
1248
+ " [ 5.8482485, 20.968369 , 10.259554 , 74.447716 ],\n",
1249
+ " [ 4.295031 , 22.474957 , 10.036483 , 67.872734 ]], dtype=float32)"
1250
+ ]
1251
+ },
1252
+ "metadata": {},
1253
+ "execution_count": 15
1254
+ }
1255
+ ],
1256
+ "source": [
1257
+ "y_pred[:10]"
1258
+ ]
1259
+ },
1260
+ {
1261
+ "cell_type": "markdown",
1262
+ "metadata": {
1263
+ "id": "b996833d"
1264
+ },
1265
+ "source": [
1266
+ "## 7️⃣ Evaluation Metrics\n",
1267
+ "Calculate MAPE, MSPE, RMSPE, and standard regression metrics."
1268
+ ]
1269
+ },
1270
+ {
1271
+ "cell_type": "code",
1272
+ "execution_count": 16,
1273
+ "metadata": {
1274
+ "colab": {
1275
+ "base_uri": "https://localhost:8080/"
1276
+ },
1277
+ "id": "gL5b_8Fb_lyj",
1278
+ "outputId": "05c40163-4803-4788-cc3d-34d0e9438dea"
1279
+ },
1280
+ "outputs": [
1281
+ {
1282
+ "output_type": "stream",
1283
+ "name": "stderr",
1284
+ "text": [
1285
+ "<ipython-input-16-84545122e16d>:2: SettingWithCopyWarning: \n",
1286
+ "A value is trying to be set on a copy of a slice from a DataFrame.\n",
1287
+ "Try using .loc[row_indexer,col_indexer] = value instead\n",
1288
+ "\n",
1289
+ "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
1290
+ " df1['fit_time_res'] = (df1['batch_time'] / df1['batch']) * df1['samples'] * df1['epochs']\n"
1291
+ ]
1292
+ }
1293
+ ],
1294
+ "source": [
1295
+ "def manualCalculate(df1):\n",
1296
+ " df1['fit_time_res'] = (df1['batch_time'] / df1['batch']) * df1['samples'] * df1['epochs']\n",
1297
+ " return df1[['fit_time_res']]\n",
1298
+ "\n",
1299
+ "y_manual = manualCalculate(X_test[['batch_time', 'batch', 'samples', 'epochs']])"
1300
+ ]
1301
+ },
1302
+ {
1303
+ "cell_type": "code",
1304
+ "execution_count": 17,
1305
+ "metadata": {
1306
+ "colab": {
1307
+ "base_uri": "https://localhost:8080/"
1308
+ },
1309
+ "id": "zHc7GLmw_eDu",
1310
+ "outputId": "7240f37a-3dc2-4ae9-a3ac-08b977714fbd"
1311
+ },
1312
+ "outputs": [
1313
+ {
1314
+ "output_type": "stream",
1315
+ "name": "stdout",
1316
+ "text": [
1317
+ "Target Column 1:\n",
1318
+ " MSE: 1245.5831\n",
1319
+ " RMSE: 35.2928\n",
1320
+ " MAPE: 35.2928%\n",
1321
+ " MSPE: 42.7299%\n",
1322
+ " RMSPE: 6.5368%\n",
1323
+ "Target Column 2:\n",
1324
+ " MSE: 4263.1022\n",
1325
+ " RMSE: 65.2924\n",
1326
+ " MAPE: 65.2924%\n",
1327
+ " MSPE: 43.7782%\n",
1328
+ " RMSPE: 6.6165%\n",
1329
+ "Target Column 3:\n",
1330
+ " MSE: 99.2517\n",
1331
+ " RMSE: 9.9625\n",
1332
+ " MAPE: 9.9625%\n",
1333
+ " MSPE: inf%\n",
1334
+ " RMSPE: inf%\n",
1335
+ "Target Column 4:\n",
1336
+ " MSE: 456.3985\n",
1337
+ " RMSE: 21.3635\n",
1338
+ " MAPE: 21.3635%\n",
1339
+ " MSPE: inf%\n",
1340
+ " RMSPE: inf%\n"
1341
+ ]
1342
+ },
1343
+ {
1344
+ "output_type": "execute_result",
1345
+ "data": {
1346
+ "text/plain": [
1347
+ "['xgb_model_model.pkl']"
1348
+ ]
1349
+ },
1350
+ "metadata": {},
1351
+ "execution_count": 17
1352
+ }
1353
+ ],
1354
+ "source": [
1355
+ "\n",
1356
+ "\n",
1357
+ "mape__per_column, mspe_per_column, rmspe_per_column = calculate_mspe_rmspe(y_test, y_pred)\n",
1358
+ "\n",
1359
+ "mse_per_column = mean_squared_error(y_test, y_pred, multioutput='raw_values') # MSE for each column\n",
1360
+ "rmse_per_column = np.sqrt(mse_per_column) # RMSE for each column\n",
1361
+ "\n",
1362
+ "# Display results\n",
1363
+ "for i, (mse, rmse, mape, mspe, rmspe) in enumerate(zip(mse_per_column, rmse_per_column, mape__per_column, mspe_per_column, rmspe_per_column)):\n",
1364
+ " print(f\"Target Column {i + 1}:\")\n",
1365
+ " print(f\" MSE: {mse:.4f}\")\n",
1366
+ " print(f\" RMSE: {rmse:.4f}\")\n",
1367
+ " print(f\" MAPE: {rmse:.4f}%\")\n",
1368
+ " print(f\" MSPE: {mspe:.4f}%\")\n",
1369
+ " print(f\" RMSPE: {rmspe:.4f}%\")\n",
1370
+ "\n",
1371
+ "# Save the model for future use\n",
1372
+ "joblib.dump(xgb_model, 'xgb_model_model.pkl')\n",
1373
+ "\n",
1374
+ "# Example of loading the model\n",
1375
+ "# loaded_model = joblib.load('random_forest_model.pkl')"
1376
+ ]
1377
+ },
1378
+ {
1379
+ "cell_type": "code",
1380
+ "execution_count": 18,
1381
+ "metadata": {
1382
+ "colab": {
1383
+ "base_uri": "https://localhost:8080/"
1384
+ },
1385
+ "id": "VR0GKYPTBQqu",
1386
+ "outputId": "6ae3a663-c9d8-4c9d-a4ea-7db03208de35"
1387
+ },
1388
+ "outputs": [
1389
+ {
1390
+ "output_type": "stream",
1391
+ "name": "stdout",
1392
+ "text": [
1393
+ "Target Column 1:\n",
1394
+ " MSE: 111.3580\n",
1395
+ " RMSE: 10.5526\n",
1396
+ " MAPE: 10.5526%\n"
1397
+ ]
1398
+ },
1399
+ {
1400
+ "output_type": "execute_result",
1401
+ "data": {
1402
+ "text/plain": [
1403
+ "['xgb_model_model.pkl']"
1404
+ ]
1405
+ },
1406
+ "metadata": {},
1407
+ "execution_count": 18
1408
+ }
1409
+ ],
1410
+ "source": [
1411
+ "\n",
1412
+ "\n",
1413
+ "mape__per_column, mspe_per_column, rmspe_per_column = calculate_mspe_rmspe(y_test[['fit_time']], y_manual)\n",
1414
+ "\n",
1415
+ "mse_per_column = mean_squared_error(y_test[['fit_time']], y_manual, multioutput='raw_values') # MSE for each column\n",
1416
+ "rmse_per_column = np.sqrt(mse_per_column) # RMSE for each column\n",
1417
+ "\n",
1418
+ "# Display results\n",
1419
+ "for i, (mse, rmse, mape, mspe, rmspe) in enumerate(zip(mse_per_column, rmse_per_column, mape__per_column, mspe_per_column, rmspe_per_column)):\n",
1420
+ " print(f\"Target Column {i + 1}:\")\n",
1421
+ " print(f\" MSE: {mse:.4f}\")\n",
1422
+ " print(f\" RMSE: {rmse:.4f}\")\n",
1423
+ " print(f\" MAPE: {rmse:.4f}%\")\n",
1424
+ "\n",
1425
+ "# Save the model for future use\n",
1426
+ "joblib.dump(xgb_model, 'xgb_model_model.pkl')\n",
1427
+ "\n",
1428
+ "# Example of loading the model\n",
1429
+ "# loaded_model = joblib.load('random_forest_model.pkl')"
1430
+ ]
1431
+ },
1432
+ {
1433
+ "cell_type": "code",
1434
+ "execution_count": 19,
1435
+ "metadata": {
1436
+ "id": "c0a4ea0a"
1437
+ },
1438
+ "outputs": [],
1439
+ "source": [
1440
+ "from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score\n",
1441
+ "import matplotlib.pyplot as plt\n",
1442
+ "import seaborn as sns\n",
1443
+ "import numpy as np"
1444
+ ]
1445
+ },
1446
+ {
1447
+ "cell_type": "code",
1448
+ "execution_count": 22,
1449
+ "metadata": {
1450
+ "colab": {
1451
+ "base_uri": "https://localhost:8080/"
1452
+ },
1453
+ "id": "4f37c35d",
1454
+ "outputId": "6be2112f-41c1-4b0e-f367-f9ab8dd4f839"
1455
+ },
1456
+ "outputs": [
1457
+ {
1458
+ "output_type": "stream",
1459
+ "name": "stdout",
1460
+ "text": [
1461
+ "MAE: 24.9825\n",
1462
+ "RMSE: 32.9778\n",
1463
+ "R²: 0.2661\n"
1464
+ ]
1465
+ },
1466
+ {
1467
+ "output_type": "stream",
1468
+ "name": "stderr",
1469
+ "text": [
1470
+ "/usr/local/lib/python3.11/dist-packages/sklearn/metrics/_regression.py:492: FutureWarning: 'squared' is deprecated in version 1.4 and will be removed in 1.6. To calculate the root mean squared error, use the function'root_mean_squared_error'.\n",
1471
+ " warnings.warn(\n"
1472
+ ]
1473
+ }
1474
+ ],
1475
+ "source": [
1476
+ "# Standard Regression Metrics\n",
1477
+ "mae = mean_absolute_error(y_test, y_pred)\n",
1478
+ "rmse = mean_squared_error(y_test, y_pred, squared=False)\n",
1479
+ "r2 = r2_score(y_test, y_pred)\n",
1480
+ "\n",
1481
+ "print(f'MAE: {mae:.4f}')\n",
1482
+ "print(f'RMSE: {rmse:.4f}')\n",
1483
+ "print(f'R²: {r2:.4f}')"
1484
+ ]
1485
+ },
1486
+ {
1487
+ "cell_type": "markdown",
1488
+ "metadata": {
1489
+ "id": "c3eb4fc3"
1490
+ },
1491
+ "source": [
1492
+ "## 9️⃣ Conclusion\n",
1493
+ "Summarize key insights from the model performance and visualizations."
1494
+ ]
1495
+ },
1496
+ {
1497
+ "cell_type": "markdown",
1498
+ "metadata": {
1499
+ "id": "c78d5e48"
1500
+ },
1501
+ "source": [
1502
+ "### ✅ In Conclusion:\n",
1503
+ "- The XGBoost model provides a reasonable baseline for predicting CNN resource usage.\n",
1504
+ "- Visualization highlights areas where predictions deviate.\n",
1505
+ "- Feature importance gives insights into which factors most influence fit time.\n",
1506
+ "\n",
1507
+ "For future work, hyperparameter tuning and advanced models could improve accuracy."
1508
+ ]
1509
+ }
1510
+ ],
1511
+ "metadata": {
1512
+ "accelerator": "GPU",
1513
+ "colab": {
1514
+ "gpuType": "T4",
1515
+ "provenance": []
1516
+ },
1517
+ "kernelspec": {
1518
+ "display_name": "Python 3",
1519
+ "name": "python3"
1520
+ },
1521
+ "language_info": {
1522
+ "name": "python"
1523
+ }
1524
+ },
1525
+ "nbformat": 4,
1526
+ "nbformat_minor": 0
1527
+ }