-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
58 lines (47 loc) · 1.69 KB
/
main.py
File metadata and controls
58 lines (47 loc) · 1.69 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import pandas as pd
import torch
import platform
# data: (67488, 52) SWaT
# label 0.0: number = 31588,count = 46.81%
# label 1.0: number = 35900,count = 53.19%
# label 0: number = 9711,count = 43.08%
# label 1: number = 12833,count = 56.92% nsl-kdd
# label 0: number = 12228,count = 98.12%
# label 1: number = 234,count = 1.88%
# csv_path = "./data/24070102_test.csv"
def data_count(csv_path):
df = pd.read_csv(csv_path)
df.columns = df.columns.str.strip()
print("data:", df.shape)
if 'label' not in df.columns:
raise ValueError("no 'label' column")
label_counts = df['label'].value_counts()
total = label_counts.sum()
for label_value in sorted(label_counts.index):
count = label_counts[label_value]
percent = count / total * 100
print(f"label {label_value}: number = {count},count = {percent:.2f}%")
def attck_to_label(path):
df = pd.read_csv(path)
if "attack" in df.columns:
df = df.rename(columns={"attack": "label"})
print("column name has been modified.")
else:
print("no 'attack' column")
print(df.head(5))
print(df.shape)
df.to_csv(path, index=False)
def drop_index(path):
df = pd.read_csv(path, index_col=0)
df = df.reset_index(drop=True)
print(df.head())
df.to_csv(path, index=False)
if __name__ == '__main__':
# path = "../datas/SMAP/test_D_1.csv"
# df = pd.read_csv(path)
# print("data:", df.shape)
# data_count(path)
print("torch:", torch.__version__)
print("cuda:", torch.version.cuda)
print("操作系统:", platform.platform())
print("处理器:", platform.processor())