CIC-IDS2017 / CIC-IDS2017.py
rdpahalavan's picture
Update CIC-IDS2017.py
2eff270
raw
history blame
1.96 kB
import os
import csv
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({
# TODO: Adjust features according to your dataset
"flow_id": datasets.Value("int64"),
"attack_label": datasets.Value("string"),
# More columns...
}),
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):
with open(filepath, encoding="utf-8") as csv_file:
csv_reader = csv.DictReader(csv_file)
for id_, row in enumerate(csv_reader):
yield id_, {
'flow_id': row['flow_id'],
'attack_label': row['attack_label']
}