Skip to content

Instantly share code, notes, and snippets.

@TkrUdagawa
Created December 11, 2017 07:22
Show Gist options
  • Save TkrUdagawa/acb6fa40234a6b368bcf644199ae788b to your computer and use it in GitHub Desktop.
Save TkrUdagawa/acb6fa40234a6b368bcf644199ae788b to your computer and use it in GitHub Desktop.
anomaly score fluctuation
import jubatus
from jubatus.common import Datum
import random
import time
cl = jubatus.Anomaly("localhost", 9199, "test", 0)
random.seed(1)
datum_list = []
datum_length = 100
datum_num = 3000
for i in range(datum_num):
d = Datum()
for x in range(datum_length):
d.add_number("{}".format(x), random.random())
datum_list.append(d)
for i in range(5):
cl.clear()
start = time.time()
for d in datum_list:
cl.add(d)
end = time.time()
print("add time:", end - start)
print(cl.calc_score(datum_list[-1]))
{
"converter" : {
"string_filter_types" : {},
"string_filter_rules" : [],
"num_filter_types" : {},
"num_filter_rules" : [],
"string_types" : {},
"string_rules" : [
{ "key" : "*", "type" : "str", "sample_weight" : "bin", "global_weight" : "bin" }
],
"num_types" : {},
"num_rules" : [
{ "key" : "*", "type" : "num" }
]
},
"parameter" : {
"nearest_neighbor_num" : 10,
"reverse_nearest_neighbor_num" : 30,
"method" : "lsh",
"parameter" : {
"hash_num": 64
}
},
"method" : "lof"
}
$jubaanomaly -f lof.json&
$ python bench.py
2017-12-11 15:49:34,709 20751 INFO [anomaly_serv.cpp:246] model cleared:
add time: 18.31161880493164
1.0249063968658447
2017-12-11 15:49:53,028 20752 INFO [anomaly_serv.cpp:246] model cleared:
add time: 17.448886156082153
1.0471123456954956
2017-12-11 15:50:10,488 20752 INFO [anomaly_serv.cpp:246] model cleared:
add time: 19.00316023826599
1.0471124649047852
2017-12-11 15:50:29,496 20751 INFO [anomaly_serv.cpp:246] model cleared:
add time: 17.5341157913208
1.0249063968658447
2017-12-11 15:50:47,034 20751 INFO [anomaly_serv.cpp:246] model cleared:
add time: 17.534404754638672
1.0471123456954956
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment