├── DDOS_CNN.ipynb
├── DDOS_SGD,_KNN,_Naive_Bayes.ipynb
├── DDOS_XGBoost.ipynb
├── DDOS_dataProcessing.ipynb
├── README.md
└── where_to_find_the_preprocessed_dataset.md
/DDOS_CNN.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "name": "DDOS_CNN.ipynb",
7 | "provenance": [],
8 | "collapsed_sections": [],
9 | "authorship_tag": "ABX9TyPavcIoMzBgDmgzKpHYimZS",
10 | "include_colab_link": true
11 | },
12 | "kernelspec": {
13 | "name": "python3",
14 | "display_name": "Python 3"
15 | }
16 | },
17 | "cells": [
18 | {
19 | "cell_type": "markdown",
20 | "metadata": {
21 | "id": "view-in-github",
22 | "colab_type": "text"
23 | },
24 | "source": [
25 | "
"
26 | ]
27 | },
28 | {
29 | "cell_type": "code",
30 | "metadata": {
31 | "id": "xi2WzeFo5Emv",
32 | "colab_type": "code",
33 | "outputId": "22d20c94-12b3-47fc-bece-92508d7af59d",
34 | "colab": {
35 | "base_uri": "https://localhost:8080/",
36 | "height": 122
37 | }
38 | },
39 | "source": [
40 | "from google.colab import drive\n",
41 | "drive.mount('/content/drive')"
42 | ],
43 | "execution_count": 1,
44 | "outputs": [
45 | {
46 | "output_type": "stream",
47 | "text": [
48 | "Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=947318989803-6bn6qk8qdgf4n4g3pfee6491hc0brc4i.apps.googleusercontent.com&redirect_uri=urn%3aietf%3awg%3aoauth%3a2.0%3aoob&response_type=code&scope=email%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdocs.test%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive.photos.readonly%20https%3a%2f%2fwww.googleapis.com%2fauth%2fpeopleapi.readonly\n",
49 | "\n",
50 | "Enter your authorization code:\n",
51 | "··········\n",
52 | "Mounted at /content/drive\n"
53 | ],
54 | "name": "stdout"
55 | }
56 | ]
57 | },
58 | {
59 | "cell_type": "code",
60 | "metadata": {
61 | "id": "MiEJKiYQ5LS9",
62 | "colab_type": "code",
63 | "outputId": "3c499ab5-02ef-4bb9-c60e-1d64b34eb816",
64 | "colab": {
65 | "base_uri": "https://localhost:8080/",
66 | "height": 80
67 | }
68 | },
69 | "source": [
70 | " #%tensorflow_version 2.x\n",
71 | "from sklearn.preprocessing import LabelEncoder\n",
72 | "from keras.models import Sequential\n",
73 | "from keras.layers import Dense, Dropout, Activation, Lambda, Flatten\n",
74 | "from keras.layers import Convolution1D, Dense, Dropout, MaxPooling1D, LSTM\n",
75 | "from sklearn.model_selection import train_test_split\n",
76 | "from sklearn.preprocessing import Normalizer\n",
77 | "from keras import callbacks\n",
78 | "from keras.callbacks import CSVLogger\n",
79 | "from keras.utils import to_categorical\n",
80 | "from keras.callbacks import ModelCheckpoint, EarlyStopping, ReduceLROnPlateau, CSVLogger\n",
81 | "import numpy as np\n",
82 | "np.random.seed(0)"
83 | ],
84 | "execution_count": 2,
85 | "outputs": [
86 | {
87 | "output_type": "stream",
88 | "text": [
89 | "Using TensorFlow backend.\n"
90 | ],
91 | "name": "stderr"
92 | },
93 | {
94 | "output_type": "display_data",
95 | "data": {
96 | "text/html": [
97 | "
\n",
98 | "The default version of TensorFlow in Colab will soon switch to TensorFlow 2.x.
\n",
99 | "We recommend you upgrade now \n",
100 | "or ensure your notebook will continue to use TensorFlow 1.x via the %tensorflow_version 1.x
magic:\n",
101 | "more info.
\n"
102 | ],
103 | "text/plain": [
104 | ""
105 | ]
106 | },
107 | "metadata": {
108 | "tags": []
109 | }
110 | }
111 | ]
112 | },
113 | {
114 | "cell_type": "code",
115 | "metadata": {
116 | "id": "U8Y02jOF5RN7",
117 | "colab_type": "code",
118 | "colab": {}
119 | },
120 | "source": [
121 | "#loading dataset\n",
122 | "import pandas as pd\n",
123 | "x = pd.read_csv(\"/content/drive/My Drive/dos_dataset/clean_5.csv\")\n",
124 | "y = pd.read_csv(\"/content/drive/My Drive/dos_dataset/y.csv\")\n",
125 | "y=y['Label']\n",
126 | "x=x.drop(['Label'], axis=1)\n",
127 | "\n",
128 | "#normalizing the data\n",
129 | "normalized_df=(x-x.mean())/x.std()"
130 | ],
131 | "execution_count": 0,
132 | "outputs": []
133 | },
134 | {
135 | "cell_type": "code",
136 | "metadata": {
137 | "id": "EjJebHdeDSDD",
138 | "colab_type": "code",
139 | "colab": {}
140 | },
141 | "source": [
142 | "normalized_df=normalized_df.drop(['Unnamed: 0'], axis=1)\n",
143 | "normalized_df=normalized_df.drop(['Unnamed: 0.1'], axis=1)\n",
144 | "normalized_df=normalized_df.drop(['Unnamed: 0.1.1'], axis=1)\n",
145 | "normalized_df=normalized_df.drop(['Flow Bytes/s'], axis=1)\n",
146 | "normalized_df=normalized_df.drop([' Flow Packets/s'], axis=1)\n"
147 | ],
148 | "execution_count": 0,
149 | "outputs": []
150 | },
151 | {
152 | "cell_type": "code",
153 | "metadata": {
154 | "id": "8ilKdvOK5UDd",
155 | "colab_type": "code",
156 | "outputId": "9573b97f-7d71-4de1-d5cc-e5ac7b5573c0",
157 | "colab": {
158 | "base_uri": "https://localhost:8080/",
159 | "height": 275
160 | }
161 | },
162 | "source": [
163 | "normalized_df.head()"
164 | ],
165 | "execution_count": 5,
166 | "outputs": [
167 | {
168 | "output_type": "execute_result",
169 | "data": {
170 | "text/html": [
171 | "\n",
172 | "\n",
185 | "
\n",
186 | " \n",
187 | " \n",
188 | " | \n",
189 | " Source Port | \n",
190 | " Destination IP | \n",
191 | " Destination Port | \n",
192 | " Protocol | \n",
193 | " Total Length of Fwd Packets | \n",
194 | " Fwd Packet Length Max | \n",
195 | " Fwd Packet Length Min | \n",
196 | " Fwd Packet Length Mean | \n",
197 | " Bwd Packet Length Max | \n",
198 | " Bwd Packet Length Min | \n",
199 | " Bwd Packet Length Mean | \n",
200 | " Bwd Packet Length Std | \n",
201 | " Flow IAT Mean | \n",
202 | " Flow IAT Std | \n",
203 | " Fwd IAT Mean | \n",
204 | " Fwd IAT Std | \n",
205 | " Fwd PSH Flags | \n",
206 | " Fwd Packets/s | \n",
207 | " Min Packet Length | \n",
208 | " Max Packet Length | \n",
209 | " Packet Length Mean | \n",
210 | " Packet Length Variance | \n",
211 | " RST Flag Count | \n",
212 | " ACK Flag Count | \n",
213 | " URG Flag Count | \n",
214 | " CWE Flag Count | \n",
215 | " Average Packet Size | \n",
216 | " Avg Fwd Segment Size | \n",
217 | " Avg Bwd Segment Size | \n",
218 | " Subflow Fwd Bytes | \n",
219 | " Init_Win_bytes_forward | \n",
220 | " Init_Win_bytes_backward | \n",
221 | " Idle Std | \n",
222 | " Inbound | \n",
223 | "
\n",
224 | " \n",
225 | " \n",
226 | " \n",
227 | " 0 | \n",
228 | " 1.395596 | \n",
229 | " 0.157586 | \n",
230 | " -0.607399 | \n",
231 | " -2.031188 | \n",
232 | " -0.725421 | \n",
233 | " -0.954992 | \n",
234 | " -0.935156 | \n",
235 | " -0.945029 | \n",
236 | " -0.050579 | \n",
237 | " 0.342849 | \n",
238 | " 0.015085 | \n",
239 | " -0.076871 | \n",
240 | " -0.178761 | \n",
241 | " -0.175445 | \n",
242 | " -0.178330 | \n",
243 | " -0.168507 | \n",
244 | " -0.090471 | \n",
245 | " -1.335866 | \n",
246 | " -0.935040 | \n",
247 | " -0.940755 | \n",
248 | " -0.948545 | \n",
249 | " -0.069737 | \n",
250 | " -0.090471 | \n",
251 | " 2.209740 | \n",
252 | " -0.153371 | \n",
253 | " -0.101473 | \n",
254 | " -0.933777 | \n",
255 | " -0.945029 | \n",
256 | " 0.015085 | \n",
257 | " -0.725421 | \n",
258 | " -0.054584 | \n",
259 | " -0.057299 | \n",
260 | " -0.162793 | \n",
261 | " 0.19758 | \n",
262 | "
\n",
263 | " \n",
264 | " 1 | \n",
265 | " 0.347887 | \n",
266 | " 0.157586 | \n",
267 | " -1.625958 | \n",
268 | " -2.031188 | \n",
269 | " -0.733744 | \n",
270 | " -0.954992 | \n",
271 | " -0.935156 | \n",
272 | " -0.945029 | \n",
273 | " -0.050579 | \n",
274 | " 0.342849 | \n",
275 | " 0.015085 | \n",
276 | " -0.076871 | \n",
277 | " -0.216151 | \n",
278 | " -0.222876 | \n",
279 | " -0.227006 | \n",
280 | " -0.222546 | \n",
281 | " -0.090471 | \n",
282 | " -1.324001 | \n",
283 | " -0.935040 | \n",
284 | " -0.940755 | \n",
285 | " -0.948545 | \n",
286 | " -0.069737 | \n",
287 | " -0.090471 | \n",
288 | " 2.209740 | \n",
289 | " -0.153371 | \n",
290 | " -0.101473 | \n",
291 | " -0.933085 | \n",
292 | " -0.945029 | \n",
293 | " 0.015085 | \n",
294 | " -0.733744 | \n",
295 | " 7.027636 | \n",
296 | " -0.057299 | \n",
297 | " -0.162793 | \n",
298 | " 0.19758 | \n",
299 | "
\n",
300 | " \n",
301 | " 2 | \n",
302 | " 1.196809 | \n",
303 | " 0.157586 | \n",
304 | " -0.560525 | \n",
305 | " -2.031188 | \n",
306 | " -0.725421 | \n",
307 | " -0.954992 | \n",
308 | " -0.935156 | \n",
309 | " -0.945029 | \n",
310 | " -0.050579 | \n",
311 | " 0.342849 | \n",
312 | " 0.015085 | \n",
313 | " -0.076871 | \n",
314 | " -0.182709 | \n",
315 | " -0.180450 | \n",
316 | " -0.183461 | \n",
317 | " -0.174204 | \n",
318 | " -0.090471 | \n",
319 | " -1.335864 | \n",
320 | " -0.935040 | \n",
321 | " -0.940755 | \n",
322 | " -0.948545 | \n",
323 | " -0.069737 | \n",
324 | " -0.090471 | \n",
325 | " 2.209740 | \n",
326 | " -0.153371 | \n",
327 | " -0.101473 | \n",
328 | " -0.933777 | \n",
329 | " -0.945029 | \n",
330 | " 0.015085 | \n",
331 | " -0.725421 | \n",
332 | " -0.054584 | \n",
333 | " -0.057299 | \n",
334 | " -0.162793 | \n",
335 | " 0.19758 | \n",
336 | "
\n",
337 | " \n",
338 | " 3 | \n",
339 | " 0.892029 | \n",
340 | " 0.157586 | \n",
341 | " -1.562081 | \n",
342 | " -2.031188 | \n",
343 | " -0.725421 | \n",
344 | " -0.954992 | \n",
345 | " -0.935156 | \n",
346 | " -0.945029 | \n",
347 | " -0.050579 | \n",
348 | " 0.342849 | \n",
349 | " 0.015085 | \n",
350 | " -0.076871 | \n",
351 | " -0.186161 | \n",
352 | " -0.184840 | \n",
353 | " -0.187948 | \n",
354 | " -0.179186 | \n",
355 | " -0.090471 | \n",
356 | " -1.335861 | \n",
357 | " -0.935040 | \n",
358 | " -0.940755 | \n",
359 | " -0.948545 | \n",
360 | " -0.069737 | \n",
361 | " -0.090471 | \n",
362 | " 2.209740 | \n",
363 | " -0.153371 | \n",
364 | " -0.101473 | \n",
365 | " -0.933777 | \n",
366 | " -0.945029 | \n",
367 | " 0.015085 | \n",
368 | " -0.725421 | \n",
369 | " -0.054584 | \n",
370 | " -0.057299 | \n",
371 | " -0.162793 | \n",
372 | " 0.19758 | \n",
373 | "
\n",
374 | " \n",
375 | " 4 | \n",
376 | " -0.914218 | \n",
377 | " 0.157586 | \n",
378 | " 0.169285 | \n",
379 | " 0.489985 | \n",
380 | " -0.424394 | \n",
381 | " -0.494002 | \n",
382 | " -0.472024 | \n",
383 | " -0.480570 | \n",
384 | " -0.085259 | \n",
385 | " -0.138378 | \n",
386 | " -0.095478 | \n",
387 | " -0.076871 | \n",
388 | " -0.216208 | \n",
389 | " -0.222934 | \n",
390 | " -0.227005 | \n",
391 | " -0.222546 | \n",
392 | " -0.090471 | \n",
393 | " -0.610670 | \n",
394 | " -0.471885 | \n",
395 | " -0.494875 | \n",
396 | " -0.483551 | \n",
397 | " -0.069737 | \n",
398 | " -0.090471 | \n",
399 | " -0.452542 | \n",
400 | " -0.153371 | \n",
401 | " -0.101473 | \n",
402 | " -0.467788 | \n",
403 | " -0.480570 | \n",
404 | " -0.095478 | \n",
405 | " -0.424394 | \n",
406 | " -0.362285 | \n",
407 | " -0.057771 | \n",
408 | " -0.162793 | \n",
409 | " 0.19758 | \n",
410 | "
\n",
411 | " \n",
412 | "
\n",
413 | "
"
414 | ],
415 | "text/plain": [
416 | " Source Port Destination IP ... Idle Std Inbound\n",
417 | "0 1.395596 0.157586 ... -0.162793 0.19758\n",
418 | "1 0.347887 0.157586 ... -0.162793 0.19758\n",
419 | "2 1.196809 0.157586 ... -0.162793 0.19758\n",
420 | "3 0.892029 0.157586 ... -0.162793 0.19758\n",
421 | "4 -0.914218 0.157586 ... -0.162793 0.19758\n",
422 | "\n",
423 | "[5 rows x 34 columns]"
424 | ]
425 | },
426 | "metadata": {
427 | "tags": []
428 | },
429 | "execution_count": 5
430 | }
431 | ]
432 | },
433 | {
434 | "cell_type": "code",
435 | "metadata": {
436 | "id": "rEREKWdKiFB2",
437 | "colab_type": "code",
438 | "outputId": "27c8a91c-19b4-4711-fd89-edb774c80b91",
439 | "colab": {
440 | "base_uri": "https://localhost:8080/",
441 | "height": 34
442 | }
443 | },
444 | "source": [
445 | "y.nunique()"
446 | ],
447 | "execution_count": 6,
448 | "outputs": [
449 | {
450 | "output_type": "execute_result",
451 | "data": {
452 | "text/plain": [
453 | "8"
454 | ]
455 | },
456 | "metadata": {
457 | "tags": []
458 | },
459 | "execution_count": 6
460 | }
461 | ]
462 | },
463 | {
464 | "cell_type": "code",
465 | "metadata": {
466 | "id": "zBx1ZPpAKMZ1",
467 | "colab_type": "code",
468 | "outputId": "1741d9b4-3727-4e2c-9288-9ffc9329362d",
469 | "colab": {
470 | "base_uri": "https://localhost:8080/",
471 | "height": 204
472 | }
473 | },
474 | "source": [
475 | "y = pd.get_dummies(y,prefix=['Label'])\n",
476 | "y.head()"
477 | ],
478 | "execution_count": 7,
479 | "outputs": [
480 | {
481 | "output_type": "execute_result",
482 | "data": {
483 | "text/html": [
484 | "\n",
485 | "\n",
498 | "
\n",
499 | " \n",
500 | " \n",
501 | " | \n",
502 | " ['Label']_0 | \n",
503 | " ['Label']_1 | \n",
504 | " ['Label']_2 | \n",
505 | " ['Label']_3 | \n",
506 | " ['Label']_4 | \n",
507 | " ['Label']_5 | \n",
508 | " ['Label']_6 | \n",
509 | " ['Label']_7 | \n",
510 | "
\n",
511 | " \n",
512 | " \n",
513 | " \n",
514 | " 0 | \n",
515 | " 0 | \n",
516 | " 0 | \n",
517 | " 1 | \n",
518 | " 0 | \n",
519 | " 0 | \n",
520 | " 0 | \n",
521 | " 0 | \n",
522 | " 0 | \n",
523 | "
\n",
524 | " \n",
525 | " 1 | \n",
526 | " 0 | \n",
527 | " 0 | \n",
528 | " 1 | \n",
529 | " 0 | \n",
530 | " 0 | \n",
531 | " 0 | \n",
532 | " 0 | \n",
533 | " 0 | \n",
534 | "
\n",
535 | " \n",
536 | " 2 | \n",
537 | " 0 | \n",
538 | " 0 | \n",
539 | " 1 | \n",
540 | " 0 | \n",
541 | " 0 | \n",
542 | " 0 | \n",
543 | " 0 | \n",
544 | " 0 | \n",
545 | "
\n",
546 | " \n",
547 | " 3 | \n",
548 | " 0 | \n",
549 | " 0 | \n",
550 | " 1 | \n",
551 | " 0 | \n",
552 | " 0 | \n",
553 | " 0 | \n",
554 | " 0 | \n",
555 | " 0 | \n",
556 | "
\n",
557 | " \n",
558 | " 4 | \n",
559 | " 0 | \n",
560 | " 0 | \n",
561 | " 1 | \n",
562 | " 0 | \n",
563 | " 0 | \n",
564 | " 0 | \n",
565 | " 0 | \n",
566 | " 0 | \n",
567 | "
\n",
568 | " \n",
569 | "
\n",
570 | "
"
571 | ],
572 | "text/plain": [
573 | " ['Label']_0 ['Label']_1 ['Label']_2 ... ['Label']_5 ['Label']_6 ['Label']_7\n",
574 | "0 0 0 1 ... 0 0 0\n",
575 | "1 0 0 1 ... 0 0 0\n",
576 | "2 0 0 1 ... 0 0 0\n",
577 | "3 0 0 1 ... 0 0 0\n",
578 | "4 0 0 1 ... 0 0 0\n",
579 | "\n",
580 | "[5 rows x 8 columns]"
581 | ]
582 | },
583 | "metadata": {
584 | "tags": []
585 | },
586 | "execution_count": 7
587 | }
588 | ]
589 | },
590 | {
591 | "cell_type": "code",
592 | "metadata": {
593 | "id": "yXU3qYsqMecD",
594 | "colab_type": "code",
595 | "colab": {}
596 | },
597 | "source": [
598 | "from sklearn.model_selection import train_test_split\n",
599 | "X_train, X_test, y_train, y_test = train_test_split(normalized_df, y, test_size=0.25, random_state=0)\n",
600 | "y_train = np.array(y_train)"
601 | ],
602 | "execution_count": 0,
603 | "outputs": []
604 | },
605 | {
606 | "cell_type": "code",
607 | "metadata": {
608 | "id": "uXSDDA5b5biN",
609 | "colab_type": "code",
610 | "colab": {}
611 | },
612 | "source": [
613 | "y_train = np.array(y_train)\n",
614 | "y_test = np.array(y_test)\n",
615 | "X_train = np.array(X_train)\n",
616 | "X_test = np.array(X_test)\n",
617 | "X_train = np.reshape(X_train, (X_train.shape[0],X_train.shape[1],1))\n",
618 | "X_test = np.reshape(X_test, (X_test.shape[0],X_test.shape[1],1))"
619 | ],
620 | "execution_count": 0,
621 | "outputs": []
622 | },
623 | {
624 | "cell_type": "code",
625 | "metadata": {
626 | "id": "8AjyOGQX5eNt",
627 | "colab_type": "code",
628 | "outputId": "e8750d79-c2d8-4fd9-8540-352d01275a78",
629 | "colab": {
630 | "base_uri": "https://localhost:8080/",
631 | "height": 34
632 | }
633 | },
634 | "source": [
635 | "print('xtrain={}, ytrain={}, xtest={}, ytest={}'.format(X_train.shape,y_train.shape,X_test.shape,y_test.shape))"
636 | ],
637 | "execution_count": 10,
638 | "outputs": [
639 | {
640 | "output_type": "stream",
641 | "text": [
642 | "xtrain=(934348, 34, 1), ytrain=(934348, 8), xtest=(311450, 34, 1), ytest=(311450, 8)\n"
643 | ],
644 | "name": "stdout"
645 | }
646 | ]
647 | },
648 | {
649 | "cell_type": "code",
650 | "metadata": {
651 | "id": "2uy2mGjoMrDg",
652 | "colab_type": "code",
653 | "colab": {}
654 | },
655 | "source": [
656 | "from keras import optimizers\n",
657 | "sgd = optimizers.SGD(lr=0.009, decay=1e-6, momentum=0.9, nesterov=True)"
658 | ],
659 | "execution_count": 0,
660 | "outputs": []
661 | },
662 | {
663 | "cell_type": "code",
664 | "metadata": {
665 | "id": "eDumRGb15k19",
666 | "colab_type": "code",
667 | "colab": {}
668 | },
669 | "source": [
670 | "model = Sequential()\n",
671 | "model.add(Convolution1D(64, 3, activation=\"relu\", input_shape=(34,1)))\n",
672 | "model.add(Convolution1D(32, 3, activation=\"relu\"))\n",
673 | "#model.add(MaxPooling1D(pool_size=2))\n",
674 | "#model.add(Convolution1D(128, 3, activation=\"relu\"))\n",
675 | "#model.add(Convolution1D(128, 3, activation=\"relu\"))\n",
676 | "model.add(MaxPooling1D(pool_size=2))\n",
677 | "#model.add(Dropout(rate=0.3))\n",
678 | "model.add(Flatten())\n",
679 | "#model.add(Dense(30, activation=\"softmax\"))\n",
680 | "#model.add(Dense(10, activation=\"softmax\"))\n",
681 | "model.add(Dense(8))\n",
682 | "\n"
683 | ],
684 | "execution_count": 0,
685 | "outputs": []
686 | },
687 | {
688 | "cell_type": "code",
689 | "metadata": {
690 | "id": "AWBHKfGKM431",
691 | "colab_type": "code",
692 | "outputId": "9ce118f3-626c-4b95-bdc1-57653bce4776",
693 | "colab": {
694 | "base_uri": "https://localhost:8080/",
695 | "height": 921
696 | }
697 | },
698 | "source": [
699 | "model.compile(loss=\"mean_absolute_error\", optimizer=\"SGD\", metrics=['accuracy'])\n",
700 | "\n",
701 | "model.fit(X_train, y_train, epochs=20, batch_size=10, validation_data=(X_test, y_test))"
702 | ],
703 | "execution_count": 0,
704 | "outputs": [
705 | {
706 | "output_type": "stream",
707 | "text": [
708 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:1033: The name tf.assign_add is deprecated. Please use tf.compat.v1.assign_add instead.\n",
709 | "\n",
710 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:1020: The name tf.assign is deprecated. Please use tf.compat.v1.assign instead.\n",
711 | "\n",
712 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:3005: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.\n",
713 | "\n",
714 | "Train on 934348 samples, validate on 311450 samples\n",
715 | "Epoch 1/20\n",
716 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:190: The name tf.get_default_session is deprecated. Please use tf.compat.v1.get_default_session instead.\n",
717 | "\n",
718 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:197: The name tf.ConfigProto is deprecated. Please use tf.compat.v1.ConfigProto instead.\n",
719 | "\n",
720 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:207: The name tf.global_variables is deprecated. Please use tf.compat.v1.global_variables instead.\n",
721 | "\n",
722 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:216: The name tf.is_variable_initialized is deprecated. Please use tf.compat.v1.is_variable_initialized instead.\n",
723 | "\n",
724 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:223: The name tf.variables_initializer is deprecated. Please use tf.compat.v1.variables_initializer instead.\n",
725 | "\n",
726 | "934348/934348 [==============================] - 251s 268us/step - loss: 0.0641 - acc: 0.7995 - val_loss: 0.0566 - val_acc: 0.8215\n",
727 | "Epoch 2/20\n",
728 | "934348/934348 [==============================] - 250s 267us/step - loss: 0.0533 - acc: 0.8234 - val_loss: 0.0513 - val_acc: 0.8190\n",
729 | "Epoch 3/20\n",
730 | "934348/934348 [==============================] - 250s 267us/step - loss: 0.0509 - acc: 0.8227 - val_loss: 0.0509 - val_acc: 0.8215\n",
731 | "Epoch 4/20\n",
732 | "934348/934348 [==============================] - 247s 264us/step - loss: 0.0496 - acc: 0.8235 - val_loss: 0.0497 - val_acc: 0.8231\n",
733 | "Epoch 5/20\n",
734 | "934348/934348 [==============================] - 248s 265us/step - loss: 0.0488 - acc: 0.8239 - val_loss: 0.0487 - val_acc: 0.8232\n",
735 | "Epoch 6/20\n",
736 | "934348/934348 [==============================] - 247s 265us/step - loss: 0.0482 - acc: 0.8244 - val_loss: 0.0476 - val_acc: 0.8232\n",
737 | "Epoch 7/20\n",
738 | "934348/934348 [==============================] - 249s 266us/step - loss: 0.0477 - acc: 0.8248 - val_loss: 0.0482 - val_acc: 0.8232\n",
739 | "Epoch 8/20\n",
740 | " 50410/934348 [>.............................] - ETA: 3:18 - loss: 0.0481 - acc: 0.8231"
741 | ],
742 | "name": "stdout"
743 | },
744 | {
745 | "output_type": "error",
746 | "ename": "KeyboardInterrupt",
747 | "evalue": "ignored",
748 | "traceback": [
749 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
750 | "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
751 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcompile\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mloss\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"mean_absolute_error\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moptimizer\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"SGD\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmetrics\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'accuracy'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX_train\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my_train\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mepochs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m20\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbatch_size\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalidation_data\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX_test\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my_test\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
752 | "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/keras/engine/training.py\u001b[0m in \u001b[0;36mfit\u001b[0;34m(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, max_queue_size, workers, use_multiprocessing, **kwargs)\u001b[0m\n\u001b[1;32m 1176\u001b[0m \u001b[0msteps_per_epoch\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msteps_per_epoch\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1177\u001b[0m \u001b[0mvalidation_steps\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mvalidation_steps\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1178\u001b[0;31m validation_freq=validation_freq)\n\u001b[0m\u001b[1;32m 1179\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1180\u001b[0m def evaluate(self,\n",
753 | "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/keras/engine/training_arrays.py\u001b[0m in \u001b[0;36mfit_loop\u001b[0;34m(model, fit_function, fit_inputs, out_labels, batch_size, epochs, verbose, callbacks, val_function, val_inputs, shuffle, callback_metrics, initial_epoch, steps_per_epoch, validation_steps, validation_freq)\u001b[0m\n\u001b[1;32m 202\u001b[0m \u001b[0mins_batch\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mins_batch\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtoarray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 203\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 204\u001b[0;31m \u001b[0mouts\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfit_function\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mins_batch\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 205\u001b[0m \u001b[0mouts\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mto_list\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mouts\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 206\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0ml\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mo\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mout_labels\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mouts\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
754 | "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, inputs)\u001b[0m\n\u001b[1;32m 2977\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_legacy_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2978\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2979\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2980\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2981\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mpy_any\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mis_tensor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0minputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
755 | "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py\u001b[0m in \u001b[0;36m_call\u001b[0;34m(self, inputs)\u001b[0m\n\u001b[1;32m 2935\u001b[0m \u001b[0mfetched\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_callable_fn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0marray_vals\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrun_metadata\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun_metadata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2936\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2937\u001b[0;31m \u001b[0mfetched\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_callable_fn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0marray_vals\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2938\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mfetched\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0moutputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2939\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
756 | "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/client/session.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1470\u001b[0m ret = tf_session.TF_SessionRunCallable(self._session._session,\n\u001b[1;32m 1471\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_handle\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1472\u001b[0;31m run_metadata_ptr)\n\u001b[0m\u001b[1;32m 1473\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mrun_metadata\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1474\u001b[0m \u001b[0mproto_data\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtf_session\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mTF_GetBuffer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrun_metadata_ptr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
757 | "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
758 | ]
759 | }
760 | ]
761 | },
762 | {
763 | "cell_type": "code",
764 | "metadata": {
765 | "id": "QJBkErPzm9im",
766 | "colab_type": "code",
767 | "outputId": "df42b31f-d3c6-4a2e-9c7b-e86454f43e2d",
768 | "colab": {
769 | "base_uri": "https://localhost:8080/",
770 | "height": 595
771 | }
772 | },
773 | "source": [
774 | "m = Sequential()\n",
775 | "m.add(Convolution1D(128, 3, activation=\"relu\", input_shape=(34,1)))\n",
776 | "m.add(Convolution1D(64, 3, activation=\"relu\"))\n",
777 | "m.add(MaxPooling1D(pool_size=2))\n",
778 | "#model.add(Dropout(rate=0.3))\n",
779 | "#m.add(LSTM(500))\n",
780 | "m.add(Flatten())\n",
781 | "m.add(Dense(8))\n",
782 | "\n",
783 | "\n",
784 | "m.compile(loss=\"mean_absolute_error\", optimizer=\"adam\", metrics=['accuracy'])\n",
785 | "m.fit(X_train, y_train, epochs=20, batch_size=10, validation_data=(X_test, y_test))"
786 | ],
787 | "execution_count": 0,
788 | "outputs": [
789 | {
790 | "output_type": "stream",
791 | "text": [
792 | "Train on 934348 samples, validate on 311450 samples\n",
793 | "Epoch 1/20\n",
794 | "934348/934348 [==============================] - 430s 460us/step - loss: 0.0475 - acc: 0.8276 - val_loss: 0.0453 - val_acc: 0.8297\n",
795 | "Epoch 2/20\n",
796 | "934348/934348 [==============================] - 430s 460us/step - loss: 0.0443 - acc: 0.8361 - val_loss: 0.0430 - val_acc: 0.8385\n",
797 | "Epoch 3/20\n",
798 | "934348/934348 [==============================] - 429s 459us/step - loss: 0.0437 - acc: 0.8377 - val_loss: 0.0436 - val_acc: 0.8333\n",
799 | "Epoch 4/20\n",
800 | "934348/934348 [==============================] - 431s 461us/step - loss: 0.0429 - acc: 0.8391 - val_loss: 0.0424 - val_acc: 0.8393\n",
801 | "Epoch 5/20\n",
802 | "934348/934348 [==============================] - 429s 459us/step - loss: 0.0425 - acc: 0.8395 - val_loss: 0.0433 - val_acc: 0.8340\n",
803 | "Epoch 6/20\n",
804 | "934348/934348 [==============================] - 429s 459us/step - loss: 0.0423 - acc: 0.8397 - val_loss: 0.0431 - val_acc: 0.8384\n",
805 | "Epoch 7/20\n",
806 | "279910/934348 [=======>......................] - ETA: 4:24 - loss: 0.0424 - acc: 0.8392"
807 | ],
808 | "name": "stdout"
809 | },
810 | {
811 | "output_type": "error",
812 | "ename": "KeyboardInterrupt",
813 | "evalue": "ignored",
814 | "traceback": [
815 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
816 | "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
817 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[0mm\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcompile\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mloss\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"mean_absolute_error\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moptimizer\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"adam\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmetrics\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'accuracy'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 12\u001b[0;31m \u001b[0mm\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX_train\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my_train\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mepochs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m20\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbatch_size\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalidation_data\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX_test\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my_test\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
818 | "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/keras/engine/training.py\u001b[0m in \u001b[0;36mfit\u001b[0;34m(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, max_queue_size, workers, use_multiprocessing, **kwargs)\u001b[0m\n\u001b[1;32m 1176\u001b[0m \u001b[0msteps_per_epoch\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msteps_per_epoch\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1177\u001b[0m \u001b[0mvalidation_steps\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mvalidation_steps\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1178\u001b[0;31m validation_freq=validation_freq)\n\u001b[0m\u001b[1;32m 1179\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1180\u001b[0m def evaluate(self,\n",
819 | "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/keras/engine/training_arrays.py\u001b[0m in \u001b[0;36mfit_loop\u001b[0;34m(model, fit_function, fit_inputs, out_labels, batch_size, epochs, verbose, callbacks, val_function, val_inputs, shuffle, callback_metrics, initial_epoch, steps_per_epoch, validation_steps, validation_freq)\u001b[0m\n\u001b[1;32m 202\u001b[0m \u001b[0mins_batch\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mins_batch\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtoarray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 203\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 204\u001b[0;31m \u001b[0mouts\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfit_function\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mins_batch\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 205\u001b[0m \u001b[0mouts\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mto_list\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mouts\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 206\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0ml\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mo\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mout_labels\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mouts\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
820 | "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, inputs)\u001b[0m\n\u001b[1;32m 2977\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_legacy_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2978\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2979\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2980\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2981\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mpy_any\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mis_tensor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0minputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
821 | "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py\u001b[0m in \u001b[0;36m_call\u001b[0;34m(self, inputs)\u001b[0m\n\u001b[1;32m 2935\u001b[0m \u001b[0mfetched\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_callable_fn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0marray_vals\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrun_metadata\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun_metadata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2936\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2937\u001b[0;31m \u001b[0mfetched\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_callable_fn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0marray_vals\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2938\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mfetched\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0moutputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2939\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
822 | "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/client/session.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1470\u001b[0m ret = tf_session.TF_SessionRunCallable(self._session._session,\n\u001b[1;32m 1471\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_handle\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1472\u001b[0;31m run_metadata_ptr)\n\u001b[0m\u001b[1;32m 1473\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mrun_metadata\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1474\u001b[0m \u001b[0mproto_data\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtf_session\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mTF_GetBuffer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrun_metadata_ptr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
823 | "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
824 | ]
825 | }
826 | ]
827 | },
828 | {
829 | "cell_type": "code",
830 | "metadata": {
831 | "id": "rlwondpcztdH",
832 | "colab_type": "code",
833 | "outputId": "727f85ab-1d7a-4241-b58e-cd114797f771",
834 | "colab": {
835 | "base_uri": "https://localhost:8080/",
836 | "height": 1000
837 | }
838 | },
839 | "source": [
840 | "m2 = Sequential()\n",
841 | "m2.add(Convolution1D(64, 3, activation=\"relu\", input_shape=(34,1)))\n",
842 | "m2.add(Convolution1D(32, 3, activation=\"relu\"))\n",
843 | "m2.add(MaxPooling1D(pool_size=2))\n",
844 | "m2.add(Flatten())\n",
845 | "m2.add(Dense(8))\n",
846 | "\n",
847 | "\n",
848 | "m2.compile(loss=\"mean_absolute_error\", optimizer=\"adam\", metrics=['accuracy'])\n",
849 | "m2.fit(X_train, y_train, epochs=20, batch_size=10, validation_data=(X_test, y_test))"
850 | ],
851 | "execution_count": 0,
852 | "outputs": [
853 | {
854 | "output_type": "stream",
855 | "text": [
856 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:66: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.\n",
857 | "\n",
858 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:541: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.\n",
859 | "\n",
860 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:4432: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead.\n",
861 | "\n",
862 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:4267: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.\n",
863 | "\n",
864 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/optimizers.py:793: The name tf.train.Optimizer is deprecated. Please use tf.compat.v1.train.Optimizer instead.\n",
865 | "\n",
866 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:1033: The name tf.assign_add is deprecated. Please use tf.compat.v1.assign_add instead.\n",
867 | "\n",
868 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:1020: The name tf.assign is deprecated. Please use tf.compat.v1.assign instead.\n",
869 | "\n",
870 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:3005: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.\n",
871 | "\n",
872 | "Train on 934348 samples, validate on 311450 samples\n",
873 | "Epoch 1/20\n",
874 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:190: The name tf.get_default_session is deprecated. Please use tf.compat.v1.get_default_session instead.\n",
875 | "\n",
876 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:197: The name tf.ConfigProto is deprecated. Please use tf.compat.v1.ConfigProto instead.\n",
877 | "\n",
878 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:207: The name tf.global_variables is deprecated. Please use tf.compat.v1.global_variables instead.\n",
879 | "\n",
880 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:216: The name tf.is_variable_initialized is deprecated. Please use tf.compat.v1.is_variable_initialized instead.\n",
881 | "\n",
882 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:223: The name tf.variables_initializer is deprecated. Please use tf.compat.v1.variables_initializer instead.\n",
883 | "\n",
884 | "934348/934348 [==============================] - 268s 287us/step - loss: 0.0472 - acc: 0.8289 - val_loss: 0.0437 - val_acc: 0.8392\n",
885 | "Epoch 2/20\n",
886 | "934348/934348 [==============================] - 266s 285us/step - loss: 0.0436 - acc: 0.8360 - val_loss: 0.0436 - val_acc: 0.8325\n",
887 | "Epoch 3/20\n",
888 | "934348/934348 [==============================] - 271s 290us/step - loss: 0.0431 - acc: 0.8367 - val_loss: 0.0468 - val_acc: 0.8170\n",
889 | "Epoch 4/20\n",
890 | "934348/934348 [==============================] - 275s 295us/step - loss: 0.0429 - acc: 0.8376 - val_loss: 0.0423 - val_acc: 0.8379\n",
891 | "Epoch 5/20\n",
892 | "934348/934348 [==============================] - 265s 284us/step - loss: 0.0425 - acc: 0.8386 - val_loss: 0.0432 - val_acc: 0.8327\n",
893 | "Epoch 6/20\n",
894 | "934348/934348 [==============================] - 263s 282us/step - loss: 0.0423 - acc: 0.8388 - val_loss: 0.0425 - val_acc: 0.8381\n",
895 | "Epoch 7/20\n",
896 | "934348/934348 [==============================] - 263s 281us/step - loss: 0.0423 - acc: 0.8386 - val_loss: 0.0419 - val_acc: 0.8383\n",
897 | "Epoch 8/20\n",
898 | "934348/934348 [==============================] - 261s 279us/step - loss: 0.0422 - acc: 0.8386 - val_loss: 0.0426 - val_acc: 0.8374\n",
899 | "Epoch 9/20\n",
900 | "934348/934348 [==============================] - 259s 278us/step - loss: 0.0424 - acc: 0.8380 - val_loss: 0.0428 - val_acc: 0.8380\n",
901 | "Epoch 10/20\n",
902 | "934348/934348 [==============================] - 263s 282us/step - loss: 0.0422 - acc: 0.8382 - val_loss: 0.0416 - val_acc: 0.8392\n",
903 | "Epoch 11/20\n",
904 | "934348/934348 [==============================] - 263s 281us/step - loss: 0.0422 - acc: 0.8384 - val_loss: 0.0422 - val_acc: 0.8370\n",
905 | "Epoch 12/20\n",
906 | "934348/934348 [==============================] - 266s 284us/step - loss: 0.0423 - acc: 0.8381 - val_loss: 0.0422 - val_acc: 0.8374\n",
907 | "Epoch 13/20\n",
908 | "934348/934348 [==============================] - 271s 290us/step - loss: 0.0422 - acc: 0.8384 - val_loss: 0.0439 - val_acc: 0.8337\n",
909 | "Epoch 14/20\n",
910 | "934348/934348 [==============================] - 273s 293us/step - loss: 0.0421 - acc: 0.8385 - val_loss: 0.0417 - val_acc: 0.8384\n",
911 | "Epoch 15/20\n",
912 | "934348/934348 [==============================] - 268s 287us/step - loss: 0.0421 - acc: 0.8384 - val_loss: 0.0414 - val_acc: 0.8393\n",
913 | "Epoch 16/20\n",
914 | "934348/934348 [==============================] - 267s 286us/step - loss: 0.0423 - acc: 0.8385 - val_loss: 0.0418 - val_acc: 0.8386\n",
915 | "Epoch 17/20\n",
916 | "934348/934348 [==============================] - 261s 279us/step - loss: 0.0419 - acc: 0.8392 - val_loss: 0.0417 - val_acc: 0.8396\n",
917 | "Epoch 18/20\n",
918 | "934348/934348 [==============================] - 263s 281us/step - loss: 0.0423 - acc: 0.8382 - val_loss: 0.0418 - val_acc: 0.8384\n",
919 | "Epoch 19/20\n",
920 | "934348/934348 [==============================] - 264s 283us/step - loss: 0.0423 - acc: 0.8389 - val_loss: 0.0416 - val_acc: 0.8404\n",
921 | "Epoch 20/20\n",
922 | "934348/934348 [==============================] - 265s 284us/step - loss: 0.0425 - acc: 0.8373 - val_loss: 0.0423 - val_acc: 0.8389\n"
923 | ],
924 | "name": "stdout"
925 | },
926 | {
927 | "output_type": "execute_result",
928 | "data": {
929 | "text/plain": [
930 | ""
931 | ]
932 | },
933 | "metadata": {
934 | "tags": []
935 | },
936 | "execution_count": 11
937 | }
938 | ]
939 | },
940 | {
941 | "cell_type": "code",
942 | "metadata": {
943 | "id": "LkSMdt3q9ffc",
944 | "colab_type": "code",
945 | "colab": {
946 | "base_uri": "https://localhost:8080/",
947 | "height": 1000
948 | },
949 | "outputId": "d72a4f3f-b045-4813-b8fd-d6cc06c657ba"
950 | },
951 | "source": [
952 | "m2 = Sequential()\n",
953 | "m2.add(Convolution1D(64, 3, activation=\"relu\", input_shape=(34,1)))\n",
954 | "m2.add(Convolution1D(32, 3, activation=\"relu\"))\n",
955 | "m2.add(MaxPooling1D(pool_size=2))\n",
956 | "m2.add(Flatten())\n",
957 | "m2.add(Dense(8))\n",
958 | "\n",
959 | "\n",
960 | "m2.compile(loss=\"mean_absolute_error\", optimizer=\"adam\", metrics=['accuracy'])\n",
961 | "m2.fit(X_train, y_train, epochs=20, batch_size=10, validation_data=(X_test, y_test))"
962 | ],
963 | "execution_count": 11,
964 | "outputs": [
965 | {
966 | "output_type": "stream",
967 | "text": [
968 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:66: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.\n",
969 | "\n",
970 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:541: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.\n",
971 | "\n",
972 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:4432: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead.\n",
973 | "\n",
974 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:4267: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.\n",
975 | "\n",
976 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/optimizers.py:793: The name tf.train.Optimizer is deprecated. Please use tf.compat.v1.train.Optimizer instead.\n",
977 | "\n",
978 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:1033: The name tf.assign_add is deprecated. Please use tf.compat.v1.assign_add instead.\n",
979 | "\n",
980 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:1020: The name tf.assign is deprecated. Please use tf.compat.v1.assign instead.\n",
981 | "\n",
982 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:3005: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.\n",
983 | "\n",
984 | "Train on 934348 samples, validate on 311450 samples\n",
985 | "Epoch 1/20\n",
986 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:190: The name tf.get_default_session is deprecated. Please use tf.compat.v1.get_default_session instead.\n",
987 | "\n",
988 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:197: The name tf.ConfigProto is deprecated. Please use tf.compat.v1.ConfigProto instead.\n",
989 | "\n",
990 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:207: The name tf.global_variables is deprecated. Please use tf.compat.v1.global_variables instead.\n",
991 | "\n",
992 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:216: The name tf.is_variable_initialized is deprecated. Please use tf.compat.v1.is_variable_initialized instead.\n",
993 | "\n",
994 | "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:223: The name tf.variables_initializer is deprecated. Please use tf.compat.v1.variables_initializer instead.\n",
995 | "\n",
996 | "934348/934348 [==============================] - 253s 271us/step - loss: 0.0471 - acc: 0.8291 - val_loss: 0.0438 - val_acc: 0.8373\n",
997 | "Epoch 2/20\n",
998 | "934348/934348 [==============================] - 248s 265us/step - loss: 0.0436 - acc: 0.8357 - val_loss: 0.0438 - val_acc: 0.8374\n",
999 | "Epoch 3/20\n",
1000 | "934348/934348 [==============================] - 247s 265us/step - loss: 0.0432 - acc: 0.8354 - val_loss: 0.0445 - val_acc: 0.8389\n",
1001 | "Epoch 4/20\n",
1002 | "934348/934348 [==============================] - 248s 266us/step - loss: 0.0430 - acc: 0.8365 - val_loss: 0.0432 - val_acc: 0.8377\n",
1003 | "Epoch 5/20\n",
1004 | "934348/934348 [==============================] - 247s 264us/step - loss: 0.0428 - acc: 0.8367 - val_loss: 0.0437 - val_acc: 0.8315\n",
1005 | "Epoch 6/20\n",
1006 | "934348/934348 [==============================] - 250s 267us/step - loss: 0.0428 - acc: 0.8369 - val_loss: 0.0432 - val_acc: 0.8378\n",
1007 | "Epoch 7/20\n",
1008 | " 19780/934348 [..............................] - ETA: 3:33 - loss: 0.0421 - acc: 0.8395"
1009 | ],
1010 | "name": "stdout"
1011 | },
1012 | {
1013 | "output_type": "error",
1014 | "ename": "KeyboardInterrupt",
1015 | "evalue": "ignored",
1016 | "traceback": [
1017 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
1018 | "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
1019 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0mm2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcompile\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mloss\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"mean_absolute_error\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moptimizer\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"adam\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmetrics\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'accuracy'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 10\u001b[0;31m \u001b[0mm2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX_train\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my_train\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mepochs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m20\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbatch_size\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalidation_data\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX_test\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my_test\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
1020 | "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/keras/engine/training.py\u001b[0m in \u001b[0;36mfit\u001b[0;34m(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, max_queue_size, workers, use_multiprocessing, **kwargs)\u001b[0m\n\u001b[1;32m 1176\u001b[0m \u001b[0msteps_per_epoch\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msteps_per_epoch\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1177\u001b[0m \u001b[0mvalidation_steps\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mvalidation_steps\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1178\u001b[0;31m validation_freq=validation_freq)\n\u001b[0m\u001b[1;32m 1179\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1180\u001b[0m def evaluate(self,\n",
1021 | "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/keras/engine/training_arrays.py\u001b[0m in \u001b[0;36mfit_loop\u001b[0;34m(model, fit_function, fit_inputs, out_labels, batch_size, epochs, verbose, callbacks, val_function, val_inputs, shuffle, callback_metrics, initial_epoch, steps_per_epoch, validation_steps, validation_freq)\u001b[0m\n\u001b[1;32m 202\u001b[0m \u001b[0mins_batch\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mins_batch\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtoarray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 203\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 204\u001b[0;31m \u001b[0mouts\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfit_function\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mins_batch\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 205\u001b[0m \u001b[0mouts\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mto_list\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mouts\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 206\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0ml\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mo\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mout_labels\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mouts\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
1022 | "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, inputs)\u001b[0m\n\u001b[1;32m 2977\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_legacy_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2978\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2979\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2980\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2981\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mpy_any\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mis_tensor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0minputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
1023 | "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py\u001b[0m in \u001b[0;36m_call\u001b[0;34m(self, inputs)\u001b[0m\n\u001b[1;32m 2935\u001b[0m \u001b[0mfetched\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_callable_fn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0marray_vals\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrun_metadata\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun_metadata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2936\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2937\u001b[0;31m \u001b[0mfetched\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_callable_fn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0marray_vals\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2938\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mfetched\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0moutputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2939\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
1024 | "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/client/session.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1470\u001b[0m ret = tf_session.TF_SessionRunCallable(self._session._session,\n\u001b[1;32m 1471\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_handle\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1472\u001b[0;31m run_metadata_ptr)\n\u001b[0m\u001b[1;32m 1473\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mrun_metadata\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1474\u001b[0m \u001b[0mproto_data\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtf_session\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mTF_GetBuffer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrun_metadata_ptr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
1025 | "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
1026 | ]
1027 | }
1028 | ]
1029 | },
1030 | {
1031 | "cell_type": "code",
1032 | "metadata": {
1033 | "id": "frzX_kXg9i7C",
1034 | "colab_type": "code",
1035 | "colab": {}
1036 | },
1037 | "source": [
1038 | "#save to folder\n",
1039 | "m2.save(\"/content/drive/My Drive/dos_dataset/final_cnn_m2.h5\")"
1040 | ],
1041 | "execution_count": 0,
1042 | "outputs": []
1043 | },
1044 | {
1045 | "cell_type": "code",
1046 | "metadata": {
1047 | "id": "M3-DWLWPbLk4",
1048 | "colab_type": "code",
1049 | "colab": {}
1050 | },
1051 | "source": [
1052 | "y_pred = m2.predict(X_test)"
1053 | ],
1054 | "execution_count": 0,
1055 | "outputs": []
1056 | },
1057 | {
1058 | "cell_type": "code",
1059 | "metadata": {
1060 | "id": "0cNO8st5uc9G",
1061 | "colab_type": "code",
1062 | "colab": {}
1063 | },
1064 | "source": [
1065 | "a = (y_pred > 0.5)\n",
1066 | "b = (y_test > 0.5) "
1067 | ],
1068 | "execution_count": 0,
1069 | "outputs": []
1070 | },
1071 | {
1072 | "cell_type": "code",
1073 | "metadata": {
1074 | "id": "AtDc4wLdzaBi",
1075 | "colab_type": "code",
1076 | "colab": {}
1077 | },
1078 | "source": [
1079 | "b=np.argmax(y_test, axis=1)"
1080 | ],
1081 | "execution_count": 0,
1082 | "outputs": []
1083 | },
1084 | {
1085 | "cell_type": "code",
1086 | "metadata": {
1087 | "id": "ppJB_LMjzFr3",
1088 | "colab_type": "code",
1089 | "outputId": "d307ee6e-945a-4f26-b5f5-f0166a820d03",
1090 | "colab": {
1091 | "base_uri": "https://localhost:8080/",
1092 | "height": 34
1093 | }
1094 | },
1095 | "source": [
1096 | "a=np.argmax(y_pred, axis=1)\n",
1097 | "a[2]"
1098 | ],
1099 | "execution_count": 16,
1100 | "outputs": [
1101 | {
1102 | "output_type": "execute_result",
1103 | "data": {
1104 | "text/plain": [
1105 | "1"
1106 | ]
1107 | },
1108 | "metadata": {
1109 | "tags": []
1110 | },
1111 | "execution_count": 16
1112 | }
1113 | ]
1114 | },
1115 | {
1116 | "cell_type": "code",
1117 | "metadata": {
1118 | "id": "xouyY6kCbC-s",
1119 | "colab_type": "code",
1120 | "outputId": "a1a19d7b-dbce-499f-d696-a5e97fc7aa46",
1121 | "colab": {
1122 | "base_uri": "https://localhost:8080/",
1123 | "height": 564
1124 | }
1125 | },
1126 | "source": [
1127 | "from sklearn import metrics\n",
1128 | "from sklearn.metrics import accuracy_score\n",
1129 | "from sklearn.metrics import f1_score\n",
1130 | "\n",
1131 | "print('Convolution Neural Network')\n",
1132 | "\n",
1133 | "print('Accuracy: %f' % (accuracy_score(a, b)*100))\n",
1134 | "print(\"Confusion Matrix =\\n\", metrics.confusion_matrix(b, a, labels=None, \n",
1135 | " sample_weight=None))\n",
1136 | "print(\"Recall =\", metrics.recall_score(b, a, labels=None, \n",
1137 | " pos_label=1, average='weighted', \n",
1138 | " sample_weight=None))\n",
1139 | "print(\"Classification Report =\\n\", metrics.classification_report(b, a, \n",
1140 | " labels=None, \n",
1141 | " target_names=None, \n",
1142 | " sample_weight=None, \n",
1143 | " digits=2, \n",
1144 | " output_dict=False))\n",
1145 | "\n",
1146 | "print(\"F1 Score = \",f1_score(a, b, average='macro'))"
1147 | ],
1148 | "execution_count": 18,
1149 | "outputs": [
1150 | {
1151 | "output_type": "stream",
1152 | "text": [
1153 | "Convolution Neural Network\n",
1154 | "Accuracy: 83.924225\n",
1155 | "Confusion Matrix =\n",
1156 | " [[14222 58 6 11 6 18 0 0]\n",
1157 | " [ 9 48066 2 12 1588 0 85 0]\n",
1158 | " [ 10 3 49270 530 6 3 0 0]\n",
1159 | " [ 2 0 1143 48551 29 0 550 0]\n",
1160 | " [ 163 43372 0 123 3197 0 63 0]\n",
1161 | " [ 9 0 0 2 0 49651 2 0]\n",
1162 | " [ 9 9 0 1714 10 0 48425 0]\n",
1163 | " [ 49 0 0 30 4 0 438 0]]\n",
1164 | "Recall = 0.8392422539733505\n"
1165 | ],
1166 | "name": "stdout"
1167 | },
1168 | {
1169 | "output_type": "stream",
1170 | "text": [
1171 | "/usr/local/lib/python3.6/dist-packages/sklearn/metrics/_classification.py:1272: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
1172 | " _warn_prf(average, modifier, msg_start, len(result))\n"
1173 | ],
1174 | "name": "stderr"
1175 | },
1176 | {
1177 | "output_type": "stream",
1178 | "text": [
1179 | "Classification Report =\n",
1180 | " precision recall f1-score support\n",
1181 | "\n",
1182 | " 0 0.98 0.99 0.99 14321\n",
1183 | " 1 0.53 0.97 0.68 49762\n",
1184 | " 2 0.98 0.99 0.98 49822\n",
1185 | " 3 0.95 0.97 0.96 50275\n",
1186 | " 4 0.66 0.07 0.12 46918\n",
1187 | " 5 1.00 1.00 1.00 49664\n",
1188 | " 6 0.98 0.97 0.97 50167\n",
1189 | " 7 0.00 0.00 0.00 521\n",
1190 | "\n",
1191 | " accuracy 0.84 311450\n",
1192 | " macro avg 0.76 0.74 0.71 311450\n",
1193 | "weighted avg 0.86 0.84 0.80 311450\n",
1194 | "\n",
1195 | "F1 Score = 0.713088426198137\n"
1196 | ],
1197 | "name": "stdout"
1198 | }
1199 | ]
1200 | }
1201 | ]
1202 | }
--------------------------------------------------------------------------------
/DDOS_XGBoost.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "name": "DDOS_XGBoost.ipynb",
7 | "provenance": [],
8 | "include_colab_link": true
9 | },
10 | "kernelspec": {
11 | "name": "python3",
12 | "display_name": "Python 3"
13 | }
14 | },
15 | "cells": [
16 | {
17 | "cell_type": "markdown",
18 | "metadata": {
19 | "id": "view-in-github",
20 | "colab_type": "text"
21 | },
22 | "source": [
23 | "
"
24 | ]
25 | },
26 | {
27 | "cell_type": "code",
28 | "metadata": {
29 | "id": "lnz8kF7JX4kO",
30 | "colab_type": "code",
31 | "outputId": "770c4510-44fa-4bc6-9453-1fd699bb5e2f",
32 | "colab": {
33 | "base_uri": "https://localhost:8080/",
34 | "height": 122
35 | }
36 | },
37 | "source": [
38 | "from google.colab import drive\n",
39 | "drive.mount('/content/drive')"
40 | ],
41 | "execution_count": 1,
42 | "outputs": [
43 | {
44 | "output_type": "stream",
45 | "text": [
46 | "Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=947318989803-6bn6qk8qdgf4n4g3pfee6491hc0brc4i.apps.googleusercontent.com&redirect_uri=urn%3aietf%3awg%3aoauth%3a2.0%3aoob&response_type=code&scope=email%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdocs.test%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive.photos.readonly%20https%3a%2f%2fwww.googleapis.com%2fauth%2fpeopleapi.readonly\n",
47 | "\n",
48 | "Enter your authorization code:\n",
49 | "··········\n",
50 | "Mounted at /content/drive\n"
51 | ],
52 | "name": "stdout"
53 | }
54 | ]
55 | },
56 | {
57 | "cell_type": "code",
58 | "metadata": {
59 | "id": "oS-BDuLOX_vC",
60 | "colab_type": "code",
61 | "outputId": "93f21e0b-74f2-4ae4-9090-646930fc37f6",
62 | "colab": {
63 | "base_uri": "https://localhost:8080/",
64 | "height": 80
65 | }
66 | },
67 | "source": [
68 | " #%tensorflow_version 2.x\n",
69 | "from sklearn.preprocessing import LabelEncoder\n",
70 | "from keras.models import Sequential\n",
71 | "from keras.layers import Dense, Dropout, Activation, Lambda, Flatten\n",
72 | "from keras.layers import Convolution1D, Dense, Dropout, MaxPooling1D, LSTM\n",
73 | "from sklearn.model_selection import train_test_split\n",
74 | "from sklearn.preprocessing import Normalizer\n",
75 | "from keras import callbacks\n",
76 | "from keras.callbacks import CSVLogger\n",
77 | "from keras.utils import to_categorical\n",
78 | "from keras.callbacks import ModelCheckpoint, EarlyStopping, ReduceLROnPlateau, CSVLogger\n",
79 | "import numpy as np\n",
80 | "np.random.seed(0)"
81 | ],
82 | "execution_count": 2,
83 | "outputs": [
84 | {
85 | "output_type": "stream",
86 | "text": [
87 | "Using TensorFlow backend.\n"
88 | ],
89 | "name": "stderr"
90 | },
91 | {
92 | "output_type": "display_data",
93 | "data": {
94 | "text/html": [
95 | "\n",
96 | "The default version of TensorFlow in Colab will soon switch to TensorFlow 2.x.
\n",
97 | "We recommend you upgrade now \n",
98 | "or ensure your notebook will continue to use TensorFlow 1.x via the %tensorflow_version 1.x
magic:\n",
99 | "more info.
\n"
100 | ],
101 | "text/plain": [
102 | ""
103 | ]
104 | },
105 | "metadata": {
106 | "tags": []
107 | }
108 | }
109 | ]
110 | },
111 | {
112 | "cell_type": "code",
113 | "metadata": {
114 | "id": "UhGqcdZLX_z7",
115 | "colab_type": "code",
116 | "outputId": "5c5c57f9-c6b8-4957-b6de-9706ccb87521",
117 | "colab": {
118 | "base_uri": "https://localhost:8080/",
119 | "height": 275
120 | }
121 | },
122 | "source": [
123 | "#loading dataset\n",
124 | "import pandas as pd\n",
125 | "x = pd.read_csv(\"/content/drive/My Drive/dos_dataset/clean_5.csv\")\n",
126 | "y = pd.read_csv(\"/content/drive/My Drive/dos_dataset/y.csv\")\n",
127 | "y=y['Label']\n",
128 | "x=x.drop(['Label'], axis=1)\n",
129 | "\n",
130 | "#normalizing the data\n",
131 | "normalized_df=(x-x.mean())/x.std()\n",
132 | "\n",
133 | "normalized_df=normalized_df.drop(['Unnamed: 0'], axis=1)\n",
134 | "normalized_df=normalized_df.drop(['Unnamed: 0.1'], axis=1)\n",
135 | "normalized_df=normalized_df.drop(['Unnamed: 0.1.1'], axis=1)\n",
136 | "normalized_df=normalized_df.drop(['Flow Bytes/s'], axis=1)\n",
137 | "normalized_df=normalized_df.drop([' Flow Packets/s'], axis=1)\n",
138 | "\n",
139 | "y = pd.get_dummies(y,prefix=['Label'], drop_first=True)\n",
140 | "\n",
141 | "normalized_df.head()"
142 | ],
143 | "execution_count": 3,
144 | "outputs": [
145 | {
146 | "output_type": "execute_result",
147 | "data": {
148 | "text/html": [
149 | "\n",
150 | "\n",
163 | "
\n",
164 | " \n",
165 | " \n",
166 | " | \n",
167 | " Source Port | \n",
168 | " Destination IP | \n",
169 | " Destination Port | \n",
170 | " Protocol | \n",
171 | " Total Length of Fwd Packets | \n",
172 | " Fwd Packet Length Max | \n",
173 | " Fwd Packet Length Min | \n",
174 | " Fwd Packet Length Mean | \n",
175 | " Bwd Packet Length Max | \n",
176 | " Bwd Packet Length Min | \n",
177 | " Bwd Packet Length Mean | \n",
178 | " Bwd Packet Length Std | \n",
179 | " Flow IAT Mean | \n",
180 | " Flow IAT Std | \n",
181 | " Fwd IAT Mean | \n",
182 | " Fwd IAT Std | \n",
183 | " Fwd PSH Flags | \n",
184 | " Fwd Packets/s | \n",
185 | " Min Packet Length | \n",
186 | " Max Packet Length | \n",
187 | " Packet Length Mean | \n",
188 | " Packet Length Variance | \n",
189 | " RST Flag Count | \n",
190 | " ACK Flag Count | \n",
191 | " URG Flag Count | \n",
192 | " CWE Flag Count | \n",
193 | " Average Packet Size | \n",
194 | " Avg Fwd Segment Size | \n",
195 | " Avg Bwd Segment Size | \n",
196 | " Subflow Fwd Bytes | \n",
197 | " Init_Win_bytes_forward | \n",
198 | " Init_Win_bytes_backward | \n",
199 | " Idle Std | \n",
200 | " Inbound | \n",
201 | "
\n",
202 | " \n",
203 | " \n",
204 | " \n",
205 | " 0 | \n",
206 | " 1.395596 | \n",
207 | " 0.157586 | \n",
208 | " -0.607399 | \n",
209 | " -2.031188 | \n",
210 | " -0.725421 | \n",
211 | " -0.954992 | \n",
212 | " -0.935156 | \n",
213 | " -0.945029 | \n",
214 | " -0.050579 | \n",
215 | " 0.342849 | \n",
216 | " 0.015085 | \n",
217 | " -0.076871 | \n",
218 | " -0.178761 | \n",
219 | " -0.175445 | \n",
220 | " -0.178330 | \n",
221 | " -0.168507 | \n",
222 | " -0.090471 | \n",
223 | " -1.335866 | \n",
224 | " -0.935040 | \n",
225 | " -0.940755 | \n",
226 | " -0.948545 | \n",
227 | " -0.069737 | \n",
228 | " -0.090471 | \n",
229 | " 2.209740 | \n",
230 | " -0.153371 | \n",
231 | " -0.101473 | \n",
232 | " -0.933777 | \n",
233 | " -0.945029 | \n",
234 | " 0.015085 | \n",
235 | " -0.725421 | \n",
236 | " -0.054584 | \n",
237 | " -0.057299 | \n",
238 | " -0.162793 | \n",
239 | " 0.19758 | \n",
240 | "
\n",
241 | " \n",
242 | " 1 | \n",
243 | " 0.347887 | \n",
244 | " 0.157586 | \n",
245 | " -1.625958 | \n",
246 | " -2.031188 | \n",
247 | " -0.733744 | \n",
248 | " -0.954992 | \n",
249 | " -0.935156 | \n",
250 | " -0.945029 | \n",
251 | " -0.050579 | \n",
252 | " 0.342849 | \n",
253 | " 0.015085 | \n",
254 | " -0.076871 | \n",
255 | " -0.216151 | \n",
256 | " -0.222876 | \n",
257 | " -0.227006 | \n",
258 | " -0.222546 | \n",
259 | " -0.090471 | \n",
260 | " -1.324001 | \n",
261 | " -0.935040 | \n",
262 | " -0.940755 | \n",
263 | " -0.948545 | \n",
264 | " -0.069737 | \n",
265 | " -0.090471 | \n",
266 | " 2.209740 | \n",
267 | " -0.153371 | \n",
268 | " -0.101473 | \n",
269 | " -0.933085 | \n",
270 | " -0.945029 | \n",
271 | " 0.015085 | \n",
272 | " -0.733744 | \n",
273 | " 7.027636 | \n",
274 | " -0.057299 | \n",
275 | " -0.162793 | \n",
276 | " 0.19758 | \n",
277 | "
\n",
278 | " \n",
279 | " 2 | \n",
280 | " 1.196809 | \n",
281 | " 0.157586 | \n",
282 | " -0.560525 | \n",
283 | " -2.031188 | \n",
284 | " -0.725421 | \n",
285 | " -0.954992 | \n",
286 | " -0.935156 | \n",
287 | " -0.945029 | \n",
288 | " -0.050579 | \n",
289 | " 0.342849 | \n",
290 | " 0.015085 | \n",
291 | " -0.076871 | \n",
292 | " -0.182709 | \n",
293 | " -0.180450 | \n",
294 | " -0.183461 | \n",
295 | " -0.174204 | \n",
296 | " -0.090471 | \n",
297 | " -1.335864 | \n",
298 | " -0.935040 | \n",
299 | " -0.940755 | \n",
300 | " -0.948545 | \n",
301 | " -0.069737 | \n",
302 | " -0.090471 | \n",
303 | " 2.209740 | \n",
304 | " -0.153371 | \n",
305 | " -0.101473 | \n",
306 | " -0.933777 | \n",
307 | " -0.945029 | \n",
308 | " 0.015085 | \n",
309 | " -0.725421 | \n",
310 | " -0.054584 | \n",
311 | " -0.057299 | \n",
312 | " -0.162793 | \n",
313 | " 0.19758 | \n",
314 | "
\n",
315 | " \n",
316 | " 3 | \n",
317 | " 0.892029 | \n",
318 | " 0.157586 | \n",
319 | " -1.562081 | \n",
320 | " -2.031188 | \n",
321 | " -0.725421 | \n",
322 | " -0.954992 | \n",
323 | " -0.935156 | \n",
324 | " -0.945029 | \n",
325 | " -0.050579 | \n",
326 | " 0.342849 | \n",
327 | " 0.015085 | \n",
328 | " -0.076871 | \n",
329 | " -0.186161 | \n",
330 | " -0.184840 | \n",
331 | " -0.187948 | \n",
332 | " -0.179186 | \n",
333 | " -0.090471 | \n",
334 | " -1.335861 | \n",
335 | " -0.935040 | \n",
336 | " -0.940755 | \n",
337 | " -0.948545 | \n",
338 | " -0.069737 | \n",
339 | " -0.090471 | \n",
340 | " 2.209740 | \n",
341 | " -0.153371 | \n",
342 | " -0.101473 | \n",
343 | " -0.933777 | \n",
344 | " -0.945029 | \n",
345 | " 0.015085 | \n",
346 | " -0.725421 | \n",
347 | " -0.054584 | \n",
348 | " -0.057299 | \n",
349 | " -0.162793 | \n",
350 | " 0.19758 | \n",
351 | "
\n",
352 | " \n",
353 | " 4 | \n",
354 | " -0.914218 | \n",
355 | " 0.157586 | \n",
356 | " 0.169285 | \n",
357 | " 0.489985 | \n",
358 | " -0.424394 | \n",
359 | " -0.494002 | \n",
360 | " -0.472024 | \n",
361 | " -0.480570 | \n",
362 | " -0.085259 | \n",
363 | " -0.138378 | \n",
364 | " -0.095478 | \n",
365 | " -0.076871 | \n",
366 | " -0.216208 | \n",
367 | " -0.222934 | \n",
368 | " -0.227005 | \n",
369 | " -0.222546 | \n",
370 | " -0.090471 | \n",
371 | " -0.610670 | \n",
372 | " -0.471885 | \n",
373 | " -0.494875 | \n",
374 | " -0.483551 | \n",
375 | " -0.069737 | \n",
376 | " -0.090471 | \n",
377 | " -0.452542 | \n",
378 | " -0.153371 | \n",
379 | " -0.101473 | \n",
380 | " -0.467788 | \n",
381 | " -0.480570 | \n",
382 | " -0.095478 | \n",
383 | " -0.424394 | \n",
384 | " -0.362285 | \n",
385 | " -0.057771 | \n",
386 | " -0.162793 | \n",
387 | " 0.19758 | \n",
388 | "
\n",
389 | " \n",
390 | "
\n",
391 | "
"
392 | ],
393 | "text/plain": [
394 | " Source Port Destination IP ... Idle Std Inbound\n",
395 | "0 1.395596 0.157586 ... -0.162793 0.19758\n",
396 | "1 0.347887 0.157586 ... -0.162793 0.19758\n",
397 | "2 1.196809 0.157586 ... -0.162793 0.19758\n",
398 | "3 0.892029 0.157586 ... -0.162793 0.19758\n",
399 | "4 -0.914218 0.157586 ... -0.162793 0.19758\n",
400 | "\n",
401 | "[5 rows x 34 columns]"
402 | ]
403 | },
404 | "metadata": {
405 | "tags": []
406 | },
407 | "execution_count": 3
408 | }
409 | ]
410 | },
411 | {
412 | "cell_type": "code",
413 | "metadata": {
414 | "id": "dJTE1lD8YhDQ",
415 | "colab_type": "code",
416 | "outputId": "7b8f40e8-f9b5-4408-9249-c420ae9d740a",
417 | "colab": {
418 | "base_uri": "https://localhost:8080/",
419 | "height": 119
420 | }
421 | },
422 | "source": [
423 | "y = pd.read_csv(\"/content/drive/My Drive/dos_dataset/y.csv\")\n",
424 | "y=y['Label']\n",
425 | "y.head()"
426 | ],
427 | "execution_count": 4,
428 | "outputs": [
429 | {
430 | "output_type": "execute_result",
431 | "data": {
432 | "text/plain": [
433 | "0 2\n",
434 | "1 2\n",
435 | "2 2\n",
436 | "3 2\n",
437 | "4 2\n",
438 | "Name: Label, dtype: int64"
439 | ]
440 | },
441 | "metadata": {
442 | "tags": []
443 | },
444 | "execution_count": 4
445 | }
446 | ]
447 | },
448 | {
449 | "cell_type": "code",
450 | "metadata": {
451 | "id": "XDBQEpsTX_3b",
452 | "colab_type": "code",
453 | "outputId": "0ee5cbde-c3be-4a0e-b3e7-8952e21b6d02",
454 | "colab": {
455 | "base_uri": "https://localhost:8080/",
456 | "height": 34
457 | }
458 | },
459 | "source": [
460 | "from sklearn.model_selection import train_test_split\n",
461 | "X_train, X_test, y_train, y_test = train_test_split(normalized_df, y, test_size=0.3, random_state=0)\n",
462 | "y_train = np.array(y_train)\n",
463 | "\n",
464 | "y_train = np.array(y_train)\n",
465 | "y_test = np.array(y_test)\n",
466 | "X_train = np.array(X_train)\n",
467 | "X_test = np.array(X_test)\n",
468 | "X_train = np.reshape(X_train, (X_train.shape[0],X_train.shape[1]))\n",
469 | "X_test = np.reshape(X_test, (X_test.shape[0],X_test.shape[1]))\n",
470 | "\n",
471 | "print('xtrain={}, ytrain={}, xtest={}, ytest={}'.format(X_train.shape,y_train.shape,X_test.shape,y_test.shape))"
472 | ],
473 | "execution_count": 5,
474 | "outputs": [
475 | {
476 | "output_type": "stream",
477 | "text": [
478 | "xtrain=(872058, 34), ytrain=(872058,), xtest=(373740, 34), ytest=(373740,)\n"
479 | ],
480 | "name": "stdout"
481 | }
482 | ]
483 | },
484 | {
485 | "cell_type": "markdown",
486 | "metadata": {
487 | "id": "a7ZM193PagA5",
488 | "colab_type": "text"
489 | },
490 | "source": [
491 | "**XGBoost**\n",
492 | "\n",
493 | "> with metrics\n",
494 | "\n"
495 | ]
496 | },
497 | {
498 | "cell_type": "code",
499 | "metadata": {
500 | "id": "phVeKBGYamO-",
501 | "colab_type": "code",
502 | "outputId": "22c659dd-7f91-4b0c-be67-5c9dfe1897a3",
503 | "colab": {
504 | "base_uri": "https://localhost:8080/",
505 | "height": 68
506 | }
507 | },
508 | "source": [
509 | "!pip install xgboost"
510 | ],
511 | "execution_count": 6,
512 | "outputs": [
513 | {
514 | "output_type": "stream",
515 | "text": [
516 | "Requirement already satisfied: xgboost in /usr/local/lib/python3.6/dist-packages (0.90)\n",
517 | "Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from xgboost) (1.17.5)\n",
518 | "Requirement already satisfied: scipy in /usr/local/lib/python3.6/dist-packages (from xgboost) (1.4.1)\n"
519 | ],
520 | "name": "stdout"
521 | }
522 | ]
523 | },
524 | {
525 | "cell_type": "code",
526 | "metadata": {
527 | "id": "9ZE9XYK6AzKO",
528 | "colab_type": "code",
529 | "colab": {}
530 | },
531 | "source": [
532 | "from xgboost import XGBClassifier\n",
533 | "model = XGBClassifier()\n",
534 | "model.fit(X_train, y_train)\n",
535 | "\n",
536 | "import pickle\n",
537 | "pickle.dump(model, open(\"/content/drive/My Drive/dos_dataset/final_xgb.pickle.dat\", \"wb\"))"
538 | ],
539 | "execution_count": 0,
540 | "outputs": []
541 | },
542 | {
543 | "cell_type": "code",
544 | "metadata": {
545 | "id": "tVRI3zWqGJD1",
546 | "colab_type": "code",
547 | "colab": {}
548 | },
549 | "source": [
550 | "y_pred=model.predict(X_test)"
551 | ],
552 | "execution_count": 0,
553 | "outputs": []
554 | },
555 | {
556 | "cell_type": "code",
557 | "metadata": {
558 | "id": "8RrZdXa8Fz2C",
559 | "colab_type": "code",
560 | "outputId": "3aef8cd0-6990-488b-8fac-bcfd93ddb686",
561 | "colab": {
562 | "base_uri": "https://localhost:8080/",
563 | "height": 34
564 | }
565 | },
566 | "source": [
567 | "y_train.shape"
568 | ],
569 | "execution_count": 10,
570 | "outputs": [
571 | {
572 | "output_type": "execute_result",
573 | "data": {
574 | "text/plain": [
575 | "(872058,)"
576 | ]
577 | },
578 | "metadata": {
579 | "tags": []
580 | },
581 | "execution_count": 10
582 | }
583 | ]
584 | },
585 | {
586 | "cell_type": "code",
587 | "metadata": {
588 | "id": "854hNxDbao_c",
589 | "colab_type": "code",
590 | "outputId": "9da28dd8-ce69-4883-df42-ab3c4d3c9692",
591 | "colab": {
592 | "base_uri": "https://localhost:8080/",
593 | "height": 510
594 | }
595 | },
596 | "source": [
597 | "from sklearn import metrics\n",
598 | "from sklearn.metrics import f1_score\n",
599 | "print('XGBoost Classifier')\n",
600 | "\n",
601 | "print('Accuracy = ', metrics.accuracy_score(y_test, y_pred)*100)\n",
602 | "print(\"Confusion Matrix =\\n\", metrics.confusion_matrix(y_test, y_pred, labels=None, \n",
603 | " sample_weight=None))\n",
604 | "print(\"Recall =\", metrics.recall_score(y_test, y_pred, labels=None, \n",
605 | " pos_label=1, average='weighted', \n",
606 | " sample_weight=None))\n",
607 | "print(\"Classification Report =\\n\", metrics.classification_report(y_test, y_pred, \n",
608 | " labels=None, \n",
609 | " target_names=None, \n",
610 | " sample_weight=None, \n",
611 | " digits=2, \n",
612 | " output_dict=False))\n",
613 | "\n",
614 | "print(\"F1 Score = \",f1_score(y_test, y_pred, average='macro'))"
615 | ],
616 | "execution_count": 15,
617 | "outputs": [
618 | {
619 | "output_type": "stream",
620 | "text": [
621 | "XGBoost Classifier\n",
622 | "Accuracy = 89.29871033338685\n",
623 | "Confusion Matrix =\n",
624 | " [[17136 0 0 0 0 0 0 0]\n",
625 | " [ 1 56298 6 0 3467 0 0 1]\n",
626 | " [ 0 0 59645 42 17 5 0 0]\n",
627 | " [ 2 1 24 60168 22 0 199 0]\n",
628 | " [ 11 34241 8 68 21904 1 0 16]\n",
629 | " [ 1 0 0 2 1 59765 2 0]\n",
630 | " [ 1 0 0 1621 11 0 58430 19]\n",
631 | " [ 1 0 0 20 55 0 129 399]]\n",
632 | "Recall = 0.8929871033338684\n",
633 | "Classification Report =\n",
634 | " precision recall f1-score support\n",
635 | "\n",
636 | " 0 1.00 1.00 1.00 17136\n",
637 | " 1 0.62 0.94 0.75 59773\n",
638 | " 2 1.00 1.00 1.00 59709\n",
639 | " 3 0.97 1.00 0.98 60416\n",
640 | " 4 0.86 0.39 0.54 56249\n",
641 | " 5 1.00 1.00 1.00 59771\n",
642 | " 6 0.99 0.97 0.98 60082\n",
643 | " 7 0.92 0.66 0.77 604\n",
644 | "\n",
645 | " accuracy 0.89 373740\n",
646 | " macro avg 0.92 0.87 0.88 373740\n",
647 | "weighted avg 0.91 0.89 0.88 373740\n",
648 | "\n",
649 | "F1 Score = 0.8773342009066785\n"
650 | ],
651 | "name": "stdout"
652 | }
653 | ]
654 | }
655 | ]
656 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Detection-and-Classification-of-Distributed-DDoS-Attacks
2 | This repository contains ipython notebooks which were used for detection and classification of Distributed Denial of Service (DDoS) attacks. The dataset used in this study is called 'DDoS Evaluation Dataset (CICDDoS2019)' which was obtained from Canadian Institute for Cybersecurity. The dataset contains thousands of synthesized DDoS attack scenarios which are based on actual attacks attacks that were reported in 2019. The results from this study have been used in a research work hence give a citation if you are using these notebooks/results from this repository.
3 |
4 | Link to the paper: https://link.springer.com/chapter/10.1007%2F978-981-15-9647-6_78
5 |
--------------------------------------------------------------------------------
/where_to_find_the_preprocessed_dataset.md:
--------------------------------------------------------------------------------
1 | Orinal dataset can be found on Canadian Institute for Cybersecurity website:
2 | https://www.unb.ca/cic/datasets/ddos-2019.html (the download link at the end of the page is dead)
3 |
4 | ~~The datasets used in the pre-processing IPython Notebook (DDOS_dataProcessing.ipynb) can be downloaded from the following link:~~
5 | ~~https://drive.google.com/drive/folders/1BBCAAL7I4xKwRQJ8Joziqi28PccBQGOi?usp=sharing~~
6 | ________________________________________________________________________________________
7 | Update (Jan, 2022):
8 |
9 | The datasets are in two parts and can be found here:
10 | ~~https://drive.google.com/drive/folders/1BBCAAL7I4xKwRQJ8Joziqi28PccBQGOi?usp=sharing~~
11 | ~~https://drive.google.com/drive/folders/1-0nrb9K4mwgpeLqRr7jrsTYVockLQm2J?usp=sharing~~
12 | There has been some changes in the way this data was stored during the project and necessary changes will be required in the ipnb files to read the datasets correctly. Please note that this project is no longer maintained so I won't be updating the ipython notebooks
13 |
14 | ________________________________________________________________________________________
15 | Update (Jan, 2024):
16 |
17 | Unfortunately the dataset download link on the Canadian Institute for Cybersecurity website is down (at the time of writing) and I've lost access to my uni google drive where I had uploaded the two-part dataset, so those URLs are also no longer working.
18 |
19 | Not all is lost though as the original dataset is available on Kaggle (here's the download link: https://www.kaggle.com/datasets/rodrigorosasilva/cic-ddos2019-30gb-full-dataset-csv-files). You can download the dataset from there and run it through the `DDOS_dataProcessing.ipynb` file and store the resulting "cleaned" files. You'll need these processed data files to run the rest of the ipython notebooks.
20 |
21 | As previously stated, this repo is not actively maintained but feel free to raise an issue if you have any questions and I will try to get back to you with an answer. Thanks :)
22 |
--------------------------------------------------------------------------------