Skip to content

Commit c112d0a

Browse files
committed
API: update anomaly detection hyperparameter and logging
1 parent a9aedb4 commit c112d0a

File tree

2 files changed

+17
-103
lines changed

2 files changed

+17
-103
lines changed

src/MLApplications.API/Controllers/AnomalyDetectionController.cs

+16-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class AnomalyDetectionController : ControllerBase
1919
// Data file path and dataset size
2020
private string _dataPath = Path.Combine(Environment.CurrentDirectory, "Datasets", "intraday_5min_TSLA.csv");
2121
// assign the Number of records in dataset file to constant variable
22-
private const int _docsize = 180;
22+
private const int _docsize = 79;
2323

2424
/// <summary>
2525
/// Controller ctor
@@ -63,6 +63,21 @@ private IEnumerable<ModelOutput> DetectSpike(MLContext mlContext, int docSize, I
6363

6464
var predictions = mlContext.Data.CreateEnumerable<ModelOutput>(transformedData, reuseRowObject: false);
6565

66+
Console.WriteLine("Alert\tStock Price\tP-Value");
67+
68+
foreach (var p in predictions)
69+
{
70+
var results = $"{p.Prediction[0]}\t{p.Prediction[1]:f2}\t{p.Prediction[2]:F2}";
71+
72+
if (p.Prediction[0] == 1)
73+
{
74+
results += " <-- Spike detected";
75+
}
76+
77+
Console.WriteLine(results);
78+
}
79+
Console.WriteLine("");
80+
6681
return predictions;
6782
}
6883

Original file line numberDiff line numberDiff line change
@@ -1,57 +1,4 @@
11
timestamp,open,high,low,close,volume
2-
2020-12-31 4:05,693.5,693.62,693,693.2,4343
3-
2020-12-31 4:10,692.7,692.7,690.49,690.52,3942
4-
2020-12-31 4:15,691.77,693.4,691.77,693.4,1302
5-
2020-12-31 4:35,692.7,692.7,692.7,692.7,410
6-
2020-12-31 4:50,692.7,692.7,692.7,692.7,582
7-
2020-12-31 5:20,693.35,693.35,693.35,693.35,518
8-
2020-12-31 5:25,693.3,693.3,693.3,693.3,113
9-
2020-12-31 5:35,693.2,693.2,693.2,693.2,454
10-
2020-12-31 5:40,693.5,693.5,693.5,693.5,303
11-
2020-12-31 5:45,693.36,693.5,693.35,693.5,1308
12-
2020-12-31 5:50,694.2,694.2,694.2,694.2,420
13-
2020-12-31 5:55,693.99,693.99,693.92,693.92,640
14-
2020-12-31 6:00,693.89,693.99,693.89,693.99,707
15-
2020-12-31 6:05,693.95,693.95,693.95,693.95,452
16-
2020-12-31 6:15,694.5,696,694.5,696,1495
17-
2020-12-31 6:20,697,697.47,696.79,697.47,3352
18-
2020-12-31 6:25,698,699.3,698,699.2,7656
19-
2020-12-31 6:30,698.94,699,698,698,2799
20-
2020-12-31 6:35,698.98,699,698.8,699,1702
21-
2020-12-31 6:40,698.3,698.3,697.5,697.75,1671
22-
2020-12-31 6:45,698.06,698.65,698,698.65,1812
23-
2020-12-31 6:50,698.66,699,698.66,698.66,5497
24-
2020-12-31 6:55,698.66,699.34,698.66,699.34,2178
25-
2020-12-31 7:00,699.01,699.25,698.91,698.91,4114
26-
2020-12-31 7:05,698.25,703.39,697.5,703.36,117016
27-
2020-12-31 7:10,703.37,705.49,702.66,703.29,119348
28-
2020-12-31 7:15,703.85,706,703,705,55892
29-
2020-12-31 7:20,705,705.4,704.13,705.4,27193
30-
2020-12-31 7:25,705.44,706.3,703.97,704.35,49987
31-
2020-12-31 7:30,704.75,704.75,702.75,703.5,30252
32-
2020-12-31 7:35,703.65,704.75,703.5,704.6,19961
33-
2020-12-31 7:40,704.33,704.7,703.55,704.17,27060
34-
2020-12-31 7:45,703.59,703.79,702.4,703.6,15635
35-
2020-12-31 7:50,703.51,704.04,703.15,703.7,15044
36-
2020-12-31 7:55,703.55,703.55,702.5,702.5,9692
37-
2020-12-31 8:00,702.3,704.1,702.05,703.4,15371
38-
2020-12-31 8:05,699.5,706.0102,697.65,703.63,107676
39-
2020-12-31 8:10,703.65,703.9799,703,703.31,18780
40-
2020-12-31 8:15,703.45,704,703.24,703.25,21703
41-
2020-12-31 8:20,703.49,704,702.65,702.65,22247
42-
2020-12-31 8:25,702.65,703.15,702.03,702.69,24129
43-
2020-12-31 8:30,702.25,702.5,701.35,701.79,33827
44-
2020-12-31 8:35,701.72,702.13,701.55,701.92,17089
45-
2020-12-31 8:40,701.98,702.43,701.98,702.21,11180
46-
2020-12-31 8:45,702,702.91,702,702.89,13484
47-
2020-12-31 8:50,702.8,702.8,701.55,701.6,20300
48-
2020-12-31 8:55,701.55,701.57,700.11,700.11,27113
49-
2020-12-31 9:00,700.11,701,698.5,699,70210
50-
2020-12-31 9:05,699.27,700.8,699,700.8,42136
51-
2020-12-31 9:10,700.21,700.9,699.79,700.5,33364
52-
2020-12-31 9:15,700.3,700.4,699.5,699.69,17435
53-
2020-12-31 9:20,699.6,700.01,698.82,700,30120
54-
2020-12-31 9:25,700,700.8,700,700.5,26340
552
2020-12-31 9:30,700,700.68,699.07,699.93,50422
563
2020-12-31 9:35,699.99,703.7399,696.59,698.38,1844955
574
2020-12-31 9:40,698.29,701,696,700.3774,1047052
@@ -130,52 +77,4 @@ timestamp,open,high,low,close,volume
13077
2020-12-31 15:45,700.74,704.95,699.7801,704.17,624427
13178
2020-12-31 15:50,704.2213,705.9999,702.64,703.78,714316
13279
2020-12-31 15:55,704.2,706.61,703.4,706.59,632155
133-
2020-12-31 16:00,706.51,706.8999,705,705.21,919892
134-
2020-12-31 16:05,705.67,705.99,703.24,704.59,134863
135-
2020-12-31 16:10,704.68,705.38,704.3,705,26462
136-
2020-12-31 16:15,705.17,705.17,704.65,704.8,11656
137-
2020-12-31 16:20,704.805,705,704.78,705,13556
138-
2020-12-31 16:25,705,705.67,704.75,705.18,10075
139-
2020-12-31 16:30,705.04,705.04,704.7,704.7,7629
140-
2020-12-31 16:35,704.7,705,704.7,704.85,7675
141-
2020-12-31 16:40,704.85,705,704.85,705,5771
142-
2020-12-31 16:45,704.98,705.01,704.8,705.01,25504
143-
2020-12-31 16:50,705,705.33,704.95,704.95,11348
144-
2020-12-31 16:55,704.91,705.01,704.8,704.8,4678
145-
2020-12-31 17:00,704.85,704.8802,704.8,704.8802,195281
146-
2020-12-31 17:05,704.98,705.12,704.96,705,9304
147-
2020-12-31 17:10,704.97,705.0202,704.95,705.02,3524
148-
2020-12-31 17:15,705.04,705.04,704.96,705.01,2964
149-
2020-12-31 17:20,705.01,705.01,704.98,705.01,5116
150-
2020-12-31 17:25,705.03,705.04,704.99,704.99,4300
151-
2020-12-31 17:30,704.99,705,704.88,704.88,5099
152-
2020-12-31 17:35,704.74,704.95,704.71,704.89,4660
153-
2020-12-31 17:40,704.9,704.9,704.85,704.85,822
154-
2020-12-31 17:45,704.89,704.98,704.89,704.98,4371
155-
2020-12-31 17:50,705,705.04,704.9501,705,5675
156-
2020-12-31 17:55,704.85,704.85,704.5,704.84,1429
157-
2020-12-31 18:00,704.85,704.99,704.85,704.99,2280
158-
2020-12-31 18:05,704.99,704.99,704.99,704.99,673
159-
2020-12-31 18:10,704.93,704.94,704.9299,704.94,1405
160-
2020-12-31 18:15,704.9,704.95,704.85,704.85,1962
161-
2020-12-31 18:20,704.94,704.94,704.85,704.85,1142
162-
2020-12-31 18:25,704.9,704.9,704.85,704.85,475
163-
2020-12-31 18:30,704.85,704.9,704.85,704.85,579
164-
2020-12-31 18:35,704.9,704.9,704.9,704.9,625
165-
2020-12-31 18:40,704.9,704.93,704.85,704.93,1798
166-
2020-12-31 18:45,704.97,705,704.95,704.95,2485
167-
2020-12-31 18:50,704.96,704.96,704.75,704.87,4364
168-
2020-12-31 18:55,704.58,704.9,704.58,704.84,1365
169-
2020-12-31 19:00,704.89,704.89,704.71,704.71,1956
170-
2020-12-31 19:05,704.65,704.65,704.65,704.65,2004
171-
2020-12-31 19:10,704.51,704.51,704.06,704.35,4733
172-
2020-12-31 19:15,704.21,704.49,704.2,704.35,2087
173-
2020-12-31 19:20,704.35,704.35,704.21,704.25,2030
174-
2020-12-31 19:25,704.25,704.5,704.25,704.43,2065
175-
2020-12-31 19:30,704.43,704.43,704.15,704.25,2770
176-
2020-12-31 19:35,704.22,704.28,704.05,704.28,2214
177-
2020-12-31 19:40,704.24,704.28,704.14,704.14,2045
178-
2020-12-31 19:45,704.2,704.27,704.15,704.25,5347
179-
2020-12-31 19:50,704.27,704.5,704.27,704.48,15066
180-
2020-12-31 19:55,704.4,704.49,704.35,704.35,5175
181-
2020-12-31 20:00,704.4,704.7,704.4,704.5,12221
80+
2020-12-31 16:00,706.51,706.8999,705,705.21,919892

0 commit comments

Comments
 (0)