Datasets:
Upload 3 files
Browse files- .gitattributes +1 -0
- README.md +20 -0
- kddcup.data +3 -0
- kddcup.py +151 -0
.gitattributes
CHANGED
|
@@ -52,3 +52,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 52 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 53 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
| 54 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 52 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 53 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
| 54 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
| 55 |
+
kddcup.data filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
tags:
|
| 5 |
+
- kddcup
|
| 6 |
+
- tabular_classification
|
| 7 |
+
- binary_classification
|
| 8 |
+
pretty_name: Kddcup
|
| 9 |
+
task_categories: # Full list at https://github.com/huggingface/hub-docs/blob/main/js/src/lib/interfaces/Types.ts
|
| 10 |
+
- tabular-classification
|
| 11 |
+
configs:
|
| 12 |
+
- kddcup
|
| 13 |
+
---
|
| 14 |
+
# Kddcup
|
| 15 |
+
The Kddcup dataset.
|
| 16 |
+
|
| 17 |
+
# Configurations and tasks
|
| 18 |
+
| **Configuration** | **Task** |
|
| 19 |
+
|-----------------------|---------------------------|
|
| 20 |
+
| kddcup | Multiclass classification.|
|
kddcup.data
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3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
|
| 2 |
+
|
| 3 |
+
from typing import List
|
| 4 |
+
from functools import partial
|
| 5 |
+
|
| 6 |
+
import datasets
|
| 7 |
+
|
| 8 |
+
import pandas
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
VERSION = datasets.Version("1.0.0")
|
| 12 |
+
|
| 13 |
+
_ENCODING_DICS = {
|
| 14 |
+
"class": {value: i
|
| 15 |
+
for value, i in enumerate("normal.",
|
| 16 |
+
"buffer_overflow.",
|
| 17 |
+
"loadmodule.",
|
| 18 |
+
"perl.",
|
| 19 |
+
"neptune.",
|
| 20 |
+
"smurf.",
|
| 21 |
+
"guess_passwd.",
|
| 22 |
+
"pod.",
|
| 23 |
+
"teardrop.",
|
| 24 |
+
"portsweep.",
|
| 25 |
+
"ipsweep.",
|
| 26 |
+
"land.",
|
| 27 |
+
"ftp_write.",
|
| 28 |
+
"back.",
|
| 29 |
+
"imap.",
|
| 30 |
+
"satan.",
|
| 31 |
+
"phf.",
|
| 32 |
+
"nmap.",
|
| 33 |
+
"multihop.",
|
| 34 |
+
"warezmaster.",
|
| 35 |
+
"warezclient.",
|
| 36 |
+
"spy.",
|
| 37 |
+
"rootkit.")
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
DESCRIPTION = "Kddcup dataset."
|
| 42 |
+
_HOMEPAGE = ""
|
| 43 |
+
_URLS = ("")
|
| 44 |
+
_CITATION = """"""
|
| 45 |
+
|
| 46 |
+
# Dataset info
|
| 47 |
+
urls_per_split = {
|
| 48 |
+
"train": "https://huggingface.co/datasets/mstz/kddcup/resolve/main/kddcup.data"
|
| 49 |
+
}
|
| 50 |
+
features_types_per_config = {
|
| 51 |
+
"kddcup": {
|
| 52 |
+
"duration": datasets.Value("float"),
|
| 53 |
+
"protocol_type": datasets.Value("string"),
|
| 54 |
+
"service": datasets.Value("string"),
|
| 55 |
+
"flag": datasets.Value("string"),
|
| 56 |
+
"src_bytes": datasets.Value("integer"),
|
| 57 |
+
"dst_bytes": datasets.Value("integer"),
|
| 58 |
+
"land": datasets.Value("integer"),
|
| 59 |
+
"wrong_fragment": datasets.Value("integer"),
|
| 60 |
+
"urgent": datasets.Value("integer"),
|
| 61 |
+
"hot": datasets.Value("integer"),
|
| 62 |
+
"num_failed_logins": datasets.Value("integer"),
|
| 63 |
+
"logged_in": datasets.Value("integer"),
|
| 64 |
+
"num_compromised": datasets.Value("integer"),
|
| 65 |
+
"root_shell": datasets.Value("integer"),
|
| 66 |
+
"su_attempted": datasets.Value("integer"),
|
| 67 |
+
"num_root": datasets.Value("integer"),
|
| 68 |
+
"num_file_creations": datasets.Value("integer"),
|
| 69 |
+
"num_shells": datasets.Value("integer"),
|
| 70 |
+
"num_access_files": datasets.Value("integer"),
|
| 71 |
+
"num_outbound_cmds": datasets.Value("integer"),
|
| 72 |
+
"is_host_login": datasets.Value("integer"),
|
| 73 |
+
"is_guest_login": datasets.Value("integer"),
|
| 74 |
+
"count": datasets.Value("integer"),
|
| 75 |
+
"srv_count": datasets.Value("integer"),
|
| 76 |
+
"serror_rate": datasets.Value("float"),
|
| 77 |
+
"srv_serror_rate": datasets.Value("float"),
|
| 78 |
+
"rerror_rate": datasets.Value("float"),
|
| 79 |
+
"srv_rerror_rate": datasets.Value("float"),
|
| 80 |
+
"same_srv_rate": datasets.Value("float"),
|
| 81 |
+
"diff_srv_rate": datasets.Value("float"),
|
| 82 |
+
"srv_diff_host_rate": datasets.Value("float"),
|
| 83 |
+
"dst_host_count": datasets.Value("integer"),
|
| 84 |
+
"dst_host_srv_count": datasets.Value("integer"),
|
| 85 |
+
"dst_host_same_srv_rate": datasets.Value("float"),
|
| 86 |
+
"dst_host_diff_srv_rate": datasets.Value("float"),
|
| 87 |
+
"dst_host_same_src_port_rate": datasets.Value("float"),
|
| 88 |
+
"dst_host_srv_diff_host_rate": datasets.Value("float"),
|
| 89 |
+
"dst_host_serror_rate": datasets.Value("float"),
|
| 90 |
+
"dst_host_srv_serror_rate": datasets.Value("float"),
|
| 91 |
+
"dst_host_rerror_rate": datasets.Value("float"),
|
| 92 |
+
"dst_host_srv_rerror_rate": datasets.Value("float"),
|
| 93 |
+
"class": datasets.ClassLabel(num_classes=23,
|
| 94 |
+
names=("normal.", "buffer_overflow.", "loadmodule.", "perl.", "neptune.",
|
| 95 |
+
"smurf.", "guess_passwd.", "pod.", "teardrop.", "portsweep.",
|
| 96 |
+
"ipsweep.", "land.", "ftp_write.", "back.", "imap.", "satan.",
|
| 97 |
+
"phf.", "nmap.", "multihop.", "warezmaster.", "warezclient.",
|
| 98 |
+
"spy.", "rootkit.")),
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
class KddcupConfig(datasets.BuilderConfig):
|
| 105 |
+
def __init__(self, **kwargs):
|
| 106 |
+
super(KddcupConfig, self).__init__(version=VERSION, **kwargs)
|
| 107 |
+
self.features = features_per_config[kwargs["name"]]
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
class Kddcup(datasets.GeneratorBasedBuilder):
|
| 111 |
+
# dataset versions
|
| 112 |
+
DEFAULT_CONFIG = "kddcup"
|
| 113 |
+
BUILDER_CONFIGS = [
|
| 114 |
+
KddcupConfig(name="kddcup", description="Kddcup for multiclass classification.")
|
| 115 |
+
]
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def _info(self):
|
| 119 |
+
info = datasets.DatasetInfo(description=DESCRIPTION, citation=_CITATION, homepage=_HOMEPAGE,
|
| 120 |
+
features=features_per_config[self.config.name])
|
| 121 |
+
|
| 122 |
+
return info
|
| 123 |
+
|
| 124 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
| 125 |
+
downloads = dl_manager.download_and_extract(urls_per_split)
|
| 126 |
+
|
| 127 |
+
return [
|
| 128 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloads["train"]}),
|
| 129 |
+
]
|
| 130 |
+
|
| 131 |
+
def _generate_examples(self, filepath: str):
|
| 132 |
+
data = pandas.read_csv(filepath, header=None)
|
| 133 |
+
data = self.preprocess(data)
|
| 134 |
+
|
| 135 |
+
for row_id, row in data.iterrows():
|
| 136 |
+
data_row = dict(row)
|
| 137 |
+
|
| 138 |
+
yield row_id, data_row
|
| 139 |
+
|
| 140 |
+
def preprocess(self, data: pandas.DataFrame) -> pandas.DataFrame:
|
| 141 |
+
data.columns = [f"feature_{i}" for i in range(5000)] + ["class"]
|
| 142 |
+
for feature in _ENCODING_DICS:
|
| 143 |
+
encoding_function = partial(self.encode, feature)
|
| 144 |
+
data.loc[:, feature] = data[feature].apply(encoding_function)
|
| 145 |
+
|
| 146 |
+
return data[list(features_types_per_config[self.config.name].keys())]
|
| 147 |
+
|
| 148 |
+
def encode(self, feature, value):
|
| 149 |
+
if feature in _ENCODING_DICS:
|
| 150 |
+
return _ENCODING_DICS[feature][value]
|
| 151 |
+
raise ValueError(f"Unknown feature: {feature}")
|