View Source Soothsayer (soothsayer v0.3.1)
The main module for the Soothsayer library, providing functions for creating, fitting, and using time series forecasting models.
Summary
Functions
Fits the Soothsayer model to the provided data.
Creates a new Soothsayer model with the given configuration.
Makes predictions using a fitted Soothsayer model.
Makes predictions and returns the individual components (trend, seasonality) using a fitted Soothsayer model.
Functions
@spec fit(Soothsayer.Model.t(), Explorer.DataFrame.t()) :: Soothsayer.Model.t()
Fits the Soothsayer model to the provided data.
Parameters
model
- ASoothsayer.Model
struct.data
- AnExplorer.DataFrame
containing the training data.
Returns
An updated Soothsayer.Model
struct with fitted parameters.
Examples
iex> model = Soothsayer.new()
iex> data = Explorer.DataFrame.new(%{"ds" => [...], "y" => [...]})
iex> fitted_model = Soothsayer.fit(model, data)
%Soothsayer.Model{config: %{}, network: %Axon.Node{}, params: %{}}
@spec new(map()) :: Soothsayer.Model.t()
Creates a new Soothsayer model with the given configuration.
Parameters
config
- A map containing the model configuration. Defaults to an empty map.
Returns
A new Soothsayer.Model
struct.
Examples
iex> Soothsayer.new()
%Soothsayer.Model{config: %{trend: %{enabled: true}, seasonality: %{yearly: %{enabled: true, fourier_terms: 6}, weekly: %{enabled: true, fourier_terms: 3}}, epochs: 100, learning_rate: 0.01}, network: %Axon.Node{}, params: nil}
iex> Soothsayer.new(%{epochs: 200, learning_rate: 0.005})
%Soothsayer.Model{config: %{trend: %{enabled: true}, seasonality: %{yearly: %{enabled: true, fourier_terms: 6}, weekly: %{enabled: true, fourier_terms: 3}}, epochs: 200, learning_rate: 0.005}, network: %Axon.Node{}, params: nil}
@spec predict(Soothsayer.Model.t(), Explorer.Series.t()) :: Nx.Tensor.t()
Makes predictions using a fitted Soothsayer model.
Parameters
model
- A fittedSoothsayer.Model
struct.x
- AnExplorer.Series
containing the dates for which to make predictions.
Returns
An Nx.Tensor
containing the predicted values.
Examples
iex> fitted_model = Soothsayer.fit(model, training_data)
iex> future_dates = Explorer.Series.from_list([~D[2023-01-01], ~D[2023-01-02], ~D[2023-01-03]])
iex> predictions = Soothsayer.predict(fitted_model, future_dates)
#Nx.Tensor<
f32[3][1]
[
[1.5],
[2.3],
[3.1]
]
>
@spec predict_components(Soothsayer.Model.t(), Explorer.Series.t()) :: %{ combined: Nx.Tensor.t(), trend: Nx.Tensor.t(), yearly_seasonality: Nx.Tensor.t(), weekly_seasonality: Nx.Tensor.t() }
Makes predictions and returns the individual components (trend, seasonality) using a fitted Soothsayer model.
Parameters
model
- A fittedSoothsayer.Model
struct.x
- AnExplorer.Series
containing the dates for which to make predictions.
Returns
A map containing the predicted values for each component (trend, yearly seasonality, weekly seasonality) and the combined prediction.
Examples
iex> fitted_model = Soothsayer.fit(model, training_data)
iex> future_dates = Explorer.Series.from_list([~D[2023-01-01], ~D[2023-01-02], ~D[2023-01-03]])
iex> predictions = Soothsayer.predict_components(fitted_model, future_dates)
%{
combined: #Nx.Tensor<...>,
trend: #Nx.Tensor<...>,
yearly_seasonality: #Nx.Tensor<...>,
weekly_seasonality: #Nx.Tensor<...>
}