Skip to content

Commit edda512

Browse files
committed
add time and sample windowing mode examples using same dataset
1 parent bc86819 commit edda512

11 files changed

Lines changed: 3959 additions & 1 deletion

example/prediction_example.py renamed to examples/legacy-example/prediction_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import datetime
22
import os
33
import sys
4-
sys.path.insert(1, os.path.join(sys.path[0], '../src')) # add edgeml to path
4+
sys.path.insert(1, os.path.join(sys.path[0], '../../src')) # add edgeml to path
55

66
import time as timelib
77
import pandas as pd

examples/shake-example/DatasetUsedForTraining.csv

Lines changed: 1547 additions & 0 deletions
Large diffs are not rendered by default.

examples/shake-example/Readme.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
### shake-example
2+
3+
This example uses a csv data as input and does inference on the data. Input csv file, as well as the dataset used for training the model can be found in the directory. This dataset is used to create two different models, one with time based windowing, other with sample based windowing.
4+
5+
#### Usage:
6+
7+
```
8+
❯ python sample_mode_example.py
9+
❯ python time_mode_example.py
10+
```
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from datetime import datetime
2+
import os
3+
import sys
4+
sys.path.insert(1, os.path.join(sys.path[0], '../../src')) # add edgeml to path
5+
6+
import time as timelib
7+
import pandas as pd
8+
from edgeml.predictor import Predictor, PredictorError
9+
10+
from shakesample_python import score
11+
12+
p = Predictor(
13+
predictor = lambda input: score(input),
14+
sensors = ['AccelerometerX', 'AccelerometerY', 'AccelerometerZ', 'GyroscopeX', 'GyroscopeY', 'GyroscopeZ'],
15+
window_size = 100,
16+
labels = ['shake', 'STILL'],
17+
scaler = {'scale': [456.89999999999986, 1.7000000000000002, 4.568999999999999, 1.0, 16.37991667923493, 272.6723773333334, 20.55429975152452, 43.50000000000001, 43.50000000000001, 37.7, 553.2333333333333, 4.800000000000001, 5.532333333333334, 1.0, 8.87448778931522, 80.51507597222225, 5.233021007637985, 14.399999999999999, 23.9, 29.300000000000004, 458.1333333333331, 1.1416666666666693, 4.58133333333333, 1.0, 17.97626482222193, 331.8784097777778, 10.897358557974057, 61.400000000000006, 61.400000000000006, 36.7, 27.92177737340528, 0.02923426497090502, 0.27921777373405277, 1.0, 5.674080882891607, 32.662245725674715, 6.131156197061794, 12.037535851004892, 15.02379420116719, 15.063936773963059, 31.333023396428203, 0.019634954084936207, 0.31333023396428206, 1.0, 8.905398086799991, 80.0946344892207, 8.90367312352328, 19.853120241435498, 19.853120241435498, 18.327702475192456, 17.675821999572577, 0.013962634015954637, 0.17675821999572577, 1.0, 5.575594915257246, 31.388752739250815, 5.869938977435963, 12.514010736799342, 12.514010736799342, 12.006119924468992], 'center': [156.8, 1.1, 1.568, 100.0, 10.265825965308393, 105.38718275000001, 11.602474951492033, 25.200000000000003, 25.200000000000003, -11.9, 180.99999999999994, 2.2, 1.8099999999999994, 100.0, 4.214677396379888, 17.763505555555554, 4.944580366421402, 13.200000000000001, 14.0, -7.9, 954.2499999999999, 9.2, 9.542499999999999, 100.0, 6.213705056387677, 38.610130527777784, 13.107873693996973, 29.5, 29.5, -12.200000000000001, -0.029670597283903654, -0.0008726646259971647, -0.0002967059728390365, 100.0, 1.607205387675301, 2.5831091581725145, 1.6081365012688127, 3.286454981505323, 11.082840750163992, -3.2951816277652943, 0.29466975537837603, 0.0017453292519943296, 0.0029466975537837605, 100.0, 3.250629986683856, 10.566595310328285, 3.2519927095577077, 6.485643500410929, 9.889035541799872, -9.321803534901715, -0.061959188445798744, 0.006981317007977318, -0.0006195918844579874, 100.0, 3.978628992873262, 15.829488662931706, 4.101449761530525, 10.10196571054318, 10.567968620825665, -5.46637121724624], 'name': 'RobustScaler'},
18+
windowing_mode = "sample"
19+
)
20+
21+
test = pd.read_csv('./test.csv', index_col=0)
22+
23+
for t, row in test.iterrows():
24+
time = int(t) / 1e3
25+
for key, valStr in row.iteritems():
26+
p.add_datapoint(key, float(valStr), time)
27+
28+
try:
29+
print(datetime.fromtimestamp(time), p.predict())
30+
timelib.sleep(0.01)
31+
except PredictorError:
32+
pass

0 commit comments

Comments
 (0)