model_selection
¶
skforecast.model_selection._validation.backtesting_forecaster ¶
backtesting_forecaster(
forecaster,
y,
cv,
metric,
exog=None,
interval=None,
n_boot=250,
random_state=123,
use_in_sample_residuals=True,
use_binned_residuals=False,
n_jobs="auto",
verbose=False,
show_progress=True,
)
Backtesting of forecaster model following the folds generated by the TimeSeriesFold class and using the metric(s) provided.
If forecaster
is already trained and initial_train_size
is set to None
in the
TimeSeriesFold class, no initial train will be done and all data will be used
to evaluate the model. However, the first len(forecaster.last_window)
observations
are needed to create the initial predictors, so no predictions are calculated for
them.
A copy of the original forecaster is created so that it is not modified during the process.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
forecaster |
(ForecasterRecursive, ForecasterDirect)
|
Forecaster model. |
required |
y |
pandas Series
|
Training time series. |
required |
cv |
TimeSeriesFold
|
TimeSeriesFold object with the information needed to split the data into folds. New in version 0.14.0 |
required |
metric |
(str, Callable, list)
|
Metric used to quantify the goodness of fit of the model.
|
required |
exog |
pandas Series, pandas DataFrame
|
Exogenous variable/s included as predictor/s. Must have the same
number of observations as |
`None`
|
interval |
list
|
Confidence of the prediction interval estimated. Sequence of percentiles
to compute, which must be between 0 and 100 inclusive. For example,
interval of 95% should be as |
`None`
|
n_boot |
int
|
Number of bootstrapping iterations used to estimate prediction intervals. |
`250`
|
random_state |
int
|
Sets a seed to the random generator, so that boot intervals are always deterministic. |
`123`
|
use_in_sample_residuals |
bool
|
If |
`True`
|
use_binned_residuals |
bool
|
If |
`False`
|
n_jobs |
(int, auto)
|
The number of jobs to run in parallel. If |
`'auto'`
|
verbose |
bool
|
Print number of folds and index of training and validation sets used for backtesting. |
`False`
|
show_progress |
bool
|
Whether to show a progress bar. |
`True`
|
Returns:
Name | Type | Description |
---|---|---|
metric_values |
pandas DataFrame
|
Value(s) of the metric(s). |
backtest_predictions |
pandas DataFrame
|
Value of predictions and their estimated interval if
|
Source code in skforecast\model_selection\_validation.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
|
skforecast.model_selection._search.grid_search_forecaster ¶
grid_search_forecaster(
forecaster,
y,
cv,
param_grid,
metric,
exog=None,
lags_grid=None,
return_best=True,
n_jobs="auto",
verbose=True,
show_progress=True,
output_file=None,
)
Exhaustive search over specified parameter values for a Forecaster object. Validation is done using time series backtesting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
forecaster |
(ForecasterRecursive, ForecasterDirect)
|
Forecaster model. |
required |
y |
pandas Series
|
Training time series. |
required |
cv |
(TimeSeriesFold, OneStepAheadFold)
|
TimeSeriesFold or OneStepAheadFold object with the information needed to split the data into folds. New in version 0.14.0 |
required |
param_grid |
dict
|
Dictionary with parameters names ( |
required |
metric |
(str, Callable, list)
|
Metric used to quantify the goodness of fit of the model.
|
required |
exog |
pandas Series, pandas DataFrame
|
Exogenous variable/s included as predictor/s. Must have the same
number of observations as |
`None`
|
lags_grid |
(list, dict)
|
Lists of lags to try, containing int, lists, numpy ndarray, or range
objects. If |
`None`
|
return_best |
bool
|
Refit the |
`True`
|
n_jobs |
(int, auto)
|
The number of jobs to run in parallel. If |
`'auto'`
|
verbose |
bool
|
Print number of folds used for cv or backtesting. |
`True`
|
show_progress |
bool
|
Whether to show a progress bar. |
`True`
|
output_file |
str
|
Specifies the filename or full path where the results should be saved.
The results will be saved in a tab-separated values (TSV) format. If
|
`None`
|
Returns:
Name | Type | Description |
---|---|---|
results |
pandas DataFrame
|
Results for each combination of parameters.
|
Source code in skforecast\model_selection\_search.py
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 |
|
skforecast.model_selection._search.random_search_forecaster ¶
random_search_forecaster(
forecaster,
y,
cv,
param_distributions,
metric,
exog=None,
lags_grid=None,
n_iter=10,
random_state=123,
return_best=True,
n_jobs="auto",
verbose=True,
show_progress=True,
output_file=None,
)
Random search over specified parameter values or distributions for a Forecaster object. Validation is done using time series backtesting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
forecaster |
(ForecasterRecursive, ForecasterDirect)
|
Forecaster model. |
required |
y |
pandas Series
|
Training time series. |
required |
cv |
(TimeSeriesFold, OneStepAheadFold)
|
TimeSeriesFold or OneStepAheadFold object with the information needed to split the data into folds. New in version 0.14.0 |
required |
param_distributions |
dict
|
Dictionary with parameters names ( |
required |
metric |
(str, Callable, list)
|
Metric used to quantify the goodness of fit of the model.
|
required |
exog |
pandas Series, pandas DataFrame
|
Exogenous variable/s included as predictor/s. Must have the same
number of observations as |
`None`
|
lags_grid |
(list, dict)
|
Lists of lags to try, containing int, lists, numpy ndarray, or range
objects. If |
`None`
|
n_iter |
int
|
Number of parameter settings that are sampled per lags configuration. n_iter trades off runtime vs quality of the solution. |
`10`
|
random_state |
int
|
Sets a seed to the random sampling for reproducible output. |
`123`
|
return_best |
bool
|
Refit the |
`True`
|
n_jobs |
(int, auto)
|
The number of jobs to run in parallel. If |
`'auto'`
|
verbose |
bool
|
Print number of folds used for cv or backtesting. |
`True`
|
show_progress |
bool
|
Whether to show a progress bar. |
`True`
|
output_file |
str
|
Specifies the filename or full path where the results should be saved.
The results will be saved in a tab-separated values (TSV) format. If
|
`None`
|
Returns:
Name | Type | Description |
---|---|---|
results |
pandas DataFrame
|
Results for each combination of parameters.
|
Source code in skforecast\model_selection\_search.py
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 |
|
skforecast.model_selection._search.bayesian_search_forecaster ¶
bayesian_search_forecaster(
forecaster,
y,
cv,
search_space,
metric,
exog=None,
n_trials=10,
random_state=123,
return_best=True,
n_jobs="auto",
verbose=True,
show_progress=True,
output_file=None,
kwargs_create_study={},
kwargs_study_optimize={},
)
Bayesian search for hyperparameters of a Forecaster object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
forecaster |
(ForecasterRecursive, ForecasterDirect)
|
Forecaster model. |
required |
y |
pandas Series
|
Training time series. |
required |
cv |
(TimeSeriesFold, OneStepAheadFold)
|
TimeSeriesFold or OneStepAheadFold object with the information needed to split the data into folds. New in version 0.14.0 |
required |
search_space |
Callable(optuna)
|
Function with argument |
required |
metric |
(str, Callable, list)
|
Metric used to quantify the goodness of fit of the model.
|
required |
exog |
pandas Series, pandas DataFrame
|
Exogenous variable/s included as predictor/s. Must have the same
number of observations as |
`None`
|
n_trials |
int
|
Number of parameter settings that are sampled in each lag configuration. |
`10`
|
random_state |
int
|
Sets a seed to the sampling for reproducible output. When a new sampler
is passed in |
`123`
|
return_best |
bool
|
Refit the |
`True`
|
n_jobs |
(int, auto)
|
The number of jobs to run in parallel. If |
`'auto'`
|
verbose |
bool
|
Print number of folds used for cv or backtesting. |
`True`
|
show_progress |
bool
|
Whether to show a progress bar. |
`True`
|
output_file |
str
|
Specifies the filename or full path where the results should be saved.
The results will be saved in a tab-separated values (TSV) format. If
|
`None`
|
kwargs_create_study |
dict
|
Keyword arguments (key, value mappings) to pass to optuna.create_study(). If default, the direction is set to 'minimize' and a TPESampler(seed=123) sampler is used during optimization. |
`{}`
|
kwargs_study_optimize |
dict
|
Other keyword arguments (key, value mappings) to pass to study.optimize(). |
`{}`
|
Returns:
Name | Type | Description |
---|---|---|
results |
pandas DataFrame
|
Results for each combination of parameters.
|
best_trial |
optuna object
|
The best optimization result returned as a FrozenTrial optuna object. |
Source code in skforecast\model_selection\_search.py
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 |
|
skforecast.model_selection._validation.backtesting_forecaster_multiseries ¶
backtesting_forecaster_multiseries(
forecaster,
series,
cv,
metric,
levels=None,
add_aggregated_metric=True,
exog=None,
interval=None,
n_boot=250,
random_state=123,
use_in_sample_residuals=True,
n_jobs="auto",
verbose=False,
show_progress=True,
suppress_warnings=False,
)
Backtesting of forecaster model following the folds generated by the TimeSeriesFold class and using the metric(s) provided.
If forecaster
is already trained and initial_train_size
is set to None
in the
TimeSeriesFold class, no initial train will be done and all data will be used
to evaluate the model. However, the first len(forecaster.last_window)
observations
are needed to create the initial predictors, so no predictions are calculated for
them.
A copy of the original forecaster is created so that it is not modified during the process.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
forecaster |
(ForecasterRecursiveMultiSeries, ForecasterDirectMultiVariate, ForecasterRnn)
|
Forecaster model. |
required |
series |
pandas DataFrame, dict
|
Training time series. |
required |
cv |
TimeSeriesFold
|
TimeSeriesFold object with the information needed to split the data into folds. |
required |
metric |
(str, Callable, list)
|
Metric used to quantify the goodness of fit of the model.
|
required |
levels |
(str, list)
|
Time series to be predicted. If |
`None`
|
add_aggregated_metric |
bool
|
If
|
`True`
|
exog |
pandas Series, pandas DataFrame, dict
|
Exogenous variables. |
`None`
|
interval |
list
|
Confidence of the prediction interval estimated. Sequence of percentiles
to compute, which must be between 0 and 100 inclusive. If |
`None`
|
n_boot |
int
|
Number of bootstrapping iterations used to estimate prediction intervals. |
`250`
|
random_state |
int
|
Sets a seed to the random generator, so that boot intervals are always deterministic. |
`123`
|
use_in_sample_residuals |
bool
|
If |
`True`
|
n_jobs |
(int, auto)
|
The number of jobs to run in parallel. If |
`'auto'`
|
verbose |
bool
|
Print number of folds and index of training and validation sets used for backtesting. |
`False`
|
show_progress |
bool
|
Whether to show a progress bar. |
`True`
|
suppress_warnings |
bool
|
If |
False
|
Returns:
Name | Type | Description |
---|---|---|
metrics_levels |
pandas DataFrame
|
Value(s) of the metric(s). Index are the levels and columns the metrics. |
backtest_predictions |
pandas DataFrame
|
Value of predictions and their estimated interval if
|
Source code in skforecast\model_selection\_validation.py
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 |
|
skforecast.model_selection._search.grid_search_forecaster_multiseries ¶
grid_search_forecaster_multiseries(
forecaster,
series,
cv,
param_grid,
metric,
aggregate_metric=[
"weighted_average",
"average",
"pooling",
],
levels=None,
exog=None,
lags_grid=None,
return_best=True,
n_jobs="auto",
verbose=True,
show_progress=True,
suppress_warnings=False,
output_file=None,
)
Exhaustive search over specified parameter values for a Forecaster object. Validation is done using multi-series backtesting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
forecaster |
(ForecasterRecursiveMultiSeries, ForecasterDirectMultiVariate)
|
Forecaster model. |
required |
series |
pandas DataFrame, dict
|
Training time series. |
required |
cv |
(TimeSeriesFold, OneStepAheadFold)
|
TimeSeriesFold or OneStepAheadFold object with the information needed to split the data into folds. New in version 0.14.0 |
required |
param_grid |
dict
|
Dictionary with parameters names ( |
required |
metric |
(str, Callable, list)
|
Metric used to quantify the goodness of fit of the model.
|
required |
aggregate_metric |
(str, list)
|
Aggregation method/s used to combine the metric/s of all levels (series) when multiple levels are predicted. If list, the first aggregation method is used to select the best parameters.
|
`['weighted_average', 'average', 'pooling']`
|
levels |
(str, list)
|
level ( |
`None`
|
exog |
pandas Series, pandas DataFrame, dict
|
Exogenous variables. |
`None`
|
lags_grid |
(list, dict)
|
Lists of lags to try, containing int, lists, numpy ndarray, or range
objects. If |
`None`
|
return_best |
bool
|
Refit the |
`True`
|
n_jobs |
(int, auto)
|
The number of jobs to run in parallel. If |
`'auto'`
|
verbose |
bool
|
Print number of folds used for cv or backtesting. |
`True`
|
show_progress |
bool
|
Whether to show a progress bar. |
`True`
|
suppress_warnings |
bool
|
If |
False
|
output_file |
str
|
Specifies the filename or full path where the results should be saved.
The results will be saved in a tab-separated values (TSV) format. If
|
`None`
|
Returns:
Name | Type | Description |
---|---|---|
results |
pandas DataFrame
|
Results for each combination of parameters.
|
Source code in skforecast\model_selection\_search.py
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 |
|
skforecast.model_selection._search.random_search_forecaster_multiseries ¶
random_search_forecaster_multiseries(
forecaster,
series,
cv,
param_distributions,
metric,
aggregate_metric=[
"weighted_average",
"average",
"pooling",
],
levels=None,
exog=None,
lags_grid=None,
n_iter=10,
random_state=123,
return_best=True,
n_jobs="auto",
verbose=True,
show_progress=True,
suppress_warnings=False,
output_file=None,
)
Random search over specified parameter values or distributions for a Forecaster object. Validation is done using multi-series backtesting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
forecaster |
(ForecasterRecursiveMultiSeries, ForecasterDirectMultiVariate)
|
Forecaster model. |
required |
series |
pandas DataFrame, dict
|
Training time series. |
required |
cv |
(TimeSeriesFold, OneStepAheadFold)
|
TimeSeriesFold or OneStepAheadFold object with the information needed to split the data into folds. |
required |
param_distributions |
dict
|
Dictionary with parameters names ( |
required |
metric |
(str, Callable, list)
|
Metric used to quantify the goodness of fit of the model.
|
required |
aggregate_metric |
(str, list)
|
Aggregation method/s used to combine the metric/s of all levels (series) when multiple levels are predicted. If list, the first aggregation method is used to select the best parameters.
|
`['weighted_average', 'average', 'pooling']`
|
levels |
(str, list)
|
level ( |
`None`
|
exog |
pandas Series, pandas DataFrame, dict
|
Exogenous variables. |
`None`
|
lags_grid |
(list, dict)
|
Lists of lags to try, containing int, lists, numpy ndarray, or range
objects. If |
`None`
|
n_iter |
int
|
Number of parameter settings that are sampled per lags configuration. n_iter trades off runtime vs quality of the solution. |
`10`
|
random_state |
int
|
Sets a seed to the random sampling for reproducible output. |
`123`
|
return_best |
bool
|
Refit the |
`True`
|
n_jobs |
(int, auto)
|
The number of jobs to run in parallel. If |
`'auto'`
|
verbose |
bool
|
Print number of folds used for cv or backtesting. |
`True`
|
show_progress |
bool
|
Whether to show a progress bar. |
`True`
|
suppress_warnings |
bool
|
If |
False
|
output_file |
str
|
Specifies the filename or full path where the results should be saved.
The results will be saved in a tab-separated values (TSV) format. If
|
`None`
|
Returns:
Name | Type | Description |
---|---|---|
results |
pandas DataFrame
|
Results for each combination of parameters.
|
Source code in skforecast\model_selection\_search.py
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 |
|
skforecast.model_selection._search.bayesian_search_forecaster_multiseries ¶
bayesian_search_forecaster_multiseries(
forecaster,
series,
cv,
search_space,
metric,
aggregate_metric=[
"weighted_average",
"average",
"pooling",
],
levels=None,
exog=None,
n_trials=10,
random_state=123,
return_best=True,
n_jobs="auto",
verbose=True,
show_progress=True,
suppress_warnings=False,
output_file=None,
kwargs_create_study={},
kwargs_study_optimize={},
)
Bayesian search for hyperparameters of a Forecaster object using optuna library.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
forecaster |
(ForecasterRecursiveMultiSeries, ForecasterDirectMultiVariate)
|
Forecaster model. |
required |
series |
pandas DataFrame, dict
|
Training time series. |
required |
search_space |
Callable
|
Function with argument |
required |
metric |
(str, Callable, list)
|
Metric used to quantify the goodness of fit of the model.
|
required |
aggregate_metric |
(str, list)
|
Aggregation method/s used to combine the metric/s of all levels (series) when multiple levels are predicted. If list, the first aggregation method is used to select the best parameters.
|
`['weighted_average', 'average', 'pooling']`
|
levels |
(str, list)
|
level ( |
`None`
|
exog |
pandas Series, pandas DataFrame, dict
|
Exogenous variables. |
`None`
|
n_trials |
int
|
Number of parameter settings that are sampled in each lag configuration. |
`10`
|
random_state |
int
|
Sets a seed to the sampling for reproducible output. |
`123`
|
return_best |
bool
|
Refit the |
`True`
|
n_jobs |
(int, auto)
|
The number of jobs to run in parallel. If |
`'auto'`
|
verbose |
bool
|
Print number of folds used for cv or backtesting. |
`True`
|
show_progress |
bool
|
Whether to show a progress bar. |
`True`
|
suppress_warnings |
bool
|
If |
False
|
output_file |
str
|
Specifies the filename or full path where the results should be saved.
The results will be saved in a tab-separated values (TSV) format. If
|
`None`
|
kwargs_create_study |
dict
|
Keyword arguments (key, value mappings) to pass to optuna.create_study(). If default, the direction is set to 'minimize' and a TPESampler(seed=123) sampler is used during optimization. |
`{}`
|
kwargs_study_optimize |
dict
|
Other keyword arguments (key, value mappings) to pass to study.optimize(). |
`{}`
|
Returns:
Name | Type | Description |
---|---|---|
results |
pandas DataFrame
|
Results for each combination of parameters.
|
best_trial |
optuna object
|
The best optimization result returned as a FrozenTrial optuna object. |
Source code in skforecast\model_selection\_search.py
1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 |
|
skforecast.model_selection._validation.backtesting_sarimax ¶
backtesting_sarimax(
forecaster,
y,
cv,
metric,
exog=None,
alpha=None,
interval=None,
n_jobs="auto",
verbose=False,
suppress_warnings_fit=False,
show_progress=True,
)
Backtesting of ForecasterSarimax.
A copy of the original forecaster is created so that it is not modified during the process.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
forecaster |
ForecasterSarimax
|
Forecaster model. |
required |
y |
pandas Series
|
Training time series. |
required |
cv |
TimeSeriesFold
|
TimeSeriesFold object with the information needed to split the data into folds. New in version 0.14.0 |
required |
metric |
(str, Callable, list)
|
Metric used to quantify the goodness of fit of the model.
|
required |
exog |
pandas Series, pandas DataFrame
|
Exogenous variable/s included as predictor/s. Must have the same
number of observations as |
`None`
|
alpha |
float
|
The confidence intervals for the forecasts are (1 - alpha) %.
If both, |
`0.05`
|
interval |
list
|
Confidence of the prediction interval estimated. The values must be
symmetric. Sequence of percentiles to compute, which must be between
0 and 100 inclusive. For example, interval of 95% should be as
|
`None`
|
n_jobs |
(int, auto)
|
The number of jobs to run in parallel. If |
`'auto'`
|
verbose |
bool
|
Print number of folds and index of training and validation sets used for backtesting. |
`False`
|
suppress_warnings_fit |
bool
|
If |
`False`
|
show_progress |
bool
|
Whether to show a progress bar. |
`True`
|
Returns:
Name | Type | Description |
---|---|---|
metric_values |
pandas DataFrame
|
Value(s) of the metric(s). |
backtest_predictions |
pandas DataFrame
|
Value of predictions and their estimated interval if
|
Source code in skforecast\model_selection\_validation.py
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 |
|
skforecast.model_selection._search.grid_search_sarimax ¶
grid_search_sarimax(
forecaster,
y,
cv,
param_grid,
metric,
exog=None,
return_best=True,
n_jobs="auto",
verbose=True,
suppress_warnings_fit=False,
show_progress=True,
output_file=None,
)
Exhaustive search over specified parameter values for a ForecasterSarimax object. Validation is done using time series backtesting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
forecaster |
ForecasterSarimax
|
Forecaster model. |
required |
y |
pandas Series
|
Training time series. |
required |
cv |
TimeSeriesFold
|
TimeSeriesFold object with the information needed to split the data into folds. New in version 0.14.0 |
required |
param_grid |
dict
|
Dictionary with parameters names ( |
required |
metric |
(str, Callable, list)
|
Metric used to quantify the goodness of fit of the model.
|
required |
exog |
pandas Series, pandas DataFrame
|
Exogenous variable/s included as predictor/s. Must have the same
number of observations as |
`None`
|
return_best |
bool
|
Refit the |
`True`
|
n_jobs |
(int, auto)
|
The number of jobs to run in parallel. If |
`'auto'`
|
verbose |
bool
|
Print number of folds used for cv or backtesting. |
`True`
|
suppress_warnings_fit |
bool
|
If |
`False`
|
show_progress |
bool
|
Whether to show a progress bar. |
`True`
|
output_file |
str
|
Specifies the filename or full path where the results should be saved.
The results will be saved in a tab-separated values (TSV) format. If
|
`None`
|
Returns:
Name | Type | Description |
---|---|---|
results |
pandas DataFrame
|
Results for each combination of parameters.
|
Source code in skforecast\model_selection\_search.py
2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 |
|
skforecast.model_selection._search.random_search_sarimax ¶
random_search_sarimax(
forecaster,
y,
cv,
param_distributions,
metric,
exog=None,
n_iter=10,
random_state=123,
return_best=True,
n_jobs="auto",
verbose=True,
suppress_warnings_fit=False,
show_progress=True,
output_file=None,
)
Random search over specified parameter values or distributions for a Forecaster object. Validation is done using time series backtesting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
forecaster |
ForecasterSarimax
|
Forecaster model. |
required |
y |
pandas Series
|
Training time series. |
required |
cv |
TimeSeriesFold
|
TimeSeriesFold object with the information needed to split the data into folds. New in version 0.14.0 |
required |
param_distributions |
dict
|
Dictionary with parameters names ( |
required |
metric |
(str, Callable, list)
|
Metric used to quantify the goodness of fit of the model.
|
required |
exog |
pandas Series, pandas DataFrame
|
Exogenous variable/s included as predictor/s. Must have the same
number of observations as |
`None`
|
n_iter |
int
|
Number of parameter settings that are sampled. n_iter trades off runtime vs quality of the solution. |
`10`
|
random_state |
int
|
Sets a seed to the random sampling for reproducible output. |
`123`
|
return_best |
bool
|
Refit the |
`True`
|
n_jobs |
(int, auto)
|
The number of jobs to run in parallel. If |
`'auto'`
|
verbose |
bool
|
Print number of folds used for cv or backtesting. |
`True`
|
suppress_warnings_fit |
bool
|
If |
`False`
|
show_progress |
bool
|
Whether to show a progress bar. |
`True`
|
output_file |
str
|
Specifies the filename or full path where the results should be saved.
The results will be saved in a tab-separated values (TSV) format. If
|
`None`
|
Returns:
Name | Type | Description |
---|---|---|
results |
pandas DataFrame
|
Results for each combination of parameters.
|
Source code in skforecast\model_selection\_search.py
2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 |
|
skforecast.model_selection._split.BaseFold ¶
BaseFold(
steps=None,
initial_train_size=None,
window_size=None,
differentiation=None,
refit=False,
fixed_train_size=True,
gap=0,
skip_folds=None,
allow_incomplete_fold=True,
return_all_indexes=False,
verbose=True,
)
Base class for all Fold classes in skforecast. All fold classes should specify
all the parameters that can be set at the class level in their __init__
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
steps |
int
|
Number of observations used to be predicted in each fold. This is also commonly referred to as the forecast horizon or test size. |
`None`
|
initial_train_size |
int
|
Number of observations used for initial training. |
`None`
|
window_size |
int
|
Number of observations needed to generate the autoregressive predictors. |
`None`
|
differentiation |
int
|
Number of observations to use for differentiation. This is used to extend the
|
`None`
|
refit |
(bool, int)
|
Whether to refit the forecaster in each fold.
|
`False`
|
fixed_train_size |
bool
|
Whether the training size is fixed or increases in each fold. |
`True`
|
gap |
int
|
Number of observations between the end of the training set and the start of the test set. |
`0`
|
skip_folds |
(int, list)
|
Number of folds to skip.
For example, if |
`None`
|
allow_incomplete_fold |
bool
|
Whether to allow the last fold to include fewer observations than |
`True`
|
return_all_indexes |
bool
|
Whether to return all indexes or only the start and end indexes of each fold. |
`False`
|
verbose |
bool
|
Whether to print information about generated folds. |
`True`
|
Attributes:
Name | Type | Description |
---|---|---|
steps |
int
|
Number of observations used to be predicted in each fold. This is also commonly referred to as the forecast horizon or test size. |
initial_train_size |
int
|
Number of observations used for initial training. |
window_size |
int
|
Number of observations needed to generate the autoregressive predictors. |
differentiation |
int
|
Number of observations to use for differentiation. This is used to extend the
|
refit |
(bool, int)
|
Whether to refit the forecaster in each fold. |
fixed_train_size |
bool
|
Whether the training size is fixed or increases in each fold. |
gap |
int
|
Number of observations between the end of the training set and the start of the test set. |
skip_folds |
(int, list)
|
Number of folds to skip. |
allow_incomplete_fold |
bool
|
Whether to allow the last fold to include fewer observations than |
return_all_indexes |
bool
|
Whether to return all indexes or only the start and end indexes of each fold. |
verbose |
bool
|
Whether to print information about generated folds. |
Source code in skforecast\model_selection\_split.py
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 |
|
_validate_params ¶
_validate_params(
cv_name,
steps=None,
initial_train_size=None,
window_size=None,
differentiation=None,
refit=False,
fixed_train_size=True,
gap=0,
skip_folds=None,
allow_incomplete_fold=True,
return_all_indexes=False,
verbose=True,
)
Validate all input parameters to ensure correctness.
Source code in skforecast\model_selection\_split.py
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 |
|
_extract_index ¶
_extract_index(X)
Extracts and returns the index from the input data X.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X |
pandas Series, pandas DataFrame, pandas Index, dict
|
Time series data or index to split. |
required |
Returns:
Name | Type | Description |
---|---|---|
idx |
pandas Index
|
Index extracted from the input data. |
Source code in skforecast\model_selection\_split.py
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 |
|
set_params ¶
set_params(params)
Set the parameters of the Fold object. Before overwriting the current parameters, the input parameters are validated to ensure correctness.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
dict
|
Dictionary with the parameters to set. |
required |
Returns:
Type | Description |
---|---|
None
|
|
Source code in skforecast\model_selection\_split.py
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 311 312 313 314 315 316 317 318 319 320 321 |
|
skforecast.model_selection._split.TimeSeriesFold ¶
TimeSeriesFold(
steps,
initial_train_size=None,
window_size=None,
differentiation=None,
refit=False,
fixed_train_size=True,
gap=0,
skip_folds=None,
allow_incomplete_fold=True,
return_all_indexes=False,
verbose=True,
)
Bases: BaseFold
Class to split time series data into train and test folds. When used within a backtesting or hyperparameter search, the arguments 'initial_train_size', 'window_size' and 'differentiation' are not required as they are automatically set by the backtesting or hyperparameter search functions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
steps |
int
|
Number of observations used to be predicted in each fold. This is also commonly referred to as the forecast horizon or test size. |
required |
initial_train_size |
int
|
Number of observations used for initial training. If |
`None`
|
window_size |
int
|
Number of observations needed to generate the autoregressive predictors. |
`None`
|
differentiation |
int
|
Number of observations to use for differentiation. This is used to extend the
|
`None`
|
refit |
(bool, int)
|
Whether to refit the forecaster in each fold.
|
`False`
|
fixed_train_size |
bool
|
Whether the training size is fixed or increases in each fold. |
`True`
|
gap |
int
|
Number of observations between the end of the training set and the start of the test set. |
`0`
|
skip_folds |
(int, list)
|
Number of folds to skip.
For example, if |
`None`
|
allow_incomplete_fold |
bool
|
Whether to allow the last fold to include fewer observations than |
`True`
|
return_all_indexes |
bool
|
Whether to return all indexes or only the start and end indexes of each fold. |
`False`
|
verbose |
bool
|
Whether to print information about generated folds. |
`True`
|
Attributes:
Name | Type | Description |
---|---|---|
steps |
int
|
Number of observations used to be predicted in each fold. This is also commonly referred to as the forecast horizon or test size. |
initial_train_size |
int
|
Number of observations used for initial training. If |
window_size |
int
|
Number of observations needed to generate the autoregressive predictors. |
differentiation |
int
|
Number of observations to use for differentiation. This is used to extend the
|
refit |
(bool, int)
|
Whether to refit the forecaster in each fold. |
fixed_train_size |
bool
|
Whether the training size is fixed or increases in each fold. |
gap |
int
|
Number of observations between the end of the training set and the start of the test set. |
skip_folds |
(int, list)
|
Number of folds to skip. |
allow_incomplete_fold |
bool
|
Whether to allow the last fold to include fewer observations than |
return_all_indexes |
bool
|
Whether to return all indexes or only the start and end indexes of each fold. |
verbose |
bool
|
Whether to print information about generated folds. |
Notes
Returned values are the positions of the observations and not the actual values of
the index, so they can be used to slice the data directly using iloc. For example,
if the input series is X = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
, the
initial_train_size = 3
, window_size = 2
, steps = 4
, and gap = 1
,
the output of the first fold will: [[0, 3], [1, 3], [3, 8], [4, 8], True].
The first list [0, 3]
indicates that the training set goes from the first to the
third observation. The second list [1, 3]
indicates that the last window seen by
the forecaster during training goes from the second to the third observation. The
third list [3, 8]
indicates that the test set goes from the fourth to the eighth
observation. The fourth list [4, 8]
indicates that the test set including the gap
goes from the fifth to the eighth observation. The boolean False
indicates that the
forecaster should not be trained in this fold.
Following the python convention, the start index is inclusive and the end index is exclusive. This means that the last index is not included in the slice.
Source code in skforecast\model_selection\_split.py
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 |
|
split ¶
split(X, as_pandas=False)
Split the time series data into train and test folds.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X |
pandas Series, pandas DataFrame, pandas Index, dict
|
Time series data or index to split. |
required |
as_pandas |
bool
|
If True, the folds are returned as a DataFrame. This is useful to visualize the folds in a more interpretable way. |
`False`
|
Returns:
Name | Type | Description |
---|---|---|
folds |
list, pandas DataFrame
|
A list of lists containing the indices (position) for for each fold. Each list contains 4 lists and a boolean with the following information:
It is important to note that the returned values are the positions of the observations and not the actual values of the index, so they can be used to slice the data directly using iloc. If Following the python convention, the start index is inclusive and the end index is exclusive. This means that the last index is not included in the slice. |
Source code in skforecast\model_selection\_split.py
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 |
|
_print_info ¶
_print_info(
index,
folds,
externally_fitted,
last_fold_excluded,
index_to_skip,
)
Print information about folds.
Source code in skforecast\model_selection\_split.py
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 |
|
skforecast.model_selection._split.OneStepAheadFold ¶
OneStepAheadFold(
initial_train_size,
window_size=None,
differentiation=None,
return_all_indexes=False,
verbose=True,
)
Bases: BaseFold
Class to split time series data into train and test folds for one-step-ahead forecasting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
initial_train_size |
int
|
Number of observations used for initial training. |
required |
window_size |
int
|
Number of observations needed to generate the autoregressive predictors. |
`None`
|
differentiation |
int
|
Number of observations to use for differentiation. This is used to extend the
|
`None`
|
return_all_indexes |
bool
|
Whether to return all indexes or only the start and end indexes of each fold. |
`False`
|
verbose |
bool
|
Whether to print information about generated folds. |
`True`
|
Attributes:
Name | Type | Description |
---|---|---|
initial_train_size |
int
|
Number of observations used for initial training. |
window_size |
int
|
Number of observations needed to generate the autoregressive predictors. |
differentiation |
int
|
Number of observations to use for differentiation. This is used to extend the
|
return_all_indexes |
bool
|
Whether to return all indexes or only the start and end indexes of each fold. |
verbose |
bool
|
Whether to print information about generated folds. |
steps |
Any
|
This attribute is not used in this class. It is included for API consistency. |
fixed_train_size |
Any
|
This attribute is not used in this class. It is included for API consistency. |
gap |
Any
|
This attribute is not used in this class. It is included for API consistency. |
skip_folds |
Any
|
This attribute is not used in this class. It is included for API consistency. |
allow_incomplete_fold |
Any
|
This attribute is not used in this class. It is included for API consistency. |
refit |
Any
|
This attribute is not used in this class. It is included for API consistency. |
Source code in skforecast\model_selection\_split.py
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
|
split ¶
split(X, as_pandas=False, externally_fitted=None)
Split the time series data into train and test folds.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X |
pandas Series, DataFrame, Index, or dictionary
|
Time series data or index to split. |
required |
as_pandas |
bool
|
If True, the folds are returned as a DataFrame. This is useful to visualize the folds in a more interpretable way. |
`False`
|
externally_fitted |
Any
|
This argument is not used in this class. It is included for API consistency. |
None
|
Returns:
Name | Type | Description |
---|---|---|
fold |
list, pandas DataFrame
|
A list of lists containing the indices (position) for for each fold. Each list contains 2 lists the following information:
It is important to note that the returned values are the positions of the observations and not the actual values of the index, so they can be used to slice the data directly using iloc. If Following the python convention, the start index is inclusive and the end index is exclusive. This means that the last index is not included in the slice. |
Source code in skforecast\model_selection\_split.py
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 |
|
_print_info ¶
_print_info(index, fold)
Print information about folds.
Source code in skforecast\model_selection\_split.py
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 |
|
skforecast.model_selection._utils.initialize_lags_grid ¶
initialize_lags_grid(forecaster, lags_grid=None)
Initialize lags grid and lags label for model selection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
forecaster |
Forecaster
|
Forecaster model. ForecasterRecursive, ForecasterDirect, ForecasterRecursiveMultiSeries, ForecasterDirectMultiVariate. |
required |
lags_grid |
(list, dict)
|
Lists of lags to try, containing int, lists, numpy ndarray, or range
objects. If |
`None`
|
Returns:
Name | Type | Description |
---|---|---|
lags_grid |
dict
|
Dictionary with lags configuration for each iteration. |
lags_label |
str
|
Label for lags representation in the results object. |
Source code in skforecast\model_selection\_utils.py
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 |
|
skforecast.model_selection._utils.check_backtesting_input ¶
check_backtesting_input(
forecaster,
cv,
metric,
add_aggregated_metric=True,
y=None,
series=None,
exog=None,
interval=None,
alpha=None,
n_boot=250,
random_state=123,
use_in_sample_residuals=True,
use_binned_residuals=False,
n_jobs="auto",
show_progress=True,
suppress_warnings=False,
suppress_warnings_fit=False,
)
This is a helper function to check most inputs of backtesting functions in
modules model_selection
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
forecaster |
Forecaster
|
Forecaster model. |
required |
cv |
TimeSeriesFold
|
TimeSeriesFold object with the information needed to split the data into folds. |
required |
metric |
(str, Callable, list)
|
Metric used to quantify the goodness of fit of the model. |
required |
add_aggregated_metric |
bool
|
If |
`True`
|
y |
pandas Series
|
Training time series for uni-series forecasters. |
`None`
|
series |
pandas DataFrame, dict
|
Training time series for multi-series forecasters. |
`None`
|
exog |
pandas Series, pandas DataFrame, dict
|
Exogenous variables. |
`None`
|
interval |
list
|
Confidence of the prediction interval estimated. Sequence of percentiles to compute, which must be between 0 and 100 inclusive. |
`None`
|
alpha |
float
|
The confidence intervals used in ForecasterSarimax are (1 - alpha) %. |
`None`
|
n_boot |
int
|
Number of bootstrapping iterations used to estimate prediction intervals. |
`250`
|
random_state |
int
|
Sets a seed to the random generator, so that boot intervals are always deterministic. |
`123`
|
use_in_sample_residuals |
bool
|
If |
`True`
|
use_binned_residuals |
bool
|
If |
`False`
|
n_jobs |
(int, auto)
|
The number of jobs to run in parallel. If |
`'auto'`
|
show_progress |
bool
|
Whether to show a progress bar. |
`True`
|
suppress_warnings |
bool
|
If |
False
|
suppress_warnings_fit |
bool
|
If |
`False`
|
Returns:
Type | Description |
---|---|
None
|
|
Source code in skforecast\model_selection\_utils.py
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 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
|
skforecast.model_selection._utils.select_n_jobs_backtesting ¶
select_n_jobs_backtesting(forecaster, refit)
Select the optimal number of jobs to use in the backtesting process. This selection is based on heuristics and is not guaranteed to be optimal.
The number of jobs is chosen as follows:
- If
refit
is an integer, thenn_jobs = 1
. This is because parallelization doesn't work with intermittent refit. - If forecaster is 'ForecasterRecursive' and regressor is a linear regressor,
then
n_jobs = 1
. - If forecaster is 'ForecasterRecursive' and regressor is not a linear
regressor then
n_jobs = cpu_count() - 1
. - If forecaster is 'ForecasterDirect' or 'ForecasterDirectMultiVariate'
and
refit = True
, thenn_jobs = cpu_count() - 1
. - If forecaster is 'ForecasterDirect' or 'ForecasterDirectMultiVariate'
and
refit = False
, thenn_jobs = 1
. - If forecaster is 'ForecasterRecursiveMultiSeries', then
n_jobs = cpu_count() - 1
. - If forecaster is 'ForecasterSarimax' or 'ForecasterEquivalentDate',
then
n_jobs = 1
. - If regressor is a
LGBMRegressor(n_jobs=1)
, thenn_jobs = cpu_count() - 1
. - If regressor is a
LGBMRegressor
with internal n_jobs != 1, thenn_jobs = 1
. This is becauselightgbm
is highly optimized for gradient boosting and parallelizes operations at a very fine-grained level, making additional parallelization unnecessary and potentially harmful due to resource contention.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
forecaster |
Forecaster
|
Forecaster model. |
required |
refit |
(bool, int)
|
If the forecaster is refitted during the backtesting process. |
required |
Returns:
Name | Type | Description |
---|---|---|
n_jobs |
int
|
The number of jobs to run in parallel. |
Source code in skforecast\model_selection\_utils.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 |
|