Documentation
¶
Overview ¶
Package forecast performs a single linear model fit and predict for a univariate timeseries
Index ¶
- Variables
- type Components
- type FeatureWeight
- type Forecast
- func (f *Forecast) Coefficients() (map[string]float64, error)
- func (f *Forecast) EventComponent() []float64
- func (f *Forecast) FeatureLabels() ([]feature.Feature, error)
- func (f *Forecast) Fit(t []time.Time, y []float64) error
- func (f *Forecast) Intercept() (float64, error)
- func (f *Forecast) Model() (Model, error)
- func (f *Forecast) ModelEq() (string, error)
- func (f *Forecast) Predict(t []time.Time) ([]float64, Components, error)
- func (f *Forecast) Residuals() []float64
- func (f *Forecast) Score(x []time.Time, y []float64) (float64, error)
- func (f *Forecast) Scores() Scores
- func (f *Forecast) SeasonalityComponent() []float64
- func (f *Forecast) TrendComponent() []float64
- type Model
- type Scores
- type Weights
Constants ¶
This section is empty.
Variables ¶
var ( ErrUninitializedForecast = errors.New("uninitialized forecast") ErrInsufficientTrainingData = errors.New("insufficient training data after removing Nans") ErrLabelExists = errors.New("label already exists in TimeDataset") ErrMismatchedDataLen = errors.New("input data has different length than time") ErrFeatureLabelsInitialized = errors.New("feature labels already initialized") ErrNoModelCoefficients = errors.New("no model coefficients from fit") ErrUntrainedForecast = errors.New("forecast has not been trained yet") ErrNoOptionsInModel = errors.New("no options set in model") ErrNoFeaturesForFit = errors.New("no features for fitting") ErrNegativeDataWithLog = errors.New("cannot use log transformation with negative data") ErrNoIntercept = errors.New("no intercept in model") )
var ErrResLenMismatch = errors.New("predicted and actual have different lengths")
var ErrUnknownFeatureType = errors.New("unknown feature type")
Functions ¶
This section is empty.
Types ¶
type Components ¶ added in v0.1.4
type FeatureWeight ¶
type FeatureWeight struct {
Labels map[string]string `json:"labels"`
Type feature.FeatureType `json:"type"`
Value float64 `json:"value"`
}
FeatureWeight represents a feature described with a type e.g. changepoint, labels and the value
func NewFeatureWeight ¶ added in v0.2.0
func NewFeatureWeight(f feature.Feature, val float64) FeatureWeight
type Forecast ¶
type Forecast struct {
// contains filtered or unexported fields
}
Forecast represents a single forecast model of a time series. This is a linear model using coordinate descent to calculate the weights. This will decompose the series into an intercept, trend components (based on changepoint times), and seasonal components.
func New ¶
New creates a new forecast instance withh thhe given options. If none are provided, a default is used
func NewFromModel ¶
NewFromModel creates a new forecast instance given a forecast Model to initialize. This instance can be used for inference immediately and does not need to be trained again.
func (*Forecast) Coefficients ¶
Coefficients returns a forecast model map of coefficients keyed by the string representation of each feature label
func (*Forecast) EventComponent ¶ added in v0.2.11
EventComponent represents the overall event components in the model
func (*Forecast) FeatureLabels ¶
FeatureLabels returns the slice of feature labels in the order of the coefficients
func (*Forecast) Fit ¶
Fit takes the input training data and fits a forecast model for possible changepoints, seasonal components, and intercept
func (*Forecast) Model ¶
Model returns the serializeable format of the forecast model composing of the forecast options, intercept, coefficients with their feature labels, and the model fit scores
func (*Forecast) ModelEq ¶
ModelEq returns a string representation of the model linear equation in the format of y ~ b + m1x1 + m2x2 + ...
func (*Forecast) Predict ¶
Predict takes a slice of times in any order and produces the predicted value for those times given a pre-trained model.
func (*Forecast) Residuals ¶
Residuals returns a slice of values representing the difference between the training data and the fit data
func (*Forecast) Score ¶ added in v0.2.1
Score computes the coefficient of determination of the prediction
func (*Forecast) Scores ¶
Scores returns the fit scores for evaluating how well the resulting model fit the training data
func (*Forecast) SeasonalityComponent ¶
SeasonalityComponent represents the overall seasonal component of the model
func (*Forecast) TrendComponent ¶
TrendComponent represents the overall trend component of the model which is determined by the changepoints.
type Model ¶
type Model struct {
TrainEndTime time.Time `json:"train_end_time"`
Options *options.Options `json:"options"`
Scores *Scores `json:"scores"`
Weights Weights `json:"weights"`
}
Model represents a serializeable format of a forecast storing the forecast options, fit scores, and coefficients
type Scores ¶
type Scores struct {
MSE float64 `json:"mean_squared_error"`
MAPE float64 `json:"mean_average_percent_error"`
R2 float64 `json:"r_squared"`
}
Scores tracks the fit scores
type Weights ¶
type Weights struct {
Coef []FeatureWeight `json:"coefficients"`
}
Weights stores the coefficients for the forecast model
func (*Weights) Coefficients ¶
Coefficients returns a slice copy of the coefficients ignoring the intercept.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package options contains all forecast options for a linear fit of a univariate time series
|
Package options contains all forecast options for a linear fit of a univariate time series |
|
Package util are extra utility methods
|
Package util are extra utility methods |