|
import os |
|
import pandas as pd |
|
import datasets |
|
|
|
_CITATION = """\ |
|
@InProceedings{YourReferenceHere, |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
Description of your dataset. |
|
""" |
|
|
|
_HOMEPAGE = "https://dataset-homepage/" |
|
_LICENSE = "Dataset License" |
|
|
|
_URLS = { |
|
"Network-Flows": "Network-Flows/CICIDS_Flow.csv", |
|
"Packet-Fields": "Packet-Fields/Packet_Fields_File_10.csv", |
|
"Packet-Bytes": "Packet-Bytes/Packet_Bytes_File_10.csv", |
|
"Payload-Bytes": "Payload-Bytes/Payload_Bytes_File_10.csv", |
|
} |
|
|
|
|
|
class CICIDS2017(datasets.GeneratorBasedBuilder): |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig(name=config_name, description=f"This part of my dataset covers {config_name}") |
|
for config_name in _URLS.keys() |
|
] |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features({ |
|
|
|
"flow_id": datasets.Value("int64"), |
|
"attack_label": datasets.Value("string"), |
|
|
|
}), |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
url = f"https://huggingface.co/datasets/rdpahalavan/CIC-IDS2017/blob/main/{_URLS[self.config.name]}" |
|
downloaded_file = dl_manager.download(url) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={"filepath": downloaded_file}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepath): |
|
df = pd.read_csv(filepath) |
|
for id_, row in df.iterrows(): |
|
yield id_, { |
|
'flow_id': row['flow_id'], |
|
'attack_label': row['attack_label'] |
|
} |