diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectChangePointBySsa.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectChangePointBySsa.cs index 7d545770f9..23fb7e5c9c 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectChangePointBySsa.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectChangePointBySsa.cs @@ -52,7 +52,7 @@ public static void Example() // Setup SsaChangePointDetector arguments var inputColumnName = nameof(TimeSeriesData.Value); var outputColumnName = nameof(ChangePointPrediction.Prediction); - int confidence = 95; + double confidence = 95; int changeHistoryLength = 8; // Train the change point detector. diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectChangePointBySsaBatchPrediction.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectChangePointBySsaBatchPrediction.cs index 25819052d8..85732f9259 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectChangePointBySsaBatchPrediction.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectChangePointBySsaBatchPrediction.cs @@ -59,7 +59,7 @@ public static void Example() // The transformed data. var transformedData = ml.Transforms.DetectChangePointBySsa( - outputColumnName, inputColumnName, 95, 8, TrainingSize, + outputColumnName, inputColumnName, 95.0d, 8, TrainingSize, SeasonalitySize + 1).Fit(dataView).Transform(dataView); // Getting the data of the newly created column as an IEnumerable of diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectChangePointBySsaStream.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectChangePointBySsaStream.cs index c65d3af987..dfab85aee2 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectChangePointBySsaStream.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectChangePointBySsaStream.cs @@ -52,7 +52,7 @@ public static void Example() // Setup SsaChangePointDetector arguments var inputColumnName = nameof(TimeSeriesData.Value); var outputColumnName = nameof(ChangePointPrediction.Prediction); - int confidence = 95; + double confidence = 95; int changeHistoryLength = 8; // Train the change point detector. diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIidChangePoint.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIidChangePoint.cs index 4e44a73607..852fc9f8e9 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIidChangePoint.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIidChangePoint.cs @@ -55,7 +55,7 @@ public static void Example() // Time Series model. ITransformer model = ml.Transforms.DetectIidChangePoint( - outputColumnName, inputColumnName, 95, Size / 4).Fit(dataView); + outputColumnName, inputColumnName, 95.0d, Size / 4).Fit(dataView); // Create a time series prediction engine from the model. var engine = model.CreateTimeSeriesEngine /// /// + [Obsolete("This API method is deprecated, please use the overload with confidence parameter of type double.")] public static IidChangePointEstimator DetectIidChangePoint(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, int confidence, int changeHistoryLength, MartingaleType martingale = MartingaleType.Power, double eps = 0.1) + => DetectIidChangePoint(catalog, outputColumnName, inputColumnName, (double)confidence, changeHistoryLength, martingale, eps); + + /// + /// Create , which predicts change points in an + /// independent identically distributed (i.i.d.) + /// time series based on adaptive kernel density estimations and martingale scores. + /// + /// The transform's catalog. + /// Name of the column resulting from the transformation of . + /// The column data is a vector of . The vector contains 4 elements: alert (non-zero value means a change point), raw score, p-Value and martingale score. + /// Name of column to transform. The column data must be . If set to , the value of the will be used as source. + /// The confidence for change point detection in the range [0, 100]. + /// The length of the sliding window on p-values for computing the martingale score. + /// The martingale used for scoring. + /// The epsilon parameter for the Power martingale. + /// + /// + /// + /// + /// + public static IidChangePointEstimator DetectIidChangePoint(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, + double confidence, int changeHistoryLength, MartingaleType martingale = MartingaleType.Power, double eps = 0.1) => new IidChangePointEstimator(CatalogUtils.GetEnvironment(catalog), outputColumnName, confidence, changeHistoryLength, inputColumnName, martingale, eps); /// @@ -56,8 +82,33 @@ public static IidChangePointEstimator DetectIidChangePoint(this TransformsCatalo /// ]]> /// /// + [Obsolete("This API method is deprecated, please use the overload with confidence parameter of type double.")] public static IidSpikeEstimator DetectIidSpike(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, int confidence, int pvalueHistoryLength, AnomalySide side = AnomalySide.TwoSided) + => DetectIidSpike(catalog, outputColumnName, inputColumnName, (double)confidence, pvalueHistoryLength, side); + + /// + /// Create , which predicts spikes in + /// independent identically distributed (i.i.d.) + /// time series based on adaptive kernel density estimations and martingale scores. + /// + /// The transform's catalog. + /// Name of the column resulting from the transformation of . + /// The column data is a vector of . The vector contains 3 elements: alert (non-zero value means a spike), raw score, and p-value. + /// Name of column to transform. The column data must be . + /// If set to , the value of the will be used as source. + /// The confidence for spike detection in the range [0, 100]. + /// The size of the sliding window for computing the p-value. + /// The argument that determines whether to detect positive or negative anomalies, or both. + /// + /// + /// + /// + /// + public static IidSpikeEstimator DetectIidSpike(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, + double confidence, int pvalueHistoryLength, AnomalySide side = AnomalySide.TwoSided) => new IidSpikeEstimator(CatalogUtils.GetEnvironment(catalog), outputColumnName, confidence, pvalueHistoryLength, inputColumnName, side); /// @@ -83,9 +134,38 @@ public static IidSpikeEstimator DetectIidSpike(this TransformsCatalog catalog, s /// ]]> /// /// + [Obsolete("This API method is deprecated, please use the overload with confidence parameter of type double.")] public static SsaChangePointEstimator DetectChangePointBySsa(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, int confidence, int changeHistoryLength, int trainingWindowSize, int seasonalityWindowSize, ErrorFunction errorFunction = ErrorFunction.SignedDifference, MartingaleType martingale = MartingaleType.Power, double eps = 0.1) + => DetectChangePointBySsa(catalog, outputColumnName, inputColumnName, (double)confidence, changeHistoryLength, trainingWindowSize, seasonalityWindowSize, errorFunction, martingale, eps); + + /// + /// Create , which predicts change points in time series + /// using Singular Spectrum Analysis (SSA). + /// + /// The transform's catalog. + /// Name of the column resulting from the transformation of . + /// The column data is a vector of . The vector contains 4 elements: alert (non-zero value means a change point), raw score, p-Value and martingale score. + /// Name of column to transform. The column data must be . + /// If set to , the value of the will be used as source. + /// The confidence for change point detection in the range [0, 100]. + /// The number of points from the beginning of the sequence used for training. + /// The size of the sliding window for computing the p-value. + /// An upper bound on the largest relevant seasonality in the input time-series. + /// The function used to compute the error between the expected and the observed value. + /// The martingale used for scoring. + /// The epsilon parameter for the Power martingale. + /// + /// + /// + /// + /// + public static SsaChangePointEstimator DetectChangePointBySsa(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, + double confidence, int changeHistoryLength, int trainingWindowSize, int seasonalityWindowSize, ErrorFunction errorFunction = ErrorFunction.SignedDifference, + MartingaleType martingale = MartingaleType.Power, double eps = 0.1) => new SsaChangePointEstimator(CatalogUtils.GetEnvironment(catalog), new SsaChangePointDetector.Options { Name = outputColumnName, @@ -121,7 +201,34 @@ public static SsaChangePointEstimator DetectChangePointBySsa(this TransformsCata /// ]]> /// /// + [Obsolete("This API method is deprecated, please use the overload with confidence parameter of type double.")] public static SsaSpikeEstimator DetectSpikeBySsa(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, int confidence, int pvalueHistoryLength, + int trainingWindowSize, int seasonalityWindowSize, AnomalySide side = AnomalySide.TwoSided, ErrorFunction errorFunction = ErrorFunction.SignedDifference) + => DetectSpikeBySsa(catalog, outputColumnName, inputColumnName, (double)confidence, pvalueHistoryLength, trainingWindowSize, seasonalityWindowSize, side, errorFunction); + + /// + /// Create , which predicts spikes in time series + /// using Singular Spectrum Analysis (SSA). + /// + /// The transform's catalog. + /// Name of the column resulting from the transformation of . + /// The column data is a vector of . The vector contains 3 elements: alert (non-zero value means a spike), raw score, and p-value. + /// Name of column to transform. The column data must be . + /// If set to , the value of the will be used as source. + /// The confidence for spike detection in the range [0, 100]. + /// The size of the sliding window for computing the p-value. + /// The number of points from the beginning of the sequence used for training. + /// An upper bound on the largest relevant seasonality in the input time-series. + /// The argument that determines whether to detect positive or negative anomalies, or both. + /// The function used to compute the error between the expected and the observed value. + /// + /// + /// + /// + /// + public static SsaSpikeEstimator DetectSpikeBySsa(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, double confidence, int pvalueHistoryLength, int trainingWindowSize, int seasonalityWindowSize, AnomalySide side = AnomalySide.TwoSided, ErrorFunction errorFunction = ErrorFunction.SignedDifference) => new SsaSpikeEstimator(CatalogUtils.GetEnvironment(catalog), outputColumnName, confidence, pvalueHistoryLength, trainingWindowSize, seasonalityWindowSize, inputColumnName, side, errorFunction); diff --git a/src/Microsoft.ML.TimeSeries/IidChangePointDetector.cs b/src/Microsoft.ML.TimeSeries/IidChangePointDetector.cs index 3ac2348f74..dbfdc32376 100644 --- a/src/Microsoft.ML.TimeSeries/IidChangePointDetector.cs +++ b/src/Microsoft.ML.TimeSeries/IidChangePointDetector.cs @@ -219,7 +219,7 @@ private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, Dat /// ]]> /// /// - /// + /// public sealed class IidChangePointEstimator : TrivialEstimator { /// @@ -233,7 +233,7 @@ public sealed class IidChangePointEstimator : TrivialEstimatorName of column to transform. If set to , the value of the will be used as source. /// The martingale used for scoring. /// The epsilon parameter for the Power martingale. - internal IidChangePointEstimator(IHostEnvironment env, string outputColumnName, int confidence, + internal IidChangePointEstimator(IHostEnvironment env, string outputColumnName, double confidence, int changeHistoryLength, string inputColumnName, MartingaleType martingale = MartingaleType.Power, double eps = 0.1) : base(Contracts.CheckRef(env, nameof(env)).Register(nameof(IidChangePointEstimator)), new IidChangePointDetector(env, new IidChangePointDetector.Options diff --git a/src/Microsoft.ML.TimeSeries/IidSpikeDetector.cs b/src/Microsoft.ML.TimeSeries/IidSpikeDetector.cs index e878db941a..0708aef2e8 100644 --- a/src/Microsoft.ML.TimeSeries/IidSpikeDetector.cs +++ b/src/Microsoft.ML.TimeSeries/IidSpikeDetector.cs @@ -199,7 +199,7 @@ private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, Dat /// ]]> /// /// - /// + /// public sealed class IidSpikeEstimator : TrivialEstimator { /// @@ -212,7 +212,7 @@ public sealed class IidSpikeEstimator : TrivialEstimator /// The size of the sliding window for computing the p-value. /// Name of column to transform. If set to , the value of the will be used as source. /// The argument that determines whether to detect positive or negative anomalies, or both. - internal IidSpikeEstimator(IHostEnvironment env, string outputColumnName, int confidence, int pvalueHistoryLength, string inputColumnName, AnomalySide side = AnomalySide.TwoSided) + internal IidSpikeEstimator(IHostEnvironment env, string outputColumnName, double confidence, int pvalueHistoryLength, string inputColumnName, AnomalySide side = AnomalySide.TwoSided) : base(Contracts.CheckRef(env, nameof(env)).Register(nameof(IidSpikeDetector)), new IidSpikeDetector(env, new IidSpikeDetector.Options { diff --git a/src/Microsoft.ML.TimeSeries/SsaChangePointDetector.cs b/src/Microsoft.ML.TimeSeries/SsaChangePointDetector.cs index 8d2018daed..1e3969b6a2 100644 --- a/src/Microsoft.ML.TimeSeries/SsaChangePointDetector.cs +++ b/src/Microsoft.ML.TimeSeries/SsaChangePointDetector.cs @@ -226,7 +226,7 @@ private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, Dat /// ]]> /// /// - /// + /// public sealed class SsaChangePointEstimator : IEstimator { private readonly IHost _host; @@ -247,7 +247,7 @@ public sealed class SsaChangePointEstimator : IEstimator /// The martingale used for scoring. /// The epsilon parameter for the Power martingale. internal SsaChangePointEstimator(IHostEnvironment env, string outputColumnName, - int confidence, + double confidence, int changeHistoryLength, int trainingWindowSize, int seasonalityWindowSize, diff --git a/src/Microsoft.ML.TimeSeries/SsaSpikeDetector.cs b/src/Microsoft.ML.TimeSeries/SsaSpikeDetector.cs index e22f80969e..a0e1fca547 100644 --- a/src/Microsoft.ML.TimeSeries/SsaSpikeDetector.cs +++ b/src/Microsoft.ML.TimeSeries/SsaSpikeDetector.cs @@ -207,7 +207,7 @@ private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, Dat /// ]]> /// /// - /// + /// public sealed class SsaSpikeEstimator : IEstimator { private readonly IHost _host; @@ -228,7 +228,7 @@ public sealed class SsaSpikeEstimator : IEstimator /// The function used to compute the error between the expected and the observed value. internal SsaSpikeEstimator(IHostEnvironment env, string outputColumnName, - int confidence, + double confidence, int pvalueHistoryLength, int trainingWindowSize, int seasonalityWindowSize, diff --git a/test/Microsoft.ML.TimeSeries.Tests/TimeSeriesSimpleApiTests.cs b/test/Microsoft.ML.TimeSeries.Tests/TimeSeriesSimpleApiTests.cs index aad10ccef2..7905bf6d89 100644 --- a/test/Microsoft.ML.TimeSeries.Tests/TimeSeriesSimpleApiTests.cs +++ b/test/Microsoft.ML.TimeSeries.Tests/TimeSeriesSimpleApiTests.cs @@ -48,7 +48,7 @@ public void ChangeDetection() data.Add(new Data((float)(5 + i * 1.1))); // Build the pipeline - var learningPipeline = ML.Transforms.DetectIidChangePoint("Data", "Value", 80, size); + var learningPipeline = ML.Transforms.DetectIidChangePoint("Data", "Value", 80.0d, size); // Train var detector = learningPipeline.Fit(dataView); @@ -92,7 +92,7 @@ public void ChangePointDetectionWithSeasonality() data.Add(new Data(i * 100)); // Build the pipeline - var learningPipeline = ML.Transforms.DetectChangePointBySsa("Data", "Value", 95, changeHistorySize, maxTrainingSize, seasonalitySize); + var learningPipeline = ML.Transforms.DetectChangePointBySsa("Data", "Value", 95.0d, changeHistorySize, maxTrainingSize, seasonalitySize); // Train var detector = learningPipeline.Fit(dataView); // Transform @@ -133,7 +133,7 @@ public void SpikeDetection() data.Add(new Data(5)); // Build the pipeline - var learningPipeline = ML.Transforms.DetectIidSpike("Data", "Value", 80, pvalHistoryLength); + var learningPipeline = ML.Transforms.DetectIidSpike("Data", "Value", 80.0d, pvalHistoryLength); // Train var detector = learningPipeline.Fit(dataView); // Transform @@ -185,7 +185,7 @@ public void SsaSpikeDetection() data.Add(new Data(5)); // Build the pipeline - var learningPipeline = ML.Transforms.DetectSpikeBySsa("Data", "Value", 80, changeHistoryLength, trainingWindowSize, seasonalityWindowSize); + var learningPipeline = ML.Transforms.DetectSpikeBySsa("Data", "Value", 80.0d, changeHistoryLength, trainingWindowSize, seasonalityWindowSize); // Train var detector = learningPipeline.Fit(dataView); // Transform