Loading

Network Intrusion Detection System, SNS'2021

Baseline For SNS Assignment

A getting started code for SNS Assignment.

ashivani

Getting Started Code for SNS Assignment on AIcrowd

Author : Ayush

Download Necessary Packages 📚

In [1]:
!pip install aicrowd-cli
Collecting aicrowd-cli
  Downloading https://files.pythonhosted.org/packages/29/18/2dcc043573e489f6134e4a76644f640874d3fa4d8f3e0593bf54a7c8b53a/aicrowd_cli-0.1.2-py3-none-any.whl (42kB)
     |████████████████████████████████| 51kB 2.2MB/s 
Collecting requests-toolbelt<1,>=0.9.1
  Downloading https://files.pythonhosted.org/packages/60/ef/7681134338fc097acef8d9b2f8abe0458e4d87559c689a8c306d0957ece5/requests_toolbelt-0.9.1-py2.py3-none-any.whl (54kB)
     |████████████████████████████████| 61kB 4.5MB/s 
Collecting gitpython<4,>=3.1.12
  Downloading https://files.pythonhosted.org/packages/a6/99/98019716955ba243657daedd1de8f3a88ca1f5b75057c38e959db22fb87b/GitPython-3.1.14-py3-none-any.whl (159kB)
     |████████████████████████████████| 163kB 17.8MB/s 
Requirement already satisfied: toml<1,>=0.10.2 in /usr/local/lib/python3.7/dist-packages (from aicrowd-cli) (0.10.2)
Collecting tqdm<5,>=4.56.0
  Downloading https://files.pythonhosted.org/packages/72/8a/34efae5cf9924328a8f34eeb2fdaae14c011462d9f0e3fcded48e1266d1c/tqdm-4.60.0-py2.py3-none-any.whl (75kB)
     |████████████████████████████████| 81kB 6.8MB/s 
Collecting rich<11,>=10.0.0
  Downloading https://files.pythonhosted.org/packages/1a/da/2a1f064dc620ab47f3f826ae085384084b71ea05c8c21d67f1dfc29189ab/rich-10.1.0-py3-none-any.whl (201kB)
     |████████████████████████████████| 204kB 21.7MB/s 
Requirement already satisfied: click<8,>=7.1.2 in /usr/local/lib/python3.7/dist-packages (from aicrowd-cli) (7.1.2)
Collecting requests<3,>=2.25.1
  Downloading https://files.pythonhosted.org/packages/29/c1/24814557f1d22c56d50280771a17307e6bf87b70727d975fd6b2ce6b014a/requests-2.25.1-py2.py3-none-any.whl (61kB)
     |████████████████████████████████| 61kB 5.9MB/s 
Collecting gitdb<5,>=4.0.1
  Downloading https://files.pythonhosted.org/packages/ea/e8/f414d1a4f0bbc668ed441f74f44c116d9816833a48bf81d22b697090dba8/gitdb-4.0.7-py3-none-any.whl (63kB)
     |████████████████████████████████| 71kB 5.5MB/s 
Requirement already satisfied: pygments<3.0.0,>=2.6.0 in /usr/local/lib/python3.7/dist-packages (from rich<11,>=10.0.0->aicrowd-cli) (2.6.1)
Collecting colorama<0.5.0,>=0.4.0
  Downloading https://files.pythonhosted.org/packages/44/98/5b86278fbbf250d239ae0ecb724f8572af1c91f4a11edf4d36a206189440/colorama-0.4.4-py2.py3-none-any.whl
Collecting commonmark<0.10.0,>=0.9.0
  Downloading https://files.pythonhosted.org/packages/b1/92/dfd892312d822f36c55366118b95d914e5f16de11044a27cf10a7d71bbbf/commonmark-0.9.1-py2.py3-none-any.whl (51kB)
     |████████████████████████████████| 51kB 5.4MB/s 
Requirement already satisfied: typing-extensions<4.0.0,>=3.7.4 in /usr/local/lib/python3.7/dist-packages (from rich<11,>=10.0.0->aicrowd-cli) (3.7.4.3)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests<3,>=2.25.1->aicrowd-cli) (2020.12.5)
Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests<3,>=2.25.1->aicrowd-cli) (2.10)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests<3,>=2.25.1->aicrowd-cli) (1.24.3)
Requirement already satisfied: chardet<5,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests<3,>=2.25.1->aicrowd-cli) (3.0.4)
Collecting smmap<5,>=3.0.1
  Downloading https://files.pythonhosted.org/packages/68/ee/d540eb5e5996eb81c26ceffac6ee49041d473bc5125f2aa995cf51ec1cf1/smmap-4.0.0-py2.py3-none-any.whl
ERROR: google-colab 1.0.0 has requirement requests~=2.23.0, but you'll have requests 2.25.1 which is incompatible.
ERROR: datascience 0.10.6 has requirement folium==0.2.1, but you'll have folium 0.8.3 which is incompatible.
Installing collected packages: requests, requests-toolbelt, smmap, gitdb, gitpython, tqdm, colorama, commonmark, rich, aicrowd-cli
  Found existing installation: requests 2.23.0
    Uninstalling requests-2.23.0:
      Successfully uninstalled requests-2.23.0
  Found existing installation: tqdm 4.41.1
    Uninstalling tqdm-4.41.1:
      Successfully uninstalled tqdm-4.41.1
Successfully installed aicrowd-cli-0.1.2 colorama-0.4.4 commonmark-0.9.1 gitdb-4.0.7 gitpython-3.1.14 requests-2.25.1 requests-toolbelt-0.9.1 rich-10.1.0 smmap-4.0.0 tqdm-4.60.0

Download Data

The first step is to download out train test data. We will be training a model on the train data and make predictions on test data. We submit our predictions.

In [2]:
API_KEY = "" #Please enter your API Key from [https://www.aicrowd.com/participants/me]
!aicrowd login --api-key $API_KEY
API Key valid
Saved API Key successfully!
In [3]:
!aicrowd dataset download --challenge network-intrusion-detection-system-sns-2021
a28b9410-fb88-4f23-b54e-b8d5447f5659_sample_submission.csv: 100% 4.56M/4.56M [00:02<00:00, 2.20MB/s]
bc3696c5-696b-4c32-886a-22bbf327ab48_test.csv: 100% 34.1M/34.1M [00:04<00:00, 7.67MB/s]
0d937a6a-9605-41c4-947d-ed638f3d8ba3_full.csv: 100% 743M/743M [01:04<00:00, 11.5MB/s]
In [4]:
!rm -rf data
!mkdir data

!mv 0d937a6a-9605-41c4-947d-ed638f3d8ba3_full.csv data/full.csv
!mv bc3696c5-696b-4c32-886a-22bbf327ab48_test.csv data/test.csv
!mv a28b9410-fb88-4f23-b54e-b8d5447f5659_sample_submission.csv data/sample_submission.csv

Import packages

In [6]:
import sklearn
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
import os
import cv2
import numpy as np
import pandas as pd
In [18]:
train = pd.read_csv('data/full.csv',header=None)

Visualize the data 👀

In [19]:
train.head()
Out[19]:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
0 0 tcp http SF 215 45076 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0 0 0.0 0.0 0.00 0.0 0.0 0.0 0.0 0.0 normal.
1 0 tcp http SF 162 4528 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 2 2 0.0 0.0 0.0 0.0 1.0 0.0 0.0 1 1 1.0 0.0 1.00 0.0 0.0 0.0 0.0 0.0 normal.
2 0 tcp http SF 236 1228 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0.0 0.0 0.0 0.0 1.0 0.0 0.0 2 2 1.0 0.0 0.50 0.0 0.0 0.0 0.0 0.0 normal.
3 0 tcp http SF 233 2032 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 2 2 0.0 0.0 0.0 0.0 1.0 0.0 0.0 3 3 1.0 0.0 0.33 0.0 0.0 0.0 0.0 0.0 normal.
4 0 tcp http SF 239 486 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 3 3 0.0 0.0 0.0 0.0 1.0 0.0 0.0 4 4 1.0 0.0 0.25 0.0 0.0 0.0 0.0 0.0 normal.

Creating predictions

This is just a random prediction.

In [8]:
submission = pd.read_csv('data/sample_submission.csv')
In [9]:
submission
Out[9]:
index target
0 0 apache2.
1 1 apache2.
2 2 apache2.
3 3 apache2.
4 4 apache2.
... ... ...
311024 311024 xterm.
311025 311025 xterm.
311026 311026 xterm.
311027 311027 xterm.
311028 311028 xterm.

311029 rows × 2 columns

In [13]:
submission.to_csv('submission.csv',index=False)

Making Direct Submission thought Aicrowd CLI

In [16]:
!aicrowd submission create -c network-intrusion-detection-system-sns-2021 -f submission.csv
submission.csv ━━━━━━━━━━━━━━━━━━━━━━━━ 100.0%4.6/4.6 MB1.6 MB/s0:00:00
                                                     ╭─────────────────────────╮                                                     
                                                     │ Successfully submitted! │                                                     
                                                     ╰─────────────────────────╯                                                     
                                                           Important links                                                           
┌──────────────────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│  This submission │ https://www.aicrowd.com/challenges/network-intrusion-detection-system-sns-2021/submissions/128403              │
│                  │                                                                                                                │
│  All submissions │ https://www.aicrowd.com/challenges/network-intrusion-detection-system-sns-2021/submissions?my_submissions=true │
│                  │                                                                                                                │
│      Leaderboard │ https://www.aicrowd.com/challenges/network-intrusion-detection-system-sns-2021/leaderboards                    │
│                  │                                                                                                                │
│ Discussion forum │ https://discourse.aicrowd.com/c/network-intrusion-detection-system-sns-2021                                    │
│                  │                                                                                                                │
│   Challenge page │ https://www.aicrowd.com/challenges/network-intrusion-detection-system-sns-2021                                 │
└──────────────────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
{'submission_id': 128403, 'created_at': '2021-04-06T07:51:20.647Z'}
In [ ]:


Comments

You must login before you can post a comment.

Execute