Builtin Exogenous Effects
Effects that define relationships between variables and the target.
BaseEffect
Bases: BaseObject
Base class for effects.
Effects are objects which are responsible for preparing the data and applying
a specific effect to the forecast. During preparation of the data (which happens in
transform
method), the effect receives the exogenous variables dataframe and can
use them to prepare the jax arrays that will be used at inference time. During
inference time, the predict
method is called, and it should output a new component
to the additive model of Prophetverse.
Remember that Prophetverse's models are Generalized Additive Models, which are composed of many terms summed together to form the final forecast. Each term is represented by an effect.
Children classes should implement the following methods:
-
_fit
(optional): This method is called during fit() of the forecasting and should be used to initialize any necessary parameters or data structures. It receives the exogenous variables dataframe X, the seriesy
, and the scale factorscale
that was used to scale the timeseries. -
_transform
(optional): This method receives the exogenous variables dataframe, and should return an object containing the data needed for the effect. This object will be passed to the predict method asdata
. By default the columns of the dataframe that match the regex pattern are selected, and the result is converted to ajnp.ndarray
. -
_predict
(mandatory): This method receives the output of_transform
and all previously computed effects. It should return the effect values as ajnp.ndarray
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id |
str
|
The id of the effect, by default "". Used to identify the effect in the model. |
required |
regex |
Optional[str]
|
A regex pattern to match the columns of the exogenous variables dataframe, by default None. If None, and _tags["skip_predict_if_no_match"] is True, the effect will be skipped if no columns are found. |
required |
effect_mode |
EFFECT_APPLICATION_TYPE
|
The mode of the effect, either "additive" or "multiplicative", by default "multiplicative". If "multiplicative", the effect multiplies the trend values before returning them. |
required |
Attributes:
Name | Type | Description |
---|---|---|
input_feature_column_names |
List[str]
|
The names of the input feature columns. This is set during the |
should_skip_predict |
bool
|
If True, the effect should be skipped during prediction. This is determined by
the |
Source code in src/prophetverse/effects/base.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
|
input_feature_column_names: List[str]
property
Return the input feature columns names.
should_skip_predict: bool
property
Return if the effect should be skipped by the forecaster.
Returns:
Type | Description |
---|---|
bool
|
If the effect should be skipped by the forecaster. |
__call__(data, predicted_effects)
Run the processes to calculate effect as a function.
Source code in src/prophetverse/effects/base.py
306 307 308 309 310 |
|
fit(y, X, scale=1.0)
Initialize the effect.
This method is called during fit()
of the forecasting model.
It receives the Exogenous variables DataFrame and should be used to initialize
any necessary parameters or data structures, such as detecting the columns that
match the regex pattern.
This method MUST set _input_feature_columns_names to a list of column names
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y |
DataFrame
|
The timeseries dataframe |
required |
X |
DataFrame
|
The DataFrame to initialize the effect. |
required |
scale |
float
|
The scale of the timeseries. For multivariate timeseries, this is a dataframe. For univariate, it is a simple float. |
1.0
|
Returns:
Type | Description |
---|---|
None
|
|
Raises:
Type | Description |
---|---|
ValueError
|
If the effect does not support multivariate data and the DataFrame has more than one level of index. |
Source code in src/prophetverse/effects/base.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
predict(data, predicted_effects=None)
Apply and return the effect values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Any
|
Data obtained from the transformed method. |
required |
predicted_effects |
Dict[str, ndarray]
|
A dictionary containing the predicted effects, by default None. |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
An array with shape (T,1) for univariate timeseries, or (N, T, 1) for multivariate timeseries, where T is the number of timepoints and N is the number of series. |
Source code in src/prophetverse/effects/base.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
|
transform(X, fh)
Prepare input data to be passed to numpyro model.
This method receives the Exogenous variables DataFrame and should return a
the data needed for the effect. Those data will be passed to the predict
method as data
argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X |
DataFrame
|
The input DataFrame containing the exogenous variables for the training time indexes, if passed during fit, or for the forecasting time indexes, if passed during predict. |
required |
fh |
Index
|
The forecasting horizon as a pandas Index. |
required |
Returns:
Type | Description |
---|---|
Any
|
Any object containing the data needed for the effect. The object will be
passed to |
Raises:
Type | Description |
---|---|
ValueError
|
If the effect has not been fitted. |
Source code in src/prophetverse/effects/base.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
|
HillEffect
Bases: BaseAdditiveOrMultiplicativeEffect
Represents a Hill effect in a time series model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
half_max_prior |
Distribution
|
Prior distribution for the half-maximum parameter |
None
|
slope_prior |
Distribution
|
Prior distribution for the slope parameter |
None
|
max_effect_prior |
Distribution
|
Prior distribution for the maximum effect parameter |
None
|
effect_mode |
effects_application
|
Mode of the effect (either "additive" or "multiplicative") |
'multiplicative'
|
Source code in src/prophetverse/effects/hill.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
LiftExperimentLikelihood
Bases: BaseEffect
Wrap an effect and applies a normal likelihood to its output.
This class uses an input as a reference for the effect, and applies a normal likelihood to the output of the effect.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
effect |
BaseEffect
|
The effect to wrap. |
required |
lift_test_results |
DataFrame
|
A dataframe with the lift test results. Should be in sktime format, and must have the same index as the input data. |
required |
prior_scale |
float
|
The scale of the prior distribution for the likelihood. |
required |
Source code in src/prophetverse/effects/lift_experiment.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
input_feature_column_names: List[str]
property
Return the input feature columns names.
fit(y, X, scale=1)
Initialize the effect.
This method is called during fit()
of the forecasting model.
It receives the Exogenous variables DataFrame and should be used to initialize
any necessary parameters or data structures, such as detecting the columns that
match the regex pattern.
This method MUST set _input_feature_columns_names to a list of column names
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y |
DataFrame
|
The timeseries dataframe |
required |
X |
DataFrame
|
The DataFrame to initialize the effect. |
required |
scale |
float
|
The scale of the timeseries. For multivariate timeseries, this is a dataframe. For univariate, it is a simple float. |
1
|
Returns:
Type | Description |
---|---|
None
|
|
Source code in src/prophetverse/effects/lift_experiment.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
LinearEffect
Bases: BaseAdditiveOrMultiplicativeEffect
Represents a linear effect in a hierarchical prophet model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prior |
Distribution
|
A numpyro distribution to use as prior. Defaults to dist.Normal(0, 1) |
None
|
effect_mode |
effects_application
|
Either "multiplicative" or "additive" by default "multiplicative". |
'multiplicative'
|
Source code in src/prophetverse/effects/linear.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
LinearFourierSeasonality
Bases: BaseEffect
Linear Fourier Seasonality effect.
Compute the linear seasonality using Fourier features.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sp_list |
List[float]
|
List of seasonal periods. |
required |
fourier_terms_list |
List[int]
|
List of number of Fourier terms to use for each seasonal period. |
required |
freq |
str
|
Frequency of the time series. Example: "D" for daily, "W" for weekly, etc. |
required |
prior_scale |
float
|
Scale of the prior distribution for the effect, by default 1.0. |
1.0
|
effect_mode |
str
|
Either "multiplicative" or "additive" by default "additive". |
'additive'
|
Source code in src/prophetverse/effects/fourier.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
|
LogEffect
Bases: BaseAdditiveOrMultiplicativeEffect
Represents a log effect as effect = scale * log(rate * data + 1).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scale_prior |
Optional[Distribution]
|
The prior distribution for the scale parameter., by default Gamma |
None
|
rate_prior |
Optional[Distribution]
|
The prior distribution for the rate parameter., by default Gamma |
None
|
effect_mode |
effects_application
|
Either "additive" or "multiplicative", by default "multiplicative" |
'multiplicative'
|
Source code in src/prophetverse/effects/log.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|