From 83e02ced131593834a496b27fde2b4e805fe143c Mon Sep 17 00:00:00 2001 From: Senja Filipi Date: Fri, 8 Mar 2019 22:57:37 -0800 Subject: [PATCH 1/6] Time series samples and documentation alignment --- ...ndentIdenticallyDistributedChangePoint.cs} | 8 ++-- ...IndependentIdenticallyDistributedSpike.cs} | 8 ++-- ...gularSpectrumAnalysisDetectChangePoint.cs} | 14 ++++-- .../SingularSpectrumAnalysisDetectSpike.cs} | 6 +-- .../TimeSeriesStatic.cs | 8 ++-- .../ExtensionsCatalog.cs | 46 +++++++++++++++---- .../IidChangePointDetector.cs | 13 ++---- .../IidSpikeDetector.cs | 13 ++---- .../SsaChangePointDetector.cs | 13 +----- .../SsaSpikeDetector.cs | 13 +----- 10 files changed, 73 insertions(+), 69 deletions(-) rename docs/samples/Microsoft.ML.Samples/Dynamic/{IidChangePointDetectorTransform.cs => Transforms/TimeSeries/DetectIndependentIdenticallyDistributedChangePoint.cs} (95%) rename docs/samples/Microsoft.ML.Samples/Dynamic/{IidSpikeDetectorTransform.cs => Transforms/TimeSeries/DetectIndependentIdenticallyDistributedSpike.cs} (93%) rename docs/samples/Microsoft.ML.Samples/Dynamic/{SsaChangePointDetectorTransform.cs => Transforms/TimeSeries/SingularSpectrumAnalysisDetectChangePoint.cs} (93%) rename docs/samples/Microsoft.ML.Samples/Dynamic/{SsaSpikeDetectorTransform.cs => Transforms/TimeSeries/SingularSpectrumAnalysisDetectSpike.cs} (94%) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/IidChangePointDetectorTransform.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIndependentIdenticallyDistributedChangePoint.cs similarity index 95% rename from docs/samples/Microsoft.ML.Samples/Dynamic/IidChangePointDetectorTransform.cs rename to docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIndependentIdenticallyDistributedChangePoint.cs index 1993319838..6ca6ae5968 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/IidChangePointDetectorTransform.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIndependentIdenticallyDistributedChangePoint.cs @@ -10,7 +10,7 @@ namespace Microsoft.ML.Samples.Dynamic { - public static partial class TransformSamples + public static class DetectIndependentIdenticallyDistributedChangePoint { class ChangePointPrediction { @@ -30,7 +30,7 @@ public IidChangePointData(float value) // This example creates a time series (list of Data with the i-th element corresponding to the i-th time slot). // IidChangePointDetector is applied then to identify points where data distribution changed. - public static void IidChangePointDetectorTransform() + public static void Example() { // Create a new ML context, for ML.NET operations. It can be used for exception tracking and logging, // as well as the source of randomness. @@ -53,7 +53,7 @@ public static void IidChangePointDetectorTransform() string inputColumnName = nameof(IidChangePointData.Value); // The transformed data. - var transformedData = ml.Transforms.IidChangePointEstimator(outputColumnName, inputColumnName, 95, Size / 4).Fit(dataView).Transform(dataView); + var transformedData = ml.Transforms.DetectIndependentIdenticallyDistributedChangePoint(outputColumnName, inputColumnName, 95, Size / 4).Fit(dataView).Transform(dataView); // Getting the data of the newly created column as an IEnumerable of ChangePointPrediction. var predictionColumn = ml.Data.CreateEnumerable(transformedData, reuseRowObject: false); @@ -111,7 +111,7 @@ public static void IidChangePointDetectorPrediction() string inputColumnName = nameof(IidChangePointData.Value); // Time Series model. - ITransformer model = ml.Transforms.IidChangePointEstimator(outputColumnName, inputColumnName, 95, Size / 4).Fit(dataView); + ITransformer model = ml.Transforms.DetectIndependentIdenticallyDistributedChangePoint(outputColumnName, inputColumnName, 95, Size / 4).Fit(dataView); // Create a time series prediction engine from the model. var engine = model.CreateTimeSeriesPredictionFunction(ml); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/IidSpikeDetectorTransform.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIndependentIdenticallyDistributedSpike.cs similarity index 93% rename from docs/samples/Microsoft.ML.Samples/Dynamic/IidSpikeDetectorTransform.cs rename to docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIndependentIdenticallyDistributedSpike.cs index 7d7200daac..8f41815de4 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/IidSpikeDetectorTransform.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIndependentIdenticallyDistributedSpike.cs @@ -6,7 +6,7 @@ namespace Microsoft.ML.Samples.Dynamic { - public static partial class TransformSamples + public static class DetectIndependentIdenticallyDistributedSpike { class IidSpikeData { @@ -26,7 +26,7 @@ class IidSpikePrediction // This example creates a time series (list of Data with the i-th element corresponding to the i-th time slot). // IidSpikeDetector is applied then to identify spiking points in the series. - public static void IidSpikeDetectorTransform() + public static void Example() { // Create a new ML context, for ML.NET operations. It can be used for exception tracking and logging, // as well as the source of randomness. @@ -50,7 +50,7 @@ public static void IidSpikeDetectorTransform() string inputColumnName = nameof(IidSpikeData.Value); // The transformed data. - var transformedData = ml.Transforms.IidSpikeEstimator(outputColumnName, inputColumnName, 95, Size / 4).Fit(dataView).Transform(dataView); + var transformedData = ml.Transforms.DetectIndependentIdenticallyDistributedSpike(outputColumnName, inputColumnName, 95, Size / 4).Fit(dataView).Transform(dataView); // Getting the data of the newly created column as an IEnumerable of IidSpikePrediction. var predictionColumn = ml.Data.CreateEnumerable(transformedData, reuseRowObject: false); @@ -99,7 +99,7 @@ public static void IidSpikeDetectorPrediction() string outputColumnName = nameof(IidSpikePrediction.Prediction); string inputColumnName = nameof(IidSpikeData.Value); // The transformed model. - ITransformer model = ml.Transforms.IidChangePointEstimator(outputColumnName, inputColumnName, 95, Size).Fit(dataView); + ITransformer model = ml.Transforms.DetectIndependentIdenticallyDistributedSpike(outputColumnName, inputColumnName, 95, Size).Fit(dataView); // Create a time series prediction engine from the model. var engine = model.CreateTimeSeriesPredictionFunction(ml); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/SsaChangePointDetectorTransform.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SingularSpectrumAnalysisDetectChangePoint.cs similarity index 93% rename from docs/samples/Microsoft.ML.Samples/Dynamic/SsaChangePointDetectorTransform.cs rename to docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SingularSpectrumAnalysisDetectChangePoint.cs index 9ae7d489e4..adb09a709e 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/SsaChangePointDetectorTransform.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SingularSpectrumAnalysisDetectChangePoint.cs @@ -6,8 +6,14 @@ namespace Microsoft.ML.Samples.Dynamic { - public static partial class TransformSamples + public static class SingularSpectrumAnalysisDetectChangePoint { + class ChangePointPrediction + { + [VectorType(4)] + public double[] Prediction { get; set; } + } + class SsaChangePointData { public float Value; @@ -22,7 +28,7 @@ public SsaChangePointData(float value) // SsaChangePointDetector is applied then to identify points where data distribution changed. // SsaChangePointDetector differs from IidChangePointDetector in that it can account for temporal seasonality // in the data. - public static void SsaChangePointDetectorTransform() + public static void Example() { // Create a new ML context, for ML.NET operations. It can be used for exception tracking and logging, // as well as the source of randomness. @@ -48,7 +54,7 @@ public static void SsaChangePointDetectorTransform() var outputColumnName = nameof(ChangePointPrediction.Prediction); // The transformed data. - var transformedData = ml.Transforms.SsaChangePointEstimator(outputColumnName, inputColumnName, 95, 8, TrainingSize, SeasonalitySize + 1).Fit(dataView).Transform(dataView); + var transformedData = ml.Transforms.SingularSpectrumAnalysisDetectChangePoint(outputColumnName, inputColumnName, 95, 8, TrainingSize, SeasonalitySize + 1).Fit(dataView).Transform(dataView); // Getting the data of the newly created column as an IEnumerable of ChangePointPrediction. var predictionColumn = ml.Data.CreateEnumerable(transformedData, reuseRowObject: false); @@ -109,7 +115,7 @@ public static void SsaChangePointDetectorPrediction() var outputColumnName = nameof(ChangePointPrediction.Prediction); // Train the change point detector. - ITransformer model = ml.Transforms.SsaChangePointEstimator(outputColumnName, inputColumnName, 95, 8, TrainingSize, SeasonalitySize + 1).Fit(dataView); + ITransformer model = ml.Transforms.SingularSpectrumAnalysisDetectChangePoint(outputColumnName, inputColumnName, 95, 8, TrainingSize, SeasonalitySize + 1).Fit(dataView); // Create a prediction engine from the model for feeding new data. var engine = model.CreateTimeSeriesPredictionFunction(ml); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/SsaSpikeDetectorTransform.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SingularSpectrumAnalysisDetectSpike.cs similarity index 94% rename from docs/samples/Microsoft.ML.Samples/Dynamic/SsaSpikeDetectorTransform.cs rename to docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SingularSpectrumAnalysisDetectSpike.cs index be5b24f6e9..553abfcc9f 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/SsaSpikeDetectorTransform.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SingularSpectrumAnalysisDetectSpike.cs @@ -6,7 +6,7 @@ namespace Microsoft.ML.Samples.Dynamic { - public static partial class TransformSamples + public static class SingularSpectrumAnalysisDetectSpike { class SsaSpikeData { @@ -55,7 +55,7 @@ public static void SsaSpikeDetectorTransform() var outputColumnName = nameof(SsaSpikePrediction.Prediction); // The transformed data. - var transformedData = ml.Transforms.SsaSpikeEstimator(outputColumnName, inputColumnName, 95, 8, TrainingSize, SeasonalitySize + 1).Fit(dataView).Transform(dataView); + var transformedData = ml.Transforms.SingularSpectrumAnalysisDetectSpike(outputColumnName, inputColumnName, 95, 8, TrainingSize, SeasonalitySize + 1).Fit(dataView).Transform(dataView); // Getting the data of the newly created column as an IEnumerable of SsaSpikePrediction. var predictionColumn = ml.Data.CreateEnumerable(transformedData, reuseRowObject: false); @@ -117,7 +117,7 @@ public static void SsaSpikeDetectorPrediction() var outputColumnName = nameof(SsaSpikePrediction.Prediction); // Train the change point detector. - ITransformer model = ml.Transforms.SsaChangePointEstimator(outputColumnName, inputColumnName, 95, 8, TrainingSize, SeasonalitySize + 1).Fit(dataView); + ITransformer model = ml.Transforms.SingularSpectrumAnalysisDetectSpike(outputColumnName, inputColumnName, 95, 8, TrainingSize, SeasonalitySize + 1).Fit(dataView); // Create a prediction engine from the model for feeding new data. var engine = model.CreateTimeSeriesPredictionFunction(ml); diff --git a/src/Microsoft.ML.TimeSeries.StaticPipe/TimeSeriesStatic.cs b/src/Microsoft.ML.TimeSeries.StaticPipe/TimeSeriesStatic.cs index df4d6877ef..cacadece42 100644 --- a/src/Microsoft.ML.TimeSeries.StaticPipe/TimeSeriesStatic.cs +++ b/src/Microsoft.ML.TimeSeries.StaticPipe/TimeSeriesStatic.cs @@ -57,7 +57,7 @@ public override IEstimator Reconcile(IHostEnvironment env, { Contracts.Assert(toOutput.Length == 1); var outCol = (OutColumn)toOutput[0]; - return new MLContext().Transforms.IidChangePointEstimator( + return new MLContext().Transforms.DetectIndependentIdenticallyDistributedChangePoint( outputNames[outCol], inputNames[outCol.Input], _confidence, @@ -121,7 +121,7 @@ public override IEstimator Reconcile(IHostEnvironment env, { Contracts.Assert(toOutput.Length == 1); var outCol = (OutColumn)toOutput[0]; - return new MLContext().Transforms.IidSpikeEstimator( + return new MLContext().Transforms.DetectIndependentIdenticallyDistributedSpike( outputNames[outCol], inputNames[outCol.Input], _confidence, @@ -200,7 +200,7 @@ public override IEstimator Reconcile(IHostEnvironment env, { Contracts.Assert(toOutput.Length == 1); var outCol = (OutColumn)toOutput[0]; - return new MLContext().Transforms.SsaChangePointEstimator( + return new MLContext().Transforms.SingularSpectrumAnalysisDetectChangePoint( outputNames[outCol], inputNames[outCol.Input], _confidence, @@ -282,7 +282,7 @@ public override IEstimator Reconcile(IHostEnvironment env, { Contracts.Assert(toOutput.Length == 1); var outCol = (OutColumn)toOutput[0]; - return new MLContext().Transforms.SsaSpikeEstimator( + return new MLContext().Transforms.SingularSpectrumAnalysisDetectSpike( outputNames[outCol], inputNames[outCol.Input], _confidence, diff --git a/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs b/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs index e013f7c671..915a9faf1e 100644 --- a/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs +++ b/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs @@ -10,7 +10,8 @@ namespace Microsoft.ML public static class TimeSeriesCatalog { /// - /// Create a new instance of + /// Create a new instance of that detects a change of in a indiependent identically distributed time series. + /// Detection is based on adaptive kernel density estimations and martingale scores. /// /// The transform's catalog. /// Name of the column resulting from the transformation of . @@ -20,12 +21,20 @@ public static class TimeSeriesCatalog /// 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 IidChangePointEstimator(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, + /// + /// + /// + /// + /// + public static IidChangePointEstimator DetectIndependentIdenticallyDistributedChangePoint(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, int confidence, int changeHistoryLength, MartingaleType martingale = MartingaleType.Power, double eps = 0.1) => new IidChangePointEstimator(CatalogUtils.GetEnvironment(catalog), outputColumnName, confidence, changeHistoryLength, inputColumnName, martingale, eps); /// - /// Create a new instance of + /// Create a new instance of that detects a spike in an indiependent identically distributed time series. + /// Detection is based on adaptive kernel density estimations and martingale scores. /// /// The transform's catalog. /// Name of the column resulting from the transformation of . @@ -33,12 +42,19 @@ public static IidChangePointEstimator IidChangePointEstimator(this TransformsCat /// 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 IidSpikeEstimator(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, + /// + /// + /// + /// + /// + public static IidSpikeEstimator DetectIndependentIdenticallyDistributedSpike(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, int confidence, int pvalueHistoryLength, AnomalySide side = AnomalySide.TwoSided) => new IidSpikeEstimator(CatalogUtils.GetEnvironment(catalog), outputColumnName, confidence, pvalueHistoryLength, inputColumnName, side); /// - /// Create a new instance of + /// Create a new instance of for detecting a change in a time series signal using Singular Spectrum Analysis. /// /// The transform's catalog. /// Name of the column resulting from the transformation of . @@ -51,7 +67,14 @@ public static IidSpikeEstimator IidSpikeEstimator(this TransformsCatalog catalog /// 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 SsaChangePointEstimator(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, + /// + /// + /// + /// + /// + public static SsaChangePointEstimator SingularSpectrumAnalysisDetectChangePoint(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) => new SsaChangePointEstimator(CatalogUtils.GetEnvironment(catalog), new SsaChangePointDetector.Options @@ -68,7 +91,7 @@ public static SsaChangePointEstimator SsaChangePointEstimator(this TransformsCat }); /// - /// Create a new instance of + /// Create a new instance of for detecting a spike in a time series signal using Singular Spectrum Analysis. /// /// The transform's catalog. /// Name of the column resulting from the transformation of . @@ -80,7 +103,14 @@ public static SsaChangePointEstimator SsaChangePointEstimator(this TransformsCat /// The vector contains Alert, Raw Score, P-Value as first three values. /// 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 SsaSpikeEstimator(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, int confidence, int pvalueHistoryLength, + /// + /// + /// + /// + /// + public static SsaSpikeEstimator SingularSpectrumAnalysisDetectSpike(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, int 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 08e5165389..faa0770a9e 100644 --- a/src/Microsoft.ML.TimeSeries/IidChangePointDetector.cs +++ b/src/Microsoft.ML.TimeSeries/IidChangePointDetector.cs @@ -27,7 +27,7 @@ namespace Microsoft.ML.Transforms.TimeSeries { /// - /// This class implements the change point detector transform for an i.i.d. sequence based on adaptive kernel density estimation and martingales. + /// produced by fitting the to an . /// public sealed class IidChangePointDetector : IidAnomalyDetectionBaseWrapper, IStatefulTransformer { @@ -192,16 +192,9 @@ private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, Dat } /// - /// Estimator for + /// The for detecting a signal change on an Independent Identically Distributed time series. + /// Detection is based on adaptive kernel density estimation and martingales. /// - ///

Example code can be found by searching for IidChangePointDetector in ML.NET.

- /// - /// - /// - /// - /// public sealed class IidChangePointEstimator : TrivialEstimator { /// diff --git a/src/Microsoft.ML.TimeSeries/IidSpikeDetector.cs b/src/Microsoft.ML.TimeSeries/IidSpikeDetector.cs index 10b42e2dfb..01af69aaa9 100644 --- a/src/Microsoft.ML.TimeSeries/IidSpikeDetector.cs +++ b/src/Microsoft.ML.TimeSeries/IidSpikeDetector.cs @@ -26,7 +26,7 @@ namespace Microsoft.ML.Transforms.TimeSeries { /// - /// This class implements the spike detector transform for an i.i.d. sequence based on adaptive kernel density estimation. + /// produced by fitting the to an . /// public sealed class IidSpikeDetector : IidAnomalyDetectionBaseWrapper, IStatefulTransformer { @@ -172,16 +172,9 @@ private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, Dat } /// - /// Estimator for + /// The for detecting a signal spike on an Independent Identically Distributed time series. + /// Detection is based on adaptive kernel density estimation. /// - ///

Example code can be found by searching for IidSpikeDetector in ML.NET.

- /// - /// - /// - /// - /// public sealed class IidSpikeEstimator : TrivialEstimator { /// diff --git a/src/Microsoft.ML.TimeSeries/SsaChangePointDetector.cs b/src/Microsoft.ML.TimeSeries/SsaChangePointDetector.cs index 0183a66d6a..c32cd8b63d 100644 --- a/src/Microsoft.ML.TimeSeries/SsaChangePointDetector.cs +++ b/src/Microsoft.ML.TimeSeries/SsaChangePointDetector.cs @@ -27,8 +27,7 @@ namespace Microsoft.ML.Transforms.TimeSeries { /// - /// This class implements the change point detector transform based on Singular Spectrum modeling of the time-series. - /// For the details of the Singular Spectrum Analysis (SSA), refer to http://arxiv.org/pdf/1206.6910.pdf. + /// produced by fitting the to an . /// public sealed class SsaChangePointDetector : SsaAnomalyDetectionBaseWrapper, IStatefulTransformer { @@ -202,16 +201,8 @@ private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, Dat } /// - /// Estimator for + /// The for detecting a signal change through Singular Spectrum Analysis. of time series. /// - ///

Example code can be found by searching for SsaChangePointDetector in ML.NET.

- /// - /// - /// - /// - /// public sealed class SsaChangePointEstimator : IEstimator { private readonly IHost _host; diff --git a/src/Microsoft.ML.TimeSeries/SsaSpikeDetector.cs b/src/Microsoft.ML.TimeSeries/SsaSpikeDetector.cs index 7926d895ef..ca2ba90e58 100644 --- a/src/Microsoft.ML.TimeSeries/SsaSpikeDetector.cs +++ b/src/Microsoft.ML.TimeSeries/SsaSpikeDetector.cs @@ -26,8 +26,7 @@ namespace Microsoft.ML.Transforms.TimeSeries { /// - /// This class implements the spike detector transform based on Singular Spectrum modeling of the time-series. - /// For the details of the Singular Spectrum Analysis (SSA), refer to http://arxiv.org/pdf/1206.6910.pdf. + /// produced by fitting the to an . /// public sealed class SsaSpikeDetector : SsaAnomalyDetectionBaseWrapper, IStatefulTransformer { @@ -183,16 +182,8 @@ private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, Dat } /// - /// Estimator for + /// The for detecting a signal spike through Singular Spectrum Analysis. of time series. /// - ///

Example code can be found by searching for SsaSpikeDetector in ML.NET.

- /// - /// - /// - /// - /// public sealed class SsaSpikeEstimator : IEstimator { private readonly IHost _host; From 59d20926deca4feaf0631b30301105c046df17d3 Mon Sep 17 00:00:00 2001 From: Senja Filipi Date: Mon, 11 Mar 2019 09:41:19 -0700 Subject: [PATCH 2/6] adjusting the name to IID --- ...yDistributedChangePoint.cs => DetectIidChangePoint.cs} | 6 +++--- ...ntIdenticallyDistributedSpike.cs => DetectIidSpike.cs} | 6 +++--- .../TimeSeriesStatic.cs | 4 ++-- src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) rename docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/{DetectIndependentIdenticallyDistributedChangePoint.cs => DetectIidChangePoint.cs} (95%) rename docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/{DetectIndependentIdenticallyDistributedSpike.cs => DetectIidSpike.cs} (93%) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIndependentIdenticallyDistributedChangePoint.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIidChangePoint.cs similarity index 95% rename from docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIndependentIdenticallyDistributedChangePoint.cs rename to docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIidChangePoint.cs index 6ca6ae5968..3be92cd5fb 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIndependentIdenticallyDistributedChangePoint.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIidChangePoint.cs @@ -10,7 +10,7 @@ namespace Microsoft.ML.Samples.Dynamic { - public static class DetectIndependentIdenticallyDistributedChangePoint + public static class DetectIidChangePoint { class ChangePointPrediction { @@ -53,7 +53,7 @@ public static void Example() string inputColumnName = nameof(IidChangePointData.Value); // The transformed data. - var transformedData = ml.Transforms.DetectIndependentIdenticallyDistributedChangePoint(outputColumnName, inputColumnName, 95, Size / 4).Fit(dataView).Transform(dataView); + var transformedData = ml.Transforms.DetectIidChangePoint(outputColumnName, inputColumnName, 95, Size / 4).Fit(dataView).Transform(dataView); // Getting the data of the newly created column as an IEnumerable of ChangePointPrediction. var predictionColumn = ml.Data.CreateEnumerable(transformedData, reuseRowObject: false); @@ -111,7 +111,7 @@ public static void IidChangePointDetectorPrediction() string inputColumnName = nameof(IidChangePointData.Value); // Time Series model. - ITransformer model = ml.Transforms.DetectIndependentIdenticallyDistributedChangePoint(outputColumnName, inputColumnName, 95, Size / 4).Fit(dataView); + ITransformer model = ml.Transforms.DetectIidChangePoint(outputColumnName, inputColumnName, 95, Size / 4).Fit(dataView); // Create a time series prediction engine from the model. var engine = model.CreateTimeSeriesPredictionFunction(ml); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIndependentIdenticallyDistributedSpike.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIidSpike.cs similarity index 93% rename from docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIndependentIdenticallyDistributedSpike.cs rename to docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIidSpike.cs index 8f41815de4..ac4035e720 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIndependentIdenticallyDistributedSpike.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIidSpike.cs @@ -6,7 +6,7 @@ namespace Microsoft.ML.Samples.Dynamic { - public static class DetectIndependentIdenticallyDistributedSpike + public static class DetectIidSpike { class IidSpikeData { @@ -50,7 +50,7 @@ public static void Example() string inputColumnName = nameof(IidSpikeData.Value); // The transformed data. - var transformedData = ml.Transforms.DetectIndependentIdenticallyDistributedSpike(outputColumnName, inputColumnName, 95, Size / 4).Fit(dataView).Transform(dataView); + var transformedData = ml.Transforms.DetectIidSpike(outputColumnName, inputColumnName, 95, Size / 4).Fit(dataView).Transform(dataView); // Getting the data of the newly created column as an IEnumerable of IidSpikePrediction. var predictionColumn = ml.Data.CreateEnumerable(transformedData, reuseRowObject: false); @@ -99,7 +99,7 @@ public static void IidSpikeDetectorPrediction() string outputColumnName = nameof(IidSpikePrediction.Prediction); string inputColumnName = nameof(IidSpikeData.Value); // The transformed model. - ITransformer model = ml.Transforms.DetectIndependentIdenticallyDistributedSpike(outputColumnName, inputColumnName, 95, Size).Fit(dataView); + ITransformer model = ml.Transforms.DetectIidSpike(outputColumnName, inputColumnName, 95, Size).Fit(dataView); // Create a time series prediction engine from the model. var engine = model.CreateTimeSeriesPredictionFunction(ml); diff --git a/src/Microsoft.ML.TimeSeries.StaticPipe/TimeSeriesStatic.cs b/src/Microsoft.ML.TimeSeries.StaticPipe/TimeSeriesStatic.cs index cacadece42..f41593556b 100644 --- a/src/Microsoft.ML.TimeSeries.StaticPipe/TimeSeriesStatic.cs +++ b/src/Microsoft.ML.TimeSeries.StaticPipe/TimeSeriesStatic.cs @@ -57,7 +57,7 @@ public override IEstimator Reconcile(IHostEnvironment env, { Contracts.Assert(toOutput.Length == 1); var outCol = (OutColumn)toOutput[0]; - return new MLContext().Transforms.DetectIndependentIdenticallyDistributedChangePoint( + return new MLContext().Transforms.DetectIidChangePoint( outputNames[outCol], inputNames[outCol.Input], _confidence, @@ -121,7 +121,7 @@ public override IEstimator Reconcile(IHostEnvironment env, { Contracts.Assert(toOutput.Length == 1); var outCol = (OutColumn)toOutput[0]; - return new MLContext().Transforms.DetectIndependentIdenticallyDistributedSpike( + return new MLContext().Transforms.DetectIidSpike( outputNames[outCol], inputNames[outCol.Input], _confidence, diff --git a/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs b/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs index 915a9faf1e..79699d70e6 100644 --- a/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs +++ b/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs @@ -24,11 +24,11 @@ public static class TimeSeriesCatalog /// /// /// /// /// - public static IidChangePointEstimator DetectIndependentIdenticallyDistributedChangePoint(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, + public static IidChangePointEstimator DetectIidChangePoint(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, int confidence, int changeHistoryLength, MartingaleType martingale = MartingaleType.Power, double eps = 0.1) => new IidChangePointEstimator(CatalogUtils.GetEnvironment(catalog), outputColumnName, confidence, changeHistoryLength, inputColumnName, martingale, eps); @@ -45,11 +45,11 @@ public static IidChangePointEstimator DetectIndependentIdenticallyDistributedCha /// /// /// /// /// - public static IidSpikeEstimator DetectIndependentIdenticallyDistributedSpike(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, + public static IidSpikeEstimator DetectIidSpike(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, int confidence, int pvalueHistoryLength, AnomalySide side = AnomalySide.TwoSided) => new IidSpikeEstimator(CatalogUtils.GetEnvironment(catalog), outputColumnName, confidence, pvalueHistoryLength, inputColumnName, side); From ac638e6ac909fb97dd9a9b067ef215695eb5074b Mon Sep 17 00:00:00 2001 From: Senja Filipi Date: Mon, 11 Mar 2019 12:14:44 -0700 Subject: [PATCH 3/6] keeping the acronym in the name, but not in documentation --- ...sDetectChangePoint.cs => SsaDetectChangePoint.cs} | 6 +++--- ...ctrumAnalysisDetectSpike.cs => SsaDetectSpike.cs} | 6 +++--- .../TimeSeriesStatic.cs | 4 ++-- src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs | 12 ++++++------ 4 files changed, 14 insertions(+), 14 deletions(-) rename docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/{SingularSpectrumAnalysisDetectChangePoint.cs => SsaDetectChangePoint.cs} (95%) rename docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/{SingularSpectrumAnalysisDetectSpike.cs => SsaDetectSpike.cs} (94%) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SingularSpectrumAnalysisDetectChangePoint.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SsaDetectChangePoint.cs similarity index 95% rename from docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SingularSpectrumAnalysisDetectChangePoint.cs rename to docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SsaDetectChangePoint.cs index adb09a709e..8ce042b68b 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SingularSpectrumAnalysisDetectChangePoint.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SsaDetectChangePoint.cs @@ -6,7 +6,7 @@ namespace Microsoft.ML.Samples.Dynamic { - public static class SingularSpectrumAnalysisDetectChangePoint + public static class SsaDetectChangePoint { class ChangePointPrediction { @@ -54,7 +54,7 @@ public static void Example() var outputColumnName = nameof(ChangePointPrediction.Prediction); // The transformed data. - var transformedData = ml.Transforms.SingularSpectrumAnalysisDetectChangePoint(outputColumnName, inputColumnName, 95, 8, TrainingSize, SeasonalitySize + 1).Fit(dataView).Transform(dataView); + var transformedData = ml.Transforms.SsaDetectChangePoint(outputColumnName, inputColumnName, 95, 8, TrainingSize, SeasonalitySize + 1).Fit(dataView).Transform(dataView); // Getting the data of the newly created column as an IEnumerable of ChangePointPrediction. var predictionColumn = ml.Data.CreateEnumerable(transformedData, reuseRowObject: false); @@ -115,7 +115,7 @@ public static void SsaChangePointDetectorPrediction() var outputColumnName = nameof(ChangePointPrediction.Prediction); // Train the change point detector. - ITransformer model = ml.Transforms.SingularSpectrumAnalysisDetectChangePoint(outputColumnName, inputColumnName, 95, 8, TrainingSize, SeasonalitySize + 1).Fit(dataView); + ITransformer model = ml.Transforms.SsaDetectChangePoint(outputColumnName, inputColumnName, 95, 8, TrainingSize, SeasonalitySize + 1).Fit(dataView); // Create a prediction engine from the model for feeding new data. var engine = model.CreateTimeSeriesPredictionFunction(ml); diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SingularSpectrumAnalysisDetectSpike.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SsaDetectSpike.cs similarity index 94% rename from docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SingularSpectrumAnalysisDetectSpike.cs rename to docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SsaDetectSpike.cs index 553abfcc9f..eb6b8bd0bb 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SingularSpectrumAnalysisDetectSpike.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SsaDetectSpike.cs @@ -6,7 +6,7 @@ namespace Microsoft.ML.Samples.Dynamic { - public static class SingularSpectrumAnalysisDetectSpike + public static class SsaDetectSpike { class SsaSpikeData { @@ -55,7 +55,7 @@ public static void SsaSpikeDetectorTransform() var outputColumnName = nameof(SsaSpikePrediction.Prediction); // The transformed data. - var transformedData = ml.Transforms.SingularSpectrumAnalysisDetectSpike(outputColumnName, inputColumnName, 95, 8, TrainingSize, SeasonalitySize + 1).Fit(dataView).Transform(dataView); + var transformedData = ml.Transforms.SsaDetectSpike(outputColumnName, inputColumnName, 95, 8, TrainingSize, SeasonalitySize + 1).Fit(dataView).Transform(dataView); // Getting the data of the newly created column as an IEnumerable of SsaSpikePrediction. var predictionColumn = ml.Data.CreateEnumerable(transformedData, reuseRowObject: false); @@ -117,7 +117,7 @@ public static void SsaSpikeDetectorPrediction() var outputColumnName = nameof(SsaSpikePrediction.Prediction); // Train the change point detector. - ITransformer model = ml.Transforms.SingularSpectrumAnalysisDetectSpike(outputColumnName, inputColumnName, 95, 8, TrainingSize, SeasonalitySize + 1).Fit(dataView); + ITransformer model = ml.Transforms.SsaDetectSpike(outputColumnName, inputColumnName, 95, 8, TrainingSize, SeasonalitySize + 1).Fit(dataView); // Create a prediction engine from the model for feeding new data. var engine = model.CreateTimeSeriesPredictionFunction(ml); diff --git a/src/Microsoft.ML.TimeSeries.StaticPipe/TimeSeriesStatic.cs b/src/Microsoft.ML.TimeSeries.StaticPipe/TimeSeriesStatic.cs index f41593556b..807e1672c2 100644 --- a/src/Microsoft.ML.TimeSeries.StaticPipe/TimeSeriesStatic.cs +++ b/src/Microsoft.ML.TimeSeries.StaticPipe/TimeSeriesStatic.cs @@ -200,7 +200,7 @@ public override IEstimator Reconcile(IHostEnvironment env, { Contracts.Assert(toOutput.Length == 1); var outCol = (OutColumn)toOutput[0]; - return new MLContext().Transforms.SingularSpectrumAnalysisDetectChangePoint( + return new MLContext().Transforms.SsaDetectChangePoint( outputNames[outCol], inputNames[outCol.Input], _confidence, @@ -282,7 +282,7 @@ public override IEstimator Reconcile(IHostEnvironment env, { Contracts.Assert(toOutput.Length == 1); var outCol = (OutColumn)toOutput[0]; - return new MLContext().Transforms.SingularSpectrumAnalysisDetectSpike( + return new MLContext().Transforms.SsaDetectSpike( outputNames[outCol], inputNames[outCol.Input], _confidence, diff --git a/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs b/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs index 79699d70e6..c13d0e2f7a 100644 --- a/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs +++ b/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs @@ -24,7 +24,7 @@ public static class TimeSeriesCatalog /// /// /// /// /// @@ -45,7 +45,7 @@ public static IidChangePointEstimator DetectIidChangePoint(this TransformsCatalo /// /// /// /// /// @@ -70,11 +70,11 @@ public static IidSpikeEstimator DetectIidSpike(this TransformsCatalog catalog, s /// /// /// /// /// - public static SsaChangePointEstimator SingularSpectrumAnalysisDetectChangePoint(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, + public static SsaChangePointEstimator SsaDetectChangePoint(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) => new SsaChangePointEstimator(CatalogUtils.GetEnvironment(catalog), new SsaChangePointDetector.Options @@ -106,11 +106,11 @@ public static SsaChangePointEstimator SingularSpectrumAnalysisDetectChangePoint( /// /// /// /// /// - public static SsaSpikeEstimator SingularSpectrumAnalysisDetectSpike(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, int confidence, int pvalueHistoryLength, + public static SsaSpikeEstimator SsaDetectSpike(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, int 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); } From 003e3fa592a6626623e7a1f58e3faf5ba3ab426d Mon Sep 17 00:00:00 2001 From: Senja Filipi Date: Tue, 12 Mar 2019 14:41:42 -0700 Subject: [PATCH 4/6] fixing typo --- src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs b/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs index c13d0e2f7a..1a505e9322 100644 --- a/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs +++ b/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs @@ -10,7 +10,7 @@ namespace Microsoft.ML public static class TimeSeriesCatalog { /// - /// Create a new instance of that detects a change of in a indiependent identically distributed time series. + /// Create a new instance of that detects a change of in a independent identically distributed time series. /// Detection is based on adaptive kernel density estimations and martingale scores. /// /// The transform's catalog. @@ -33,7 +33,7 @@ public static IidChangePointEstimator DetectIidChangePoint(this TransformsCatalo => new IidChangePointEstimator(CatalogUtils.GetEnvironment(catalog), outputColumnName, confidence, changeHistoryLength, inputColumnName, martingale, eps); /// - /// Create a new instance of that detects a spike in an indiependent identically distributed time series. + /// Create a new instance of that detects a spike in an independent identically distributed time series. /// Detection is based on adaptive kernel density estimations and martingale scores. /// /// The transform's catalog. From 1de52202cb2ec3278612a47779397cd1dc34d22d Mon Sep 17 00:00:00 2001 From: Senja Filipi Date: Thu, 14 Mar 2019 10:16:41 -0700 Subject: [PATCH 5/6] Addressing PR comments --- .../TimeSeries/DetectIidChangePoint.cs | 110 +----------------- .../Transforms/TimeSeries/DetectIidSpike.cs | 74 +----------- .../TimeSeries/SsaDetectChangePoint.cs | 101 +--------------- .../Transforms/TimeSeries/SsaDetectSpike.cs | 102 +--------------- .../TimeSeriesStatic.cs | 12 +- .../ExtensionsCatalog.cs | 16 ++- .../IidChangePointDetector.cs | 3 +- .../IidSpikeDetector.cs | 3 +- .../SsaChangePointDetector.cs | 2 +- .../SsaSpikeDetector.cs | 2 +- .../TimeSeriesStaticTests.cs | 8 +- 11 files changed, 38 insertions(+), 395 deletions(-) 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 3be92cd5fb..d19b1be2e1 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIidChangePoint.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIidChangePoint.cs @@ -4,9 +4,7 @@ using System; using System.Collections.Generic; -using System.IO; using Microsoft.ML.Data; -using Microsoft.ML.Transforms.TimeSeries; namespace Microsoft.ML.Samples.Dynamic { @@ -29,7 +27,7 @@ public IidChangePointData(float value) } // This example creates a time series (list of Data with the i-th element corresponding to the i-th time slot). - // IidChangePointDetector is applied then to identify points where data distribution changed. + // The estimator is applied then to identify points where data distribution changed. public static void Example() { // Create a new ML context, for ML.NET operations. It can be used for exception tracking and logging, @@ -48,7 +46,7 @@ public static void Example() // Convert data to IDataView. var dataView = ml.Data.LoadFromEnumerable(data); - // Setup IidSpikeDetector arguments + // Setup estimator arguments string outputColumnName = nameof(ChangePointPrediction.Prediction); string inputColumnName = nameof(IidChangePointData.Value); @@ -84,109 +82,5 @@ public static void Example() // 7 0 7.00 0.50 0.00 // 7 0 7.00 0.50 0.00 } - - // This example creates a time series (list of Data with the i-th element corresponding to the i-th time slot). - // IidChangePointDetector is applied then to identify points where data distribution changed using time series - // prediction engine. The engine is checkpointed and then loaded back from disk into memory and used for prediction. - public static void IidChangePointDetectorPrediction() - { - // Create a new ML context, for ML.NET operations. It can be used for exception tracking and logging, - // as well as the source of randomness. - var ml = new MLContext(); - - // Generate sample series data with a change - const int Size = 16; - var data = new List(Size); - for (int i = 0; i < Size / 2; i++) - data.Add(new IidChangePointData(5)); - // This is a change point - for (int i = 0; i < Size / 2; i++) - data.Add(new IidChangePointData(7)); - - // Convert data to IDataView. - var dataView = ml.Data.LoadFromEnumerable(data); - - // Setup IidSpikeDetector arguments - string outputColumnName = nameof(ChangePointPrediction.Prediction); - string inputColumnName = nameof(IidChangePointData.Value); - - // Time Series model. - ITransformer model = ml.Transforms.DetectIidChangePoint(outputColumnName, inputColumnName, 95, Size / 4).Fit(dataView); - - // Create a time series prediction engine from the model. - var engine = model.CreateTimeSeriesPredictionFunction(ml); - for(int index = 0; index < 8; index++) - { - // Anomaly change point detection. - var prediction = engine.Predict(new IidChangePointData(5)); - Console.WriteLine("{0}\t{1}\t{2:0.00}\t{3:0.00}\t{4:0.00}", 5, prediction.Prediction[0], - prediction.Prediction[1], prediction.Prediction[2], prediction.Prediction[3]); - } - - // Change point - var changePointPrediction = engine.Predict(new IidChangePointData(7)); - Console.WriteLine("{0}\t{1}\t{2:0.00}\t{3:0.00}\t{4:0.00}", 7, changePointPrediction.Prediction[0], - changePointPrediction.Prediction[1], changePointPrediction.Prediction[2], changePointPrediction.Prediction[3]); - - // Checkpoint the model. - var modelPath = "temp.zip"; - engine.CheckPoint(ml, modelPath); - - // Reference to current time series engine because in the next step "engine" will point to the - // checkpointed model being loaded from disk. - var timeseries1 = engine; - - // Load the model. - using (var file = File.OpenRead(modelPath)) - model = ml.Model.Load(file); - - // Create a time series prediction engine from the checkpointed model. - engine = model.CreateTimeSeriesPredictionFunction(ml); - for (int index = 0; index < 8; index++) - { - // Anomaly change point detection. - var prediction = engine.Predict(new IidChangePointData(7)); - Console.WriteLine("{0}\t{1}\t{2:0.00}\t{3:0.00}\t{4:0.00}", 7, prediction.Prediction[0], - prediction.Prediction[1], prediction.Prediction[2], prediction.Prediction[3]); - } - - // Prediction from the original time series engine should match the prediction from - // check pointed model. - engine = timeseries1; - for (int index = 0; index < 8; index++) - { - // Anomaly change point detection. - var prediction = engine.Predict(new IidChangePointData(7)); - Console.WriteLine("{0}\t{1}\t{2:0.00}\t{3:0.00}\t{4:0.00}", 7, prediction.Prediction[0], - prediction.Prediction[1], prediction.Prediction[2], prediction.Prediction[3]); - } - - // Data Alert Score P-Value Martingale value - // 5 0 5.00 0.50 0.00 <-- Time Series 1. - // 5 0 5.00 0.50 0.00 - // 5 0 5.00 0.50 0.00 - // 5 0 5.00 0.50 0.00 - // 5 0 5.00 0.50 0.00 - // 5 0 5.00 0.50 0.00 - // 5 0 5.00 0.50 0.00 - // 5 0 5.00 0.50 0.00 - // 7 1 7.00 0.00 10298.67 <-- alert is on, predicted changepoint (and model is checkpointed). - - // 7 0 7.00 0.13 33950.16 <-- Time Series 2 : Model loaded back from disk and prediction is made. - // 7 0 7.00 0.26 60866.34 - // 7 0 7.00 0.38 78362.04 - // 7 0 7.00 0.50 0.01 - // 7 0 7.00 0.50 0.00 - // 7 0 7.00 0.50 0.00 - // 7 0 7.00 0.50 0.00 - - // 7 0 7.00 0.13 33950.16 <-- Time Series 1 and prediction is made. - // 7 0 7.00 0.26 60866.34 - // 7 0 7.00 0.38 78362.04 - // 7 0 7.00 0.50 0.01 - // 7 0 7.00 0.50 0.00 - // 7 0 7.00 0.50 0.00 - // 7 0 7.00 0.50 0.00 - } } } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIidSpike.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIidSpike.cs index ac4035e720..d43b581842 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIidSpike.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectIidSpike.cs @@ -25,7 +25,7 @@ class IidSpikePrediction } // This example creates a time series (list of Data with the i-th element corresponding to the i-th time slot). - // IidSpikeDetector is applied then to identify spiking points in the series. + // The estimator is applied then to identify spiking points in the series. public static void Example() { // Create a new ML context, for ML.NET operations. It can be used for exception tracking and logging, @@ -45,7 +45,7 @@ public static void Example() // Convert data to IDataView. var dataView = ml.Data.LoadFromEnumerable(data); - // Setup IidSpikeDetector arguments + // Setup the estimator arguments string outputColumnName = nameof(IidSpikePrediction.Prediction); string inputColumnName = nameof(IidSpikeData.Value); @@ -75,75 +75,5 @@ public static void Example() // 0 5.00 0.50 // 0 5.00 0.50 } - - public static void IidSpikeDetectorPrediction() - { - // Create a new ML context, for ML.NET operations. It can be used for exception tracking and logging, - // as well as the source of randomness. - var ml = new MLContext(); - - // Generate sample series data with a spike - const int Size = 10; - var data = new List(Size); - for (int i = 0; i < Size / 2; i++) - data.Add(new IidSpikeData(5)); - // This is a spike - data.Add(new IidSpikeData(10)); - for (int i = 0; i < Size / 2; i++) - data.Add(new IidSpikeData(5)); - - // Convert data to IDataView. - var dataView = ml.Data.LoadFromEnumerable(data); - - // Setup IidSpikeDetector arguments - string outputColumnName = nameof(IidSpikePrediction.Prediction); - string inputColumnName = nameof(IidSpikeData.Value); - // The transformed model. - ITransformer model = ml.Transforms.DetectIidSpike(outputColumnName, inputColumnName, 95, Size).Fit(dataView); - - // Create a time series prediction engine from the model. - var engine = model.CreateTimeSeriesPredictionFunction(ml); - for (int index = 0; index < 5; index++) - { - // Anomaly spike detection. - var prediction = engine.Predict(new IidSpikeData(5)); - Console.WriteLine("{0}\t{1}\t{2:0.00}\t{3:0.00}", 5, prediction.Prediction[0], - prediction.Prediction[1], prediction.Prediction[2]); - } - - // Spike. - var spikePrediction = engine.Predict(new IidSpikeData(10)); - Console.WriteLine("{0}\t{1}\t{2:0.00}\t{3:0.00}", 10, spikePrediction.Prediction[0], - spikePrediction.Prediction[1], spikePrediction.Prediction[2]); - - // Checkpoint the model. - var modelPath = "temp.zip"; - engine.CheckPoint(ml, modelPath); - - // Load the model. - using (var file = File.OpenRead(modelPath)) - model = ml.Model.Load(file); - - for (int index = 0; index < 5; index++) - { - // Anomaly spike detection. - var prediction = engine.Predict(new IidSpikeData(5)); - Console.WriteLine("{0}\t{1}\t{2:0.00}\t{3:0.00}", 5, prediction.Prediction[0], - prediction.Prediction[1], prediction.Prediction[2]); - } - - // Data Alert Score P-Value - // 5 0 5.00 0.50 - // 5 0 5.00 0.50 - // 5 0 5.00 0.50 - // 5 0 5.00 0.50 - // 5 0 5.00 0.50 - // 10 1 10.00 0.00 <-- alert is on, predicted spike (check-point model) - // 5 0 5.00 0.26 <-- load model from disk. - // 5 0 5.00 0.26 - // 5 0 5.00 0.50 - // 5 0 5.00 0.50 - // 5 0 5.00 0.50 - } } } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SsaDetectChangePoint.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SsaDetectChangePoint.cs index 8ce042b68b..053ea4a4b6 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SsaDetectChangePoint.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SsaDetectChangePoint.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using System.IO; using Microsoft.ML.Data; -using Microsoft.ML.Transforms.TimeSeries; namespace Microsoft.ML.Samples.Dynamic { @@ -25,9 +23,8 @@ public SsaChangePointData(float value) } // This example creates a time series (list of Data with the i-th element corresponding to the i-th time slot). - // SsaChangePointDetector is applied then to identify points where data distribution changed. - // SsaChangePointDetector differs from IidChangePointDetector in that it can account for temporal seasonality - // in the data. + // The estimator is applied then to identify points where data distribution changed. + // This estimator can account for temporal seasonality in the data. public static void Example() { // Create a new ML context, for ML.NET operations. It can be used for exception tracking and logging, @@ -49,12 +46,12 @@ public static void Example() // Convert data to IDataView. var dataView = ml.Data.LoadFromEnumerable(data); - // Setup SsaChangePointDetector arguments + // Setup estimator arguments var inputColumnName = nameof(SsaChangePointData.Value); var outputColumnName = nameof(ChangePointPrediction.Prediction); // The transformed data. - var transformedData = ml.Transforms.SsaDetectChangePoint(outputColumnName, inputColumnName, 95, 8, TrainingSize, SeasonalitySize + 1).Fit(dataView).Transform(dataView); + var transformedData = ml.Transforms.DetectChangePointBySsa(outputColumnName, inputColumnName, 95, 8, TrainingSize, SeasonalitySize + 1).Fit(dataView).Transform(dataView); // Getting the data of the newly created column as an IEnumerable of ChangePointPrediction. var predictionColumn = ml.Data.CreateEnumerable(transformedData, reuseRowObject: false); @@ -89,95 +86,5 @@ public static void Example() // 300 0 270.40 0.01 3578470.47 // 400 0 357.11 0.03 45298370.86 } - - // This example shows change point detection as above, but demonstrates how to train a model - // that can run predictions on streaming data, and how to persist the trained model and then re-load it. - public static void SsaChangePointDetectorPrediction() - { - // Create a new ML context, for ML.NET operations. It can be used for exception tracking and logging, - // as well as the source of randomness. - var ml = new MLContext(); - - // Generate sample series data with a recurring pattern - const int SeasonalitySize = 5; - const int TrainingSeasons = 3; - const int TrainingSize = SeasonalitySize * TrainingSeasons; - var data = new List(); - for (int i = 0; i < TrainingSeasons; i++) - for (int j = 0; j < SeasonalitySize; j++) - data.Add(new SsaChangePointData(j)); - - // Convert data to IDataView. - var dataView = ml.Data.LoadFromEnumerable(data); - - // Setup SsaChangePointDetector arguments - var inputColumnName = nameof(SsaChangePointData.Value); - var outputColumnName = nameof(ChangePointPrediction.Prediction); - - // Train the change point detector. - ITransformer model = ml.Transforms.SsaDetectChangePoint(outputColumnName, inputColumnName, 95, 8, TrainingSize, SeasonalitySize + 1).Fit(dataView); - - // Create a prediction engine from the model for feeding new data. - var engine = model.CreateTimeSeriesPredictionFunction(ml); - - // Start streaming new data points with no change point to the prediction engine. - Console.WriteLine($"Output from ChangePoint predictions on new data:"); - Console.WriteLine("Data\tAlert\tScore\tP-Value\tMartingale value"); - ChangePointPrediction prediction = null; - for (int i = 0; i < 5; i++) - { - var value = i; - prediction = engine.Predict(new SsaChangePointData(value)); - Console.WriteLine("{0}\t{1}\t{2:0.00}\t{3:0.00}\t{4:0.00}", value, prediction.Prediction[0], prediction.Prediction[1], prediction.Prediction[2], prediction.Prediction[3]); - } - - // Now stream data points that reflect a change in trend. - for (int i = 0; i < 5; i++) - { - var value = (i + 1) * 100; - prediction = engine.Predict(new SsaChangePointData(value)); - Console.WriteLine("{0}\t{1}\t{2:0.00}\t{3:0.00}\t{4:0.00}", value, prediction.Prediction[0], prediction.Prediction[1], prediction.Prediction[2], prediction.Prediction[3]); - } - - // Now we demonstrate saving and loading the model. - - // Save the model that exists within the prediction engine. - // The engine has been updating this model with every new data point. - var modelPath = "model.zip"; - engine.CheckPoint(ml, modelPath); - - // Load the model. - using (var file = File.OpenRead(modelPath)) - model = ml.Model.Load(file); - - // We must create a new prediction engine from the persisted model. - engine = model.CreateTimeSeriesPredictionFunction(ml); - - // Run predictions on the loaded model. - for (int i = 0; i < 5; i++) - { - var value = (i + 1) * 100; - prediction = engine.Predict(new SsaChangePointData(value)); - Console.WriteLine("{0}\t{1}\t{2:0.00}\t{3:0.00}\t{4:0.00}", value, prediction.Prediction[0], prediction.Prediction[1], prediction.Prediction[2], prediction.Prediction[3]); - } - - // Output from ChangePoint predictions on new data: - // Data Alert Score P-Value Martingale value - // 0 0 - 1.01 0.50 0.00 - // 1 0 - 0.24 0.22 0.00 - // 2 0 - 0.31 0.30 0.00 - // 3 0 0.44 0.01 0.00 - // 4 0 2.16 0.00 0.24 - // 100 0 86.23 0.00 2076098.24 - // 200 0 171.38 0.00 809668524.21 - // 300 1 256.83 0.01 22130423541.93 <-- alert is on, note that delay is expected - // 400 0 326.55 0.04 241162710263.29 - // 500 0 364.82 0.08 597660527041.45 <-- saved to disk - // 100 0 - 58.58 0.15 1096021098844.34 <-- loaded from disk and running new predictions - // 200 0 - 41.24 0.20 97579154688.98 - // 300 0 - 30.61 0.24 95319753.87 - // 400 0 58.87 0.38 14.24 - // 500 0 219.28 0.36 0.05 - } } } diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SsaDetectSpike.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SsaDetectSpike.cs index eb6b8bd0bb..aad760430c 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SsaDetectSpike.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SsaDetectSpike.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using System.IO; using Microsoft.ML.Data; -using Microsoft.ML.Transforms.TimeSeries; namespace Microsoft.ML.Samples.Dynamic { @@ -25,9 +23,8 @@ class SsaSpikePrediction } // This example creates a time series (list of Data with the i-th element corresponding to the i-th time slot). - // SsaSpikeDetector is applied then to identify spiking points in the series. - // SsaSpikeDetector differs from IidSpikeDetector in that it can account for temporal seasonality - // in the data. + // The estimator is applied then to identify spiking points in the series. + // This estimator can account for temporal seasonality in the data. public static void SsaSpikeDetectorTransform() { // Create a new ML context, for ML.NET operations. It can be used for exception tracking and logging, @@ -50,12 +47,12 @@ public static void SsaSpikeDetectorTransform() // Convert data to IDataView. var dataView = ml.Data.LoadFromEnumerable(data); - // Setup IidSpikeDetector arguments + // Setup estimator arguments var inputColumnName = nameof(SsaSpikeData.Value); var outputColumnName = nameof(SsaSpikePrediction.Prediction); // The transformed data. - var transformedData = ml.Transforms.SsaDetectSpike(outputColumnName, inputColumnName, 95, 8, TrainingSize, SeasonalitySize + 1).Fit(dataView).Transform(dataView); + var transformedData = ml.Transforms.DetectSpikeBySsa(outputColumnName, inputColumnName, 95, 8, TrainingSize, SeasonalitySize + 1).Fit(dataView).Transform(dataView); // Getting the data of the newly created column as an IEnumerable of SsaSpikePrediction. var predictionColumn = ml.Data.CreateEnumerable(transformedData, reuseRowObject: false); @@ -91,96 +88,5 @@ public static void SsaSpikeDetectorTransform() // 3 0 - 16.50 0.29 // 4 0 - 29.82 0.21 } - - // This example shows spike detection as above, but demonstrates how to train a model - // that can run predictions on streaming data, and how to persist the trained model and then re-load it. - public static void SsaSpikeDetectorPrediction() - { - // Create a new ML context, for ML.NET operations. It can be used for exception tracking and logging, - // as well as the source of randomness. - var ml = new MLContext(); - - // Generate sample series data with a recurring pattern - const int SeasonalitySize = 5; - const int TrainingSeasons = 3; - const int TrainingSize = SeasonalitySize * TrainingSeasons; - var data = new List(); - for (int i = 0; i < TrainingSeasons; i++) - for (int j = 0; j < SeasonalitySize; j++) - data.Add(new SsaSpikeData(j)); - - // Convert data to IDataView. - var dataView = ml.Data.LoadFromEnumerable(data); - - // Setup IidSpikeDetector arguments - var inputColumnName = nameof(SsaSpikeData.Value); - var outputColumnName = nameof(SsaSpikePrediction.Prediction); - - // Train the change point detector. - ITransformer model = ml.Transforms.SsaDetectSpike(outputColumnName, inputColumnName, 95, 8, TrainingSize, SeasonalitySize + 1).Fit(dataView); - - // Create a prediction engine from the model for feeding new data. - var engine = model.CreateTimeSeriesPredictionFunction(ml); - - // Start streaming new data points with no change point to the prediction engine. - Console.WriteLine($"Output from spike predictions on new data:"); - Console.WriteLine("Data\tAlert\tScore\tP-Value"); - SsaSpikePrediction prediction = null; - for (int j = 0; j < 2; j++) - { - for (int i = 0; i < 5; i++) - { - var value = i; - prediction = engine.Predict(new SsaSpikeData(value)); - Console.WriteLine("{0}\t{1}\t{2:0.00}\t{3:0.00}", value, prediction.Prediction[0], prediction.Prediction[1], prediction.Prediction[2]); - } - } - - // Now send a data point that reflects a spike. - var newValue = 100; - prediction = engine.Predict(new SsaSpikeData(newValue)); - Console.WriteLine("{0}\t{1}\t{2:0.00}\t{3:0.00}", newValue, prediction.Prediction[0], prediction.Prediction[1], prediction.Prediction[2]); - - // Now we demonstrate saving and loading the model. - - // Save the model that exists within the prediction engine. - // The engine has been updating this model with every new data point. - var modelPath = "model.zip"; - engine.CheckPoint(ml, modelPath); - - // Load the model. - using (var file = File.OpenRead(modelPath)) - model = ml.Model.Load(file); - - // We must create a new prediction engine from the persisted model. - engine = model.CreateTimeSeriesPredictionFunction(ml); - - // Run predictions on the loaded model. - for (int i = 0; i < 5; i++) - { - var value = i; - prediction = engine.Predict(new SsaSpikeData(value)); - Console.WriteLine("{0}\t{1}\t{2:0.00}\t{3:0.00}", value, prediction.Prediction[0], prediction.Prediction[1], prediction.Prediction[2]); - } - - // Output from spike predictions on new data: - // Data Alert Score P-Value - // 0 0 - 1.01 0.50 - // 1 0 - 0.24 0.22 - // 2 0 - 0.31 0.30 - // 3 0 0.44 0.01 - // 4 0 2.16 0.00 - // 0 0 - 0.78 0.27 - // 1 0 - 0.80 0.30 - // 2 0 - 0.84 0.31 - // 3 0 0.33 0.31 - // 4 0 2.21 0.07 - // 100 1 86.17 0.00 <-- alert is on, predicted spike - // 0 0 - 2.74 0.40 <-- saved to disk, re-loaded, and running new predictions - // 1 0 - 1.47 0.42 - // 2 0 - 17.50 0.24 - // 3 0 - 30.82 0.16 - // 4 0 - 23.24 0.28 - } } } diff --git a/src/Microsoft.ML.TimeSeries.StaticPipe/TimeSeriesStatic.cs b/src/Microsoft.ML.TimeSeries.StaticPipe/TimeSeriesStatic.cs index 807e1672c2..74c1f22e93 100644 --- a/src/Microsoft.ML.TimeSeries.StaticPipe/TimeSeriesStatic.cs +++ b/src/Microsoft.ML.TimeSeries.StaticPipe/TimeSeriesStatic.cs @@ -70,7 +70,7 @@ public override IEstimator Reconcile(IHostEnvironment env, /// /// Perform IID change point detection over a column of time series data. See . /// - public static Vector IidChangePointDetect( + public static Vector DetectIidChangePoint( this Scalar input, int confidence, int changeHistoryLength, @@ -133,7 +133,7 @@ public override IEstimator Reconcile(IHostEnvironment env, /// /// Perform IID spike detection over a column of time series data. See . /// - public static Vector IidSpikeDetect( + public static Vector DetectIidSpike( this Scalar input, int confidence, int pvalueHistoryLength, @@ -200,7 +200,7 @@ public override IEstimator Reconcile(IHostEnvironment env, { Contracts.Assert(toOutput.Length == 1); var outCol = (OutColumn)toOutput[0]; - return new MLContext().Transforms.SsaDetectChangePoint( + return new MLContext().Transforms.DetectChangePointBySsa( outputNames[outCol], inputNames[outCol.Input], _confidence, @@ -216,7 +216,7 @@ public override IEstimator Reconcile(IHostEnvironment env, /// /// Perform SSA change point detection over a column of time series data. See . /// - public static Vector SsaChangePointDetect( + public static Vector DetectChangePointBySsa( this Scalar input, int confidence, int changeHistoryLength, @@ -282,7 +282,7 @@ public override IEstimator Reconcile(IHostEnvironment env, { Contracts.Assert(toOutput.Length == 1); var outCol = (OutColumn)toOutput[0]; - return new MLContext().Transforms.SsaDetectSpike( + return new MLContext().Transforms.DetectSpikeBySsa( outputNames[outCol], inputNames[outCol.Input], _confidence, @@ -297,7 +297,7 @@ public override IEstimator Reconcile(IHostEnvironment env, /// /// Perform SSA spike detection over a column of time series data. See . /// - public static Vector SsaSpikeDetect( + public static Vector DetectSpikeBySsa( this Scalar input, int confidence, int changeHistoryLength, diff --git a/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs b/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs index 1a505e9322..23c6def8da 100644 --- a/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs +++ b/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs @@ -10,7 +10,8 @@ namespace Microsoft.ML public static class TimeSeriesCatalog { /// - /// Create a new instance of that detects a change of in a independent identically distributed time series. + /// Create a new instance of that detects a change of in an + /// independent identically distributed (i.i.d.) time series. /// Detection is based on adaptive kernel density estimations and martingale scores. /// /// The transform's catalog. @@ -33,7 +34,8 @@ public static IidChangePointEstimator DetectIidChangePoint(this TransformsCatalo => new IidChangePointEstimator(CatalogUtils.GetEnvironment(catalog), outputColumnName, confidence, changeHistoryLength, inputColumnName, martingale, eps); /// - /// Create a new instance of that detects a spike in an independent identically distributed time series. + /// Create a new instance of that detects a spike in an + /// independent identically distributed (i.i.d.) time series. /// Detection is based on adaptive kernel density estimations and martingale scores. /// /// The transform's catalog. @@ -54,7 +56,8 @@ public static IidSpikeEstimator DetectIidSpike(this TransformsCatalog catalog, s => new IidSpikeEstimator(CatalogUtils.GetEnvironment(catalog), outputColumnName, confidence, pvalueHistoryLength, inputColumnName, side); /// - /// Create a new instance of for detecting a change in a time series signal using Singular Spectrum Analysis. + /// Create a new instance of for detecting a change in a time series signal + /// using Singular Spectrum Analysis (SSA). /// /// The transform's catalog. /// Name of the column resulting from the transformation of . @@ -74,7 +77,7 @@ public static IidSpikeEstimator DetectIidSpike(this TransformsCatalog catalog, s /// ]]> /// /// - public static SsaChangePointEstimator SsaDetectChangePoint(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, + 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) => new SsaChangePointEstimator(CatalogUtils.GetEnvironment(catalog), new SsaChangePointDetector.Options @@ -91,7 +94,8 @@ public static SsaChangePointEstimator SsaDetectChangePoint(this TransformsCatalo }); /// - /// Create a new instance of for detecting a spike in a time series signal using Singular Spectrum Analysis. + /// Create a new instance of for detecting a spike in a time series signal + /// using Singular Spectrum Analysis (SSA). /// /// The transform's catalog. /// Name of the column resulting from the transformation of . @@ -110,7 +114,7 @@ public static SsaChangePointEstimator SsaDetectChangePoint(this TransformsCatalo /// ]]> /// /// - public static SsaSpikeEstimator SsaDetectSpike(this TransformsCatalog catalog, string outputColumnName, string inputColumnName, int confidence, int pvalueHistoryLength, + 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) => 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 faa0770a9e..6f743ecf16 100644 --- a/src/Microsoft.ML.TimeSeries/IidChangePointDetector.cs +++ b/src/Microsoft.ML.TimeSeries/IidChangePointDetector.cs @@ -192,7 +192,8 @@ private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, Dat } /// - /// The for detecting a signal change on an Independent Identically Distributed time series. + /// The for detecting a signal change on an + /// independent identically distributed (i.i.d.) time series. /// Detection is based on adaptive kernel density estimation and martingales. /// public sealed class IidChangePointEstimator : TrivialEstimator diff --git a/src/Microsoft.ML.TimeSeries/IidSpikeDetector.cs b/src/Microsoft.ML.TimeSeries/IidSpikeDetector.cs index 01af69aaa9..b7e38552d6 100644 --- a/src/Microsoft.ML.TimeSeries/IidSpikeDetector.cs +++ b/src/Microsoft.ML.TimeSeries/IidSpikeDetector.cs @@ -172,7 +172,8 @@ private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, Dat } /// - /// The for detecting a signal spike on an Independent Identically Distributed time series. + /// The for detecting a signal spike on an + /// independent identically distributed (i.i.d.) time series. /// Detection is based on adaptive kernel density estimation. /// public sealed class IidSpikeEstimator : TrivialEstimator diff --git a/src/Microsoft.ML.TimeSeries/SsaChangePointDetector.cs b/src/Microsoft.ML.TimeSeries/SsaChangePointDetector.cs index c32cd8b63d..bdec9bb64b 100644 --- a/src/Microsoft.ML.TimeSeries/SsaChangePointDetector.cs +++ b/src/Microsoft.ML.TimeSeries/SsaChangePointDetector.cs @@ -201,7 +201,7 @@ private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, Dat } /// - /// The for detecting a signal change through Singular Spectrum Analysis. of time series. + /// The for detecting a signal change through Singular Spectrum Analysis (SSA). of time series. /// public sealed class SsaChangePointEstimator : IEstimator { diff --git a/src/Microsoft.ML.TimeSeries/SsaSpikeDetector.cs b/src/Microsoft.ML.TimeSeries/SsaSpikeDetector.cs index ca2ba90e58..81abd920d4 100644 --- a/src/Microsoft.ML.TimeSeries/SsaSpikeDetector.cs +++ b/src/Microsoft.ML.TimeSeries/SsaSpikeDetector.cs @@ -182,7 +182,7 @@ private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, Dat } /// - /// The for detecting a signal spike through Singular Spectrum Analysis. of time series. + /// The for detecting a signal spike through Singular Spectrum Analysis (SSA) of time series. /// public sealed class SsaSpikeEstimator : IEstimator { diff --git a/test/Microsoft.ML.TimeSeries.Tests/TimeSeriesStaticTests.cs b/test/Microsoft.ML.TimeSeries.Tests/TimeSeriesStaticTests.cs index bb3feddbc9..da85ad5be4 100644 --- a/test/Microsoft.ML.TimeSeries.Tests/TimeSeriesStaticTests.cs +++ b/test/Microsoft.ML.TimeSeries.Tests/TimeSeriesStaticTests.cs @@ -58,7 +58,7 @@ public void ChangeDetection() var staticData = dataView.AssertStatic(env, c => new { Value = c.R4.Scalar }); // Build the pipeline var staticLearningPipeline = staticData.MakeNewEstimator() - .Append(r => r.Value.IidChangePointDetect(80, Size)); + .Append(r => r.Value.DetectIidChangePoint(80, Size)); // Train var detector = staticLearningPipeline.Fit(staticData); // Transform @@ -104,7 +104,7 @@ public void ChangePointDetectionWithSeasonality() var staticData = dataView.AssertStatic(env, c => new { Value = c.R4.Scalar }); // Build the pipeline var staticLearningPipeline = staticData.MakeNewEstimator() - .Append(r => r.Value.SsaChangePointDetect(95, ChangeHistorySize, MaxTrainingSize, SeasonalitySize)); + .Append(r => r.Value.DetectChangePointBySsa(95, ChangeHistorySize, MaxTrainingSize, SeasonalitySize)); // Train var detector = staticLearningPipeline.Fit(staticData); // Transform @@ -148,7 +148,7 @@ public void SpikeDetection() var staticData = dataView.AssertStatic(env, c => new { Value = c.R4.Scalar }); // Build the pipeline var staticLearningPipeline = staticData.MakeNewEstimator() - .Append(r => r.Value.IidSpikeDetect(80, PvalHistoryLength)); + .Append(r => r.Value.DetectIidSpike(80, PvalHistoryLength)); // Train var detector = staticLearningPipeline.Fit(staticData); // Transform @@ -203,7 +203,7 @@ public void SsaSpikeDetection() var staticData = dataView.AssertStatic(env, c => new { Value = c.R4.Scalar }); // Build the pipeline var staticLearningPipeline = staticData.MakeNewEstimator() - .Append(r => r.Value.SsaSpikeDetect(80, ChangeHistoryLength, TrainingWindowSize, SeasonalityWindowSize)); + .Append(r => r.Value.DetectSpikeBySsa(80, ChangeHistoryLength, TrainingWindowSize, SeasonalityWindowSize)); // Train var detector = staticLearningPipeline.Fit(staticData); // Transform From 632876f5762da90f5619052b9e752bb4d405b9b3 Mon Sep 17 00:00:00 2001 From: Senja Filipi Date: Thu, 14 Mar 2019 10:33:03 -0700 Subject: [PATCH 6/6] PR comments. --- .../{SsaDetectChangePoint.cs => DetectChangePointBySsa.cs} | 2 +- .../TimeSeries/{SsaDetectSpike.cs => DetectSpikeBySsa.cs} | 2 +- src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs | 4 ++-- src/Microsoft.ML.TimeSeries/SsaChangePointDetector.cs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) rename docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/{SsaDetectChangePoint.cs => DetectChangePointBySsa.cs} (98%) rename docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/{SsaDetectSpike.cs => DetectSpikeBySsa.cs} (98%) diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SsaDetectChangePoint.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectChangePointBySsa.cs similarity index 98% rename from docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SsaDetectChangePoint.cs rename to docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectChangePointBySsa.cs index 053ea4a4b6..268c6865e7 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SsaDetectChangePoint.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectChangePointBySsa.cs @@ -4,7 +4,7 @@ namespace Microsoft.ML.Samples.Dynamic { - public static class SsaDetectChangePoint + public static class DetectChangePointBySsa { class ChangePointPrediction { diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SsaDetectSpike.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectSpikeBySsa.cs similarity index 98% rename from docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SsaDetectSpike.cs rename to docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectSpikeBySsa.cs index aad760430c..9c6f89307f 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/SsaDetectSpike.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectSpikeBySsa.cs @@ -4,7 +4,7 @@ namespace Microsoft.ML.Samples.Dynamic { - public static class SsaDetectSpike + public static class DetectSpikeBySsa { class SsaSpikeData { diff --git a/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs b/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs index 23c6def8da..aa64de5495 100644 --- a/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs +++ b/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs @@ -73,7 +73,7 @@ public static IidSpikeEstimator DetectIidSpike(this TransformsCatalog catalog, s /// /// /// /// /// @@ -110,7 +110,7 @@ public static SsaChangePointEstimator DetectChangePointBySsa(this TransformsCata /// /// /// /// /// diff --git a/src/Microsoft.ML.TimeSeries/SsaChangePointDetector.cs b/src/Microsoft.ML.TimeSeries/SsaChangePointDetector.cs index bdec9bb64b..fe6d6c4dda 100644 --- a/src/Microsoft.ML.TimeSeries/SsaChangePointDetector.cs +++ b/src/Microsoft.ML.TimeSeries/SsaChangePointDetector.cs @@ -201,7 +201,7 @@ private static IRowMapper Create(IHostEnvironment env, ModelLoadContext ctx, Dat } /// - /// The for detecting a signal change through Singular Spectrum Analysis (SSA). of time series. + /// The for detecting a signal change through Singular Spectrum Analysis (SSA) of time series. /// public sealed class SsaChangePointEstimator : IEstimator {