-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add DetectSeasonality as a Helper function in TimeSeries ExtensionDialog #5231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d48ee89
create class PeriodDetectUtils
34567ba
Test period detect
a7b3bd4
math utils
88d8824
restore file
614695c
update license
77c507f
Merge branch 'dev/seasonality' of https://github.com/guinao/machinele…
lisahuamsft 9f8281a
1. Add DetectSeasonality as a helper method in ExtensionsCatalog,
lisahuamsft 2b98245
Change SeasonalityDetector to be internal class
lisahua 177502e
1. Introduce randomnessThreshold as an optional parameter
lisahua b502212
minor float to double type change
lisahua 1ee4c01
Merge branch 'master' of https://github.com/lisahua/machinelearning i…
lisahua 53d5c0d
fix unit tests
lisahua 8609158
address Harish's comments:
lisahua d2eeb71
minor format update
lisahua beed798
update comments
lisahua 16e7e07
minor follow up comment update
lisahua 080e08f
update threshold to p value
lisahua File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/DetectSeasonality.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.ML; | ||
using Microsoft.ML.TimeSeries; | ||
|
||
namespace Samples.Dynamic | ||
{ | ||
public static class DetectSeasonality | ||
{ | ||
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.*/ | ||
var mlContext = new MLContext(); | ||
|
||
// Create a seasonal data as input: y = sin(2 * Pi + x) | ||
var seasonalData = Enumerable.Range(0, 100).Select(x => new TimeSeriesData(Math.Sin(2 * Math.PI + x))); | ||
|
||
// Load the input data as a DataView. | ||
var dataView = mlContext.Data.LoadFromEnumerable(seasonalData); | ||
|
||
/* Two option parameters: | ||
* seasonalityWindowSize: Default value is -1. When set to -1, use the whole input to fit model; | ||
* when set to a positive integer, only the first windowSize number of values will be considered. | ||
* randomnessThreshold: Randomness threshold that specifies how confidence the input values follows | ||
* a predictable pattern recurring as seasonal data. By default, it is set as 0.99. | ||
* The higher the threshold is set, the more strict recurring pattern the | ||
* input values should follow to be determined as seasonal data. | ||
*/ | ||
int period = mlContext.AnomalyDetection.DetectSeasonality( | ||
dataView, | ||
nameof(TimeSeriesData.Value), | ||
seasonalityWindowSize: 40); | ||
|
||
// Print the Seasonality Period result. | ||
Console.WriteLine($"Seasonality Period: #{period}"); | ||
} | ||
|
||
private class TimeSeriesData | ||
{ | ||
public double Value; | ||
|
||
public TimeSeriesData(double value) | ||
{ | ||
Value = value; | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.