You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unable to detect anomaly in data that appears anomalous #5491
` [Fact]
public void TestRunSrCnnAnomalyDetector()
{
var ml = new MLContext(1);
IDataView dataView;
List data = new List();
var dataPath = @"PathToInputFile";
var outputPath = @"PathToOutputFile";
var valueColumnIndex = 1;
// Load data from file into the dataView
using StreamReader inputFile = new StreamReader(dataPath);
var line = inputFile.ReadLine();
while((line = inputFile.ReadLine()) != null)
{
var content = line.Split(",".ToCharArray());
data.Add(new TimeSeriesDataDouble { Value=Double.Parse(content[valueColumnIndex]) });
}
dataView = ml.Data.LoadFromEnumerable<TimeSeriesDataDouble>(data);
// Setup the detection arguments
string outputColumnName = nameof(SrCnnAnomalyDetection.Prediction);
string inputColumnName = nameof(TimeSeriesDataDouble.Value);
// Do batch anomaly detection
var options = new SrCnnEntireAnomalyDetectorOptions()
{
Threshold = 0.23,
BatchSize = -1,
Sensitivity = 53.0,
DetectMode = SrCnnDetectMode.AnomalyAndMargin,
Period = 0,
DeseasonalityMode = SrCnnDeseasonalityMode.Stl
};
var outputDataView = ml.AnomalyDetection.DetectEntireAnomalyBySrCnn(dataView, outputColumnName, inputColumnName, options);
// Getting the data of the newly created column as an IEnumerable of SrCnnAnomalyDetection.
var predictionColumn = ml.Data.CreateEnumerable<SrCnnAnomalyDetection>(
outputDataView, reuseRowObject: false);
using StreamWriter file = new StreamWriter(outputPath, false);
file.WriteLine("value,isAnomaly,anomalyScore,magnitude,expectedValue,boundaryUnits,upperBoundary,lowerBoundary");
var k = 0;
foreach (var prediction in predictionColumn)
{
file.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7}", data[k].Value,
prediction.Prediction[0], prediction.Prediction[1], prediction.Prediction[2], prediction.Prediction[3], prediction.Prediction[4], prediction.Prediction[5], prediction.Prediction[6]);
++k;
}
}
`
Could you use this script to run the case and update the output here?
Activity
guinao commentedon Nov 18, 2020
` [Fact]
public void TestRunSrCnnAnomalyDetector()
{
var ml = new MLContext(1);
IDataView dataView;
List data = new List();
`
Could you use this script to run the case and update the output here?
nnoradie commentedon Nov 18, 2020
Here's the output I got. Looks like no anomalies were detected
guinao commentedon Nov 20, 2020
The root cause lies in the SR score function, which is
score = abs(mag - ave_mag) / ave_mag.
For the first point, ave_mag = mag, then
score_0 = (mag_0 - mag_0) / mag_0 = 0
For the second point, ave_mag = (mag_0 + mag_1) / 2, then
score_1 = (mag_1 - (mag_0 + mag_1) / 2) / ((mag_0 + mag_1) / 2) = abs(mag_1 - mag_0) / (mag_0 + mag_1) < 1.
So both two can not ever become anomaly points.
We proposed the solution to use the ave_mag of first full window to replace the avg_mag of first W points, where W is the score window size.
guinao commentedon Nov 20, 2020
The output after the fix is attached below. with parameters
antoniovs1029 commentedon Dec 28, 2020
It seems this got fixed in #5502 . Thanks @guinao for fixing it!