Documentation ¶
Overview ¶
Package hw implements the Holt-Winters forecasting algorithm.
Index ¶
- type HoltWinters
- func (hw *HoltWinters) Configure(config interface{}) error
- func (se *HoltWinters) Evaluate(ctx context.Context, sf *dataframe.SeriesFloat64, ...) (float64, error)
- func (hw *HoltWinters) Load(ctx context.Context, sf *dataframe.SeriesFloat64, r *dataframe.Range) error
- func (hw *HoltWinters) Predict(ctx context.Context, n uint) (*dataframe.SeriesFloat64, []forecast.Confidence, error)
- type HoltWintersConfig
- type Method
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HoltWinters ¶
type HoltWinters struct {
// contains filtered or unexported fields
}
HoltWinters represents the Holt-Winters algorithm for time-series forecasting.
See: https://otexts.com/fpp2/holt-winters.html
func NewHoltWinters ¶
func NewHoltWinters() *HoltWinters
NewHoltWinters creates a new HoltWinters object.
func (*HoltWinters) Configure ¶
func (hw *HoltWinters) Configure(config interface{}) error
Configure sets the various parameters for the HW algorithm. config must be a HoltWintersConfig.
func (*HoltWinters) Evaluate ¶
func (se *HoltWinters) Evaluate(ctx context.Context, sf *dataframe.SeriesFloat64, evalFunc forecast.EvaluationFunc) (float64, error)
Evaluate will measure the quality of the predicted values based on the evaluation calculation defined by evalFunc. It will compare the error between sf and the values from the end of the loaded data ("validation set"). sf is usually the output of the Predict method.
NOTE: You can use the functions directly from the validation subpackage if you need to do something other than that described above.
func (*HoltWinters) Load ¶
func (hw *HoltWinters) Load(ctx context.Context, sf *dataframe.SeriesFloat64, r *dataframe.Range) error
Load loads historical data.
sf is the series containing historical seasonal data. It must be at least a full season. For optimal results use at least two full seasons.
r is used to limit which rows of sf are loaded. Prediction will always begin from the row after that defined by r. r can be thought of as defining a "training set".
NOTE: Holt-Winters algorithm does not tolerate nil values. You may need to use the interpolation subpackage.
func (*HoltWinters) Predict ¶
func (hw *HoltWinters) Predict(ctx context.Context, n uint) (*dataframe.SeriesFloat64, []forecast.Confidence, error)
Predict forecasts the next n values for the loaded data.
type HoltWintersConfig ¶
type HoltWintersConfig struct { // Alpha must be between 0 and 1. The closer Alpha is to 1, the more the algorithm // prioritizes recent values over past values. Alpha float64 // Beta must be between 0 and 1. The closer Beta is to 1, the trend component will prioritize // recent values over past values. Beta float64 // Gamma must be between 0 and 1. The closer Gamma is to 1, the more recent seasonal pattern is prioritized. Gamma float64 // Period can be understood as follows: // // A season is a fixed length of time that contains the full repetition. // You might think your data repeats daily (there’s a peak at 2pm every day), but if the weekend has different behavior (there’s no peak at 2pm on Sunday) then your season is really a week, not a day. // Within the season, there are periods, which is the granularity of prediction. // If you want to model a value for every hour of every day within a week, your season is 168 hours long and your period is 1 hour. // // Therefore, a complete season's data consists of L periods. In the above example, L is 168. L is what you set for the Period config value. Period uint // SeasonalMethod sets whether the model is additive or multiplicative. // The default is additive. SeasonalMethod Method // ConfidenceLevels are values between 0 and 1 (exclusive) that return the associated // confidence intervals for each forecasted value. // // See: https://otexts.com/fpp2/prediction-intervals.html ConfidenceLevels []float64 }
HoltWintersConfig is used to configure the Holt-Winters algorithm.
NOTE: Holt-Winters algorithm does not tolerate nil values. You may need to use the interpolation subpackage.
See: https://otexts.com/fpp2/holt-winters.html
func (*HoltWintersConfig) Validate ¶
func (cfg *HoltWintersConfig) Validate() error
Validate checks if the config is valid.