-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample-anomaly2.py
37 lines (29 loc) · 914 Bytes
/
example-anomaly2.py
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
from skinfosec.models.anomaly.web.classes import RequestAnomalyDetector
from skinfosec.models.anomaly.web import classes
import logging
from timeit import default_timer as timer
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s')
logFile = "access.log"
#logFile = "access-extended-short.log"
logFH = open(logFile)
#X = classes.preprocess_requests(logFH, log_format="Combined")
X = classes.preprocess_requests(logFH,"CLF")
ad = RequestAnomalyDetector()
start = timer()
ad.fit(X)
end = timer()
print("fit elapsed time = ",end - start)
start = timer()
anomalies = ad.predict(X)
end = timer()
print("predict elapsed time = ",end - start)
print(anomalies)
anon_uri_len = anomalies['uri_length']
print(anomalies.loc[anomalies['uri_length'] == 1])
start = timer()
ad.kmeans()
print(ad.kmeans_labels)
end = timer()
print("kmeans elapsed time = ",end - start)
end = timer()
print(end - start)