autots 0.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- AutoTS-0.0.2/.gitignore +104 -0
- AutoTS-0.0.2/AutoTS.egg-info/PKG-INFO +167 -0
- AutoTS-0.0.2/AutoTS.egg-info/SOURCES.txt +37 -0
- AutoTS-0.0.2/AutoTS.egg-info/dependency_links.txt +1 -0
- AutoTS-0.0.2/AutoTS.egg-info/requires.txt +9 -0
- AutoTS-0.0.2/AutoTS.egg-info/top_level.txt +1 -0
- AutoTS-0.0.2/LICENSE +21 -0
- AutoTS-0.0.2/MANIFEST.in +2 -0
- AutoTS-0.0.2/PKG-INFO +167 -0
- AutoTS-0.0.2/README.md +151 -0
- AutoTS-0.0.2/autots/__init__.py +16 -0
- AutoTS-0.0.2/autots/datasets/__init__.py +6 -0
- AutoTS-0.0.2/autots/datasets/_base.py +16 -0
- AutoTS-0.0.2/autots/datasets/data/toy_daily.csv +431 -0
- AutoTS-0.0.2/autots/datasets/fred.py +54 -0
- AutoTS-0.0.2/autots/evaluator/__init__.py +4 -0
- AutoTS-0.0.2/autots/evaluator/auto_model.py +633 -0
- AutoTS-0.0.2/autots/evaluator/auto_ts.py +478 -0
- AutoTS-0.0.2/autots/evaluator/metrics.py +156 -0
- AutoTS-0.0.2/autots/models/basics.py +211 -0
- AutoTS-0.0.2/autots/models/ensemble.py +158 -0
- AutoTS-0.0.2/autots/models/prophet.py +146 -0
- AutoTS-0.0.2/autots/models/sklearn.py +163 -0
- AutoTS-0.0.2/autots/models/statsmodels.py +332 -0
- AutoTS-0.0.2/autots/tools/__init__.py +3 -0
- AutoTS-0.0.2/autots/tools/holiday.py +40 -0
- AutoTS-0.0.2/autots/tools/impute.py +105 -0
- AutoTS-0.0.2/autots/tools/probabilistic.py +102 -0
- AutoTS-0.0.2/autots/tools/profile.py +25 -0
- AutoTS-0.0.2/autots/tools/shaping.py +254 -0
- AutoTS-0.0.2/autots/tools/transform.py +416 -0
- AutoTS-0.0.2/docs/Makefile +20 -0
- AutoTS-0.0.2/docs/conf.py +55 -0
- AutoTS-0.0.2/docs/index.rst +20 -0
- AutoTS-0.0.2/docs/make.bat +35 -0
- AutoTS-0.0.2/setup.cfg +4 -0
- AutoTS-0.0.2/setup.py +34 -0
- AutoTS-0.0.2/standalone.py +1826 -0
- AutoTS-0.0.2/test.py +82 -0
AutoTS-0.0.2/.gitignore
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
*.egg-info/
|
|
24
|
+
.installed.cfg
|
|
25
|
+
*.egg
|
|
26
|
+
MANIFEST
|
|
27
|
+
|
|
28
|
+
# PyInstaller
|
|
29
|
+
# Usually these files are written by a python script from a template
|
|
30
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
31
|
+
*.manifest
|
|
32
|
+
*.spec
|
|
33
|
+
|
|
34
|
+
# Installer logs
|
|
35
|
+
pip-log.txt
|
|
36
|
+
pip-delete-this-directory.txt
|
|
37
|
+
|
|
38
|
+
# Unit test / coverage reports
|
|
39
|
+
htmlcov/
|
|
40
|
+
.tox/
|
|
41
|
+
.coverage
|
|
42
|
+
.coverage.*
|
|
43
|
+
.cache
|
|
44
|
+
nosetests.xml
|
|
45
|
+
coverage.xml
|
|
46
|
+
*.cover
|
|
47
|
+
.hypothesis/
|
|
48
|
+
.pytest_cache/
|
|
49
|
+
|
|
50
|
+
# Translations
|
|
51
|
+
*.mo
|
|
52
|
+
*.pot
|
|
53
|
+
|
|
54
|
+
# Django stuff:
|
|
55
|
+
*.log
|
|
56
|
+
local_settings.py
|
|
57
|
+
db.sqlite3
|
|
58
|
+
|
|
59
|
+
# Flask stuff:
|
|
60
|
+
instance/
|
|
61
|
+
.webassets-cache
|
|
62
|
+
|
|
63
|
+
# Scrapy stuff:
|
|
64
|
+
.scrapy
|
|
65
|
+
|
|
66
|
+
# Sphinx documentation
|
|
67
|
+
docs/_build/
|
|
68
|
+
|
|
69
|
+
# PyBuilder
|
|
70
|
+
target/
|
|
71
|
+
|
|
72
|
+
# Jupyter Notebook
|
|
73
|
+
.ipynb_checkpoints
|
|
74
|
+
|
|
75
|
+
# pyenv
|
|
76
|
+
.python-version
|
|
77
|
+
|
|
78
|
+
# celery beat schedule file
|
|
79
|
+
celerybeat-schedule
|
|
80
|
+
|
|
81
|
+
# SageMath parsed files
|
|
82
|
+
*.sage.py
|
|
83
|
+
|
|
84
|
+
# Environments
|
|
85
|
+
.env
|
|
86
|
+
.venv
|
|
87
|
+
env/
|
|
88
|
+
venv/
|
|
89
|
+
ENV/
|
|
90
|
+
env.bak/
|
|
91
|
+
venv.bak/
|
|
92
|
+
|
|
93
|
+
# Spyder project settings
|
|
94
|
+
.spyderproject
|
|
95
|
+
.spyproject
|
|
96
|
+
|
|
97
|
+
# Rope project settings
|
|
98
|
+
.ropeproject
|
|
99
|
+
|
|
100
|
+
# mkdocs documentation
|
|
101
|
+
/site
|
|
102
|
+
|
|
103
|
+
# mypy
|
|
104
|
+
.mypy_cache/
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: AutoTS
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Automated Time Series Forecasting
|
|
5
|
+
Home-page: https://github.com/winedarksea/AutoTS
|
|
6
|
+
Author: Colin Catlin
|
|
7
|
+
Author-email: colin.catlin@syllepsis.live
|
|
8
|
+
License: MIT
|
|
9
|
+
Description: # AutoTS
|
|
10
|
+
Unstable prototype: version 0.0.2
|
|
11
|
+
### Project CATS (Catlin Automated Time Series)
|
|
12
|
+
(or maybe eventually: Clustered Automated Time Series)
|
|
13
|
+
#### Model Selection for Multiple Time Series
|
|
14
|
+
|
|
15
|
+
Simple package for comparing and predicting with open-source time series implementations.
|
|
16
|
+
For other time series needs, check out the package list here: https://github.com/MaxBenChrist/awesome_time_series_in_python
|
|
17
|
+
|
|
18
|
+
`pip install autots`
|
|
19
|
+
#### Requirements:
|
|
20
|
+
Python >= 3.5 (typing) >= 3.6 (GluonTS)
|
|
21
|
+
pandas
|
|
22
|
+
sklearn >= 0.20.0 (ColumnTransformer)
|
|
23
|
+
statsmodels
|
|
24
|
+
holidays
|
|
25
|
+
|
|
26
|
+
`pip install autots['additional models']`
|
|
27
|
+
#### Requirements
|
|
28
|
+
fbprophet
|
|
29
|
+
fredapi (example datasets)
|
|
30
|
+
|
|
31
|
+
## Basic Use
|
|
32
|
+
Input data is expected to come in a 'long' format with three columns: Date (ideally already in pd.DateTime format), Value, and Series ID. the column name for each of these is passed to .fit(). For a single time series, series_id can be = None.
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
from autots.datasets import load_toy_daily
|
|
36
|
+
df_long = load_toy_daily()
|
|
37
|
+
|
|
38
|
+
from autots import AutoTS
|
|
39
|
+
model = AutoTS(forecast_length = 14, frequency = 'infer',
|
|
40
|
+
prediction_interval = 0.9, ensemble = True, weighted = False,
|
|
41
|
+
max_generations = 5, num_validations = 2, validation_method = 'even')
|
|
42
|
+
model = model.fit(df_long, date_col = 'date', value_col = 'value', id_col = 'series_id' )
|
|
43
|
+
|
|
44
|
+
# Print the name of the best mode
|
|
45
|
+
print(model.best_model['Model'].iloc[0])
|
|
46
|
+
|
|
47
|
+
prediction = model.predict()
|
|
48
|
+
# point forecasts dataframe
|
|
49
|
+
forecasts_df = prediction.forecast
|
|
50
|
+
# accuracy of all tried model results (not including cross validation)
|
|
51
|
+
model_results = model.main_results.model_results
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Underlying Process
|
|
55
|
+
AutoTS works in the following way at present:
|
|
56
|
+
* It begins by taking long data and converting it to a wide dataframe with DateTimeIndex
|
|
57
|
+
* An initial train/test split is generated where the test is the most recent data, of forecast_length
|
|
58
|
+
* A random template of models is generated and tested on the initial train/test
|
|
59
|
+
* Models consist of a pre-transformation step (fill na options, outlier removal options, etc), and algorithm (ie ETS) and model paramters (trend, damped, etc)
|
|
60
|
+
* The top models (selected by a combination of SMAPE, MAE, RMSE) are recombined with random mutations for n_generations
|
|
61
|
+
* A handful of the best models from this process go to cross validation, where they are re-assessed on new train/test splits.
|
|
62
|
+
* The best model in validation is selected as best_model and used in the .predict() method to generate forecasts.
|
|
63
|
+
|
|
64
|
+
## Caveats and Advice
|
|
65
|
+
|
|
66
|
+
#### Short Training History
|
|
67
|
+
How much data is 'too little' depends on the seasonality and volatility of the data.
|
|
68
|
+
But less than half a year of daily data or less than two years of monthly data are both going to be tight.
|
|
69
|
+
Minimal training data most greatly impacts the ability to do proper cross validation. Set num_validations = 0 in such cases.
|
|
70
|
+
Since ensembles are based on the test dataset, it would also be wise to set ensemble = False if num_validations = 0.
|
|
71
|
+
|
|
72
|
+
#### Too much training data.
|
|
73
|
+
Too much data is already handled to some extent by 'context_slicer' in the transformations, which tests using less training data.
|
|
74
|
+
That said, large datasets will be slower and more memory intensive, for high frequency data (say hourly) it can often be advisable to roll that up to a higher level (daily, hourly, etc.).
|
|
75
|
+
Rollup can be accomplished by specifying the frequency = your rollup frequency, and then setting the agg_func = 'sum' or 'mean' or other appropriate statistic.
|
|
76
|
+
|
|
77
|
+
#### Lots of NaN in data
|
|
78
|
+
Various NaN filling techniques are tested in the transformation. Rolling up data to a lower frequency may also help deal with NaNs.
|
|
79
|
+
|
|
80
|
+
#### More than one preord regressor
|
|
81
|
+
'Preord' regressor stands for 'Preordained' regressor, to make it clear this is data that will be know with high certainy about the future.
|
|
82
|
+
Such data about the future is rare, one example might be number of stores that will be (planned to be) open each given day in the future when forecast sales.
|
|
83
|
+
Since many algorithms do not handle more than one regressor, only one is handled here. If you would like to use more than one,
|
|
84
|
+
manually select the best variable or use dimensionality reduction to reduce the features to one dimension.
|
|
85
|
+
However, the model can handle quite a lot of parallel time series. Additional regressors can be passed through as additional time series to forecast.
|
|
86
|
+
The regression models here can utilize the information they provide to help improve forecast quality.
|
|
87
|
+
To prevent forecast accuracy for considering these additional series too heavily, input series weights that lower or remove their forecast accuracy from consideration.
|
|
88
|
+
|
|
89
|
+
#### Categorical Data
|
|
90
|
+
Categorical data is handled, but it is handled poorly. For example, optimization metrics do not currently include any categorical accuracy metrics.
|
|
91
|
+
For categorical data that has a meaningful order (ie 'low', 'medium', 'high') it is best for the user to encode that data before passing it in,
|
|
92
|
+
thus properly capturing the relative sequence (ie 'low' = 1, 'medium' = 2, 'high' = 3).
|
|
93
|
+
|
|
94
|
+
#### Custom Metrics
|
|
95
|
+
Implementing new metrics is rather difficult. However the internal 'Score' that compares models can easily be adjusted by passing through custom metric weights.
|
|
96
|
+
Higher weighting increases the importance of that metric.
|
|
97
|
+
`metric_weighting = {'smape_weighting' : 9, 'mae_weighting' : 1, 'rmse_weighting' : 5, 'containment_weighting' : 1, 'runtime_weighting' : 0.5}`
|
|
98
|
+
sMAPE is generally the most versatile across multiple series, but doesn't handle forecasts with lots of zeroes well.
|
|
99
|
+
Contaiment measures the percent of test data that falls between the upper and lower forecasts.
|
|
100
|
+
|
|
101
|
+
## To-Do
|
|
102
|
+
* Smaller
|
|
103
|
+
* Recombine best two of each model, if two or more present
|
|
104
|
+
* Duplicates still seem to be occurring in the genetic template runs
|
|
105
|
+
* Inf appearing in MAE and RMSE (possibly all NaN in test)
|
|
106
|
+
* Na Tolerance for test in simple_train_test_split
|
|
107
|
+
* Relative/Absolute Imports and reduce package reloading
|
|
108
|
+
* User regressor to sklearn model regression_type
|
|
109
|
+
* Import/export template
|
|
110
|
+
* ARIMA + Detrend fails
|
|
111
|
+
* Things needing testing:
|
|
112
|
+
* Confirm per_series weighting works properly
|
|
113
|
+
* Passing in Start Dates - (Test)
|
|
114
|
+
* Different frequencies
|
|
115
|
+
* Various verbose inputs
|
|
116
|
+
* Test holidays on non-daily data
|
|
117
|
+
* Handle categorical forecasts where forecast leaves known values
|
|
118
|
+
* Speed improvements, Profiling, Parallelization, and Distributed options for general greater speed
|
|
119
|
+
* Generate list of functional frequences, and improve usability on rarer frequenices
|
|
120
|
+
* Warning/handling if lots of NaN in most recent (test) part of data
|
|
121
|
+
* Figures: Add option to output figures of train/test + forecast, other performance figures
|
|
122
|
+
* Input and Output saved templates as .csv and .json
|
|
123
|
+
* 'Check Package' to check if optional model packages are installed
|
|
124
|
+
* Pre-clustering on many time series
|
|
125
|
+
* If all input are Int, convert floats back to int
|
|
126
|
+
* Trim whitespace on string inputs
|
|
127
|
+
* Hierachial correction (bottom-up to start with)
|
|
128
|
+
* Improved verbosity controls and options. Replace most 'print' with logging.
|
|
129
|
+
* Export as simpler code (as TPOT)
|
|
130
|
+
* AIC metric, other accuracy metrics
|
|
131
|
+
* Analyze and return inaccuracy patterns (most inaccurate periods out, days of week, most inaccurate series)
|
|
132
|
+
* Used saved results to resume a search partway through
|
|
133
|
+
* Generally improved probabilistic forecasting
|
|
134
|
+
* Option to drop series which haven't had a value in last N days
|
|
135
|
+
* Option to change which metric is being used for model selections
|
|
136
|
+
* Use quantile of training data to provide upper/lower forecast for Last Value Naive (so upper forecast might be 95th percentile largest number)
|
|
137
|
+
* More thorough use of setting random seed
|
|
138
|
+
* For monthly data account for number of days in month
|
|
139
|
+
* Option to run generations until generations no longer see improvement of at least X % over n generations
|
|
140
|
+
|
|
141
|
+
#### New Ensembles:
|
|
142
|
+
best 3 (unique algorithms not just variations)
|
|
143
|
+
forecast distance 30/30/30
|
|
144
|
+
best per series ensemble
|
|
145
|
+
best point with best probalistic containment
|
|
146
|
+
#### New models:
|
|
147
|
+
Seasonal Naive
|
|
148
|
+
Last Value + Drift Naive
|
|
149
|
+
Simple Decomposition forecasting
|
|
150
|
+
GluonTS Models
|
|
151
|
+
Simulations
|
|
152
|
+
Sklearn + TSFresh
|
|
153
|
+
Sklearn + polynomial features
|
|
154
|
+
Sktime
|
|
155
|
+
Ta-lib
|
|
156
|
+
tslearn
|
|
157
|
+
pydlm
|
|
158
|
+
Isotonic regression
|
|
159
|
+
TPOT if it adds multioutput functionality
|
|
160
|
+
|
|
161
|
+
Platform: UNKNOWN
|
|
162
|
+
Classifier: Programming Language :: Python :: 3
|
|
163
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
164
|
+
Classifier: Operating System :: OS Independent
|
|
165
|
+
Requires-Python: >=3.6
|
|
166
|
+
Description-Content-Type: text/markdown
|
|
167
|
+
Provides-Extra: additional models
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
.gitignore
|
|
2
|
+
LICENSE
|
|
3
|
+
MANIFEST.in
|
|
4
|
+
README.md
|
|
5
|
+
setup.py
|
|
6
|
+
standalone.py
|
|
7
|
+
test.py
|
|
8
|
+
AutoTS.egg-info/PKG-INFO
|
|
9
|
+
AutoTS.egg-info/SOURCES.txt
|
|
10
|
+
AutoTS.egg-info/dependency_links.txt
|
|
11
|
+
AutoTS.egg-info/requires.txt
|
|
12
|
+
AutoTS.egg-info/top_level.txt
|
|
13
|
+
autots/__init__.py
|
|
14
|
+
autots/datasets/__init__.py
|
|
15
|
+
autots/datasets/_base.py
|
|
16
|
+
autots/datasets/fred.py
|
|
17
|
+
autots/datasets/data/toy_daily.csv
|
|
18
|
+
autots/evaluator/__init__.py
|
|
19
|
+
autots/evaluator/auto_model.py
|
|
20
|
+
autots/evaluator/auto_ts.py
|
|
21
|
+
autots/evaluator/metrics.py
|
|
22
|
+
autots/models/basics.py
|
|
23
|
+
autots/models/ensemble.py
|
|
24
|
+
autots/models/prophet.py
|
|
25
|
+
autots/models/sklearn.py
|
|
26
|
+
autots/models/statsmodels.py
|
|
27
|
+
autots/tools/__init__.py
|
|
28
|
+
autots/tools/holiday.py
|
|
29
|
+
autots/tools/impute.py
|
|
30
|
+
autots/tools/probabilistic.py
|
|
31
|
+
autots/tools/profile.py
|
|
32
|
+
autots/tools/shaping.py
|
|
33
|
+
autots/tools/transform.py
|
|
34
|
+
docs/Makefile
|
|
35
|
+
docs/conf.py
|
|
36
|
+
docs/index.rst
|
|
37
|
+
docs/make.bat
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
autots
|
AutoTS-0.0.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Colin Catlin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
AutoTS-0.0.2/MANIFEST.in
ADDED
AutoTS-0.0.2/PKG-INFO
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: AutoTS
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Automated Time Series Forecasting
|
|
5
|
+
Home-page: https://github.com/winedarksea/AutoTS
|
|
6
|
+
Author: Colin Catlin
|
|
7
|
+
Author-email: colin.catlin@syllepsis.live
|
|
8
|
+
License: MIT
|
|
9
|
+
Description: # AutoTS
|
|
10
|
+
Unstable prototype: version 0.0.2
|
|
11
|
+
### Project CATS (Catlin Automated Time Series)
|
|
12
|
+
(or maybe eventually: Clustered Automated Time Series)
|
|
13
|
+
#### Model Selection for Multiple Time Series
|
|
14
|
+
|
|
15
|
+
Simple package for comparing and predicting with open-source time series implementations.
|
|
16
|
+
For other time series needs, check out the package list here: https://github.com/MaxBenChrist/awesome_time_series_in_python
|
|
17
|
+
|
|
18
|
+
`pip install autots`
|
|
19
|
+
#### Requirements:
|
|
20
|
+
Python >= 3.5 (typing) >= 3.6 (GluonTS)
|
|
21
|
+
pandas
|
|
22
|
+
sklearn >= 0.20.0 (ColumnTransformer)
|
|
23
|
+
statsmodels
|
|
24
|
+
holidays
|
|
25
|
+
|
|
26
|
+
`pip install autots['additional models']`
|
|
27
|
+
#### Requirements
|
|
28
|
+
fbprophet
|
|
29
|
+
fredapi (example datasets)
|
|
30
|
+
|
|
31
|
+
## Basic Use
|
|
32
|
+
Input data is expected to come in a 'long' format with three columns: Date (ideally already in pd.DateTime format), Value, and Series ID. the column name for each of these is passed to .fit(). For a single time series, series_id can be = None.
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
from autots.datasets import load_toy_daily
|
|
36
|
+
df_long = load_toy_daily()
|
|
37
|
+
|
|
38
|
+
from autots import AutoTS
|
|
39
|
+
model = AutoTS(forecast_length = 14, frequency = 'infer',
|
|
40
|
+
prediction_interval = 0.9, ensemble = True, weighted = False,
|
|
41
|
+
max_generations = 5, num_validations = 2, validation_method = 'even')
|
|
42
|
+
model = model.fit(df_long, date_col = 'date', value_col = 'value', id_col = 'series_id' )
|
|
43
|
+
|
|
44
|
+
# Print the name of the best mode
|
|
45
|
+
print(model.best_model['Model'].iloc[0])
|
|
46
|
+
|
|
47
|
+
prediction = model.predict()
|
|
48
|
+
# point forecasts dataframe
|
|
49
|
+
forecasts_df = prediction.forecast
|
|
50
|
+
# accuracy of all tried model results (not including cross validation)
|
|
51
|
+
model_results = model.main_results.model_results
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Underlying Process
|
|
55
|
+
AutoTS works in the following way at present:
|
|
56
|
+
* It begins by taking long data and converting it to a wide dataframe with DateTimeIndex
|
|
57
|
+
* An initial train/test split is generated where the test is the most recent data, of forecast_length
|
|
58
|
+
* A random template of models is generated and tested on the initial train/test
|
|
59
|
+
* Models consist of a pre-transformation step (fill na options, outlier removal options, etc), and algorithm (ie ETS) and model paramters (trend, damped, etc)
|
|
60
|
+
* The top models (selected by a combination of SMAPE, MAE, RMSE) are recombined with random mutations for n_generations
|
|
61
|
+
* A handful of the best models from this process go to cross validation, where they are re-assessed on new train/test splits.
|
|
62
|
+
* The best model in validation is selected as best_model and used in the .predict() method to generate forecasts.
|
|
63
|
+
|
|
64
|
+
## Caveats and Advice
|
|
65
|
+
|
|
66
|
+
#### Short Training History
|
|
67
|
+
How much data is 'too little' depends on the seasonality and volatility of the data.
|
|
68
|
+
But less than half a year of daily data or less than two years of monthly data are both going to be tight.
|
|
69
|
+
Minimal training data most greatly impacts the ability to do proper cross validation. Set num_validations = 0 in such cases.
|
|
70
|
+
Since ensembles are based on the test dataset, it would also be wise to set ensemble = False if num_validations = 0.
|
|
71
|
+
|
|
72
|
+
#### Too much training data.
|
|
73
|
+
Too much data is already handled to some extent by 'context_slicer' in the transformations, which tests using less training data.
|
|
74
|
+
That said, large datasets will be slower and more memory intensive, for high frequency data (say hourly) it can often be advisable to roll that up to a higher level (daily, hourly, etc.).
|
|
75
|
+
Rollup can be accomplished by specifying the frequency = your rollup frequency, and then setting the agg_func = 'sum' or 'mean' or other appropriate statistic.
|
|
76
|
+
|
|
77
|
+
#### Lots of NaN in data
|
|
78
|
+
Various NaN filling techniques are tested in the transformation. Rolling up data to a lower frequency may also help deal with NaNs.
|
|
79
|
+
|
|
80
|
+
#### More than one preord regressor
|
|
81
|
+
'Preord' regressor stands for 'Preordained' regressor, to make it clear this is data that will be know with high certainy about the future.
|
|
82
|
+
Such data about the future is rare, one example might be number of stores that will be (planned to be) open each given day in the future when forecast sales.
|
|
83
|
+
Since many algorithms do not handle more than one regressor, only one is handled here. If you would like to use more than one,
|
|
84
|
+
manually select the best variable or use dimensionality reduction to reduce the features to one dimension.
|
|
85
|
+
However, the model can handle quite a lot of parallel time series. Additional regressors can be passed through as additional time series to forecast.
|
|
86
|
+
The regression models here can utilize the information they provide to help improve forecast quality.
|
|
87
|
+
To prevent forecast accuracy for considering these additional series too heavily, input series weights that lower or remove their forecast accuracy from consideration.
|
|
88
|
+
|
|
89
|
+
#### Categorical Data
|
|
90
|
+
Categorical data is handled, but it is handled poorly. For example, optimization metrics do not currently include any categorical accuracy metrics.
|
|
91
|
+
For categorical data that has a meaningful order (ie 'low', 'medium', 'high') it is best for the user to encode that data before passing it in,
|
|
92
|
+
thus properly capturing the relative sequence (ie 'low' = 1, 'medium' = 2, 'high' = 3).
|
|
93
|
+
|
|
94
|
+
#### Custom Metrics
|
|
95
|
+
Implementing new metrics is rather difficult. However the internal 'Score' that compares models can easily be adjusted by passing through custom metric weights.
|
|
96
|
+
Higher weighting increases the importance of that metric.
|
|
97
|
+
`metric_weighting = {'smape_weighting' : 9, 'mae_weighting' : 1, 'rmse_weighting' : 5, 'containment_weighting' : 1, 'runtime_weighting' : 0.5}`
|
|
98
|
+
sMAPE is generally the most versatile across multiple series, but doesn't handle forecasts with lots of zeroes well.
|
|
99
|
+
Contaiment measures the percent of test data that falls between the upper and lower forecasts.
|
|
100
|
+
|
|
101
|
+
## To-Do
|
|
102
|
+
* Smaller
|
|
103
|
+
* Recombine best two of each model, if two or more present
|
|
104
|
+
* Duplicates still seem to be occurring in the genetic template runs
|
|
105
|
+
* Inf appearing in MAE and RMSE (possibly all NaN in test)
|
|
106
|
+
* Na Tolerance for test in simple_train_test_split
|
|
107
|
+
* Relative/Absolute Imports and reduce package reloading
|
|
108
|
+
* User regressor to sklearn model regression_type
|
|
109
|
+
* Import/export template
|
|
110
|
+
* ARIMA + Detrend fails
|
|
111
|
+
* Things needing testing:
|
|
112
|
+
* Confirm per_series weighting works properly
|
|
113
|
+
* Passing in Start Dates - (Test)
|
|
114
|
+
* Different frequencies
|
|
115
|
+
* Various verbose inputs
|
|
116
|
+
* Test holidays on non-daily data
|
|
117
|
+
* Handle categorical forecasts where forecast leaves known values
|
|
118
|
+
* Speed improvements, Profiling, Parallelization, and Distributed options for general greater speed
|
|
119
|
+
* Generate list of functional frequences, and improve usability on rarer frequenices
|
|
120
|
+
* Warning/handling if lots of NaN in most recent (test) part of data
|
|
121
|
+
* Figures: Add option to output figures of train/test + forecast, other performance figures
|
|
122
|
+
* Input and Output saved templates as .csv and .json
|
|
123
|
+
* 'Check Package' to check if optional model packages are installed
|
|
124
|
+
* Pre-clustering on many time series
|
|
125
|
+
* If all input are Int, convert floats back to int
|
|
126
|
+
* Trim whitespace on string inputs
|
|
127
|
+
* Hierachial correction (bottom-up to start with)
|
|
128
|
+
* Improved verbosity controls and options. Replace most 'print' with logging.
|
|
129
|
+
* Export as simpler code (as TPOT)
|
|
130
|
+
* AIC metric, other accuracy metrics
|
|
131
|
+
* Analyze and return inaccuracy patterns (most inaccurate periods out, days of week, most inaccurate series)
|
|
132
|
+
* Used saved results to resume a search partway through
|
|
133
|
+
* Generally improved probabilistic forecasting
|
|
134
|
+
* Option to drop series which haven't had a value in last N days
|
|
135
|
+
* Option to change which metric is being used for model selections
|
|
136
|
+
* Use quantile of training data to provide upper/lower forecast for Last Value Naive (so upper forecast might be 95th percentile largest number)
|
|
137
|
+
* More thorough use of setting random seed
|
|
138
|
+
* For monthly data account for number of days in month
|
|
139
|
+
* Option to run generations until generations no longer see improvement of at least X % over n generations
|
|
140
|
+
|
|
141
|
+
#### New Ensembles:
|
|
142
|
+
best 3 (unique algorithms not just variations)
|
|
143
|
+
forecast distance 30/30/30
|
|
144
|
+
best per series ensemble
|
|
145
|
+
best point with best probalistic containment
|
|
146
|
+
#### New models:
|
|
147
|
+
Seasonal Naive
|
|
148
|
+
Last Value + Drift Naive
|
|
149
|
+
Simple Decomposition forecasting
|
|
150
|
+
GluonTS Models
|
|
151
|
+
Simulations
|
|
152
|
+
Sklearn + TSFresh
|
|
153
|
+
Sklearn + polynomial features
|
|
154
|
+
Sktime
|
|
155
|
+
Ta-lib
|
|
156
|
+
tslearn
|
|
157
|
+
pydlm
|
|
158
|
+
Isotonic regression
|
|
159
|
+
TPOT if it adds multioutput functionality
|
|
160
|
+
|
|
161
|
+
Platform: UNKNOWN
|
|
162
|
+
Classifier: Programming Language :: Python :: 3
|
|
163
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
164
|
+
Classifier: Operating System :: OS Independent
|
|
165
|
+
Requires-Python: >=3.6
|
|
166
|
+
Description-Content-Type: text/markdown
|
|
167
|
+
Provides-Extra: additional models
|
AutoTS-0.0.2/README.md
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# AutoTS
|
|
2
|
+
Unstable prototype: version 0.0.2
|
|
3
|
+
### Project CATS (Catlin Automated Time Series)
|
|
4
|
+
(or maybe eventually: Clustered Automated Time Series)
|
|
5
|
+
#### Model Selection for Multiple Time Series
|
|
6
|
+
|
|
7
|
+
Simple package for comparing and predicting with open-source time series implementations.
|
|
8
|
+
For other time series needs, check out the package list here: https://github.com/MaxBenChrist/awesome_time_series_in_python
|
|
9
|
+
|
|
10
|
+
`pip install autots`
|
|
11
|
+
#### Requirements:
|
|
12
|
+
Python >= 3.5 (typing) >= 3.6 (GluonTS)
|
|
13
|
+
pandas
|
|
14
|
+
sklearn >= 0.20.0 (ColumnTransformer)
|
|
15
|
+
statsmodels
|
|
16
|
+
holidays
|
|
17
|
+
|
|
18
|
+
`pip install autots['additional models']`
|
|
19
|
+
#### Requirements
|
|
20
|
+
fbprophet
|
|
21
|
+
fredapi (example datasets)
|
|
22
|
+
|
|
23
|
+
## Basic Use
|
|
24
|
+
Input data is expected to come in a 'long' format with three columns: Date (ideally already in pd.DateTime format), Value, and Series ID. the column name for each of these is passed to .fit(). For a single time series, series_id can be = None.
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
from autots.datasets import load_toy_daily
|
|
28
|
+
df_long = load_toy_daily()
|
|
29
|
+
|
|
30
|
+
from autots import AutoTS
|
|
31
|
+
model = AutoTS(forecast_length = 14, frequency = 'infer',
|
|
32
|
+
prediction_interval = 0.9, ensemble = True, weighted = False,
|
|
33
|
+
max_generations = 5, num_validations = 2, validation_method = 'even')
|
|
34
|
+
model = model.fit(df_long, date_col = 'date', value_col = 'value', id_col = 'series_id' )
|
|
35
|
+
|
|
36
|
+
# Print the name of the best mode
|
|
37
|
+
print(model.best_model['Model'].iloc[0])
|
|
38
|
+
|
|
39
|
+
prediction = model.predict()
|
|
40
|
+
# point forecasts dataframe
|
|
41
|
+
forecasts_df = prediction.forecast
|
|
42
|
+
# accuracy of all tried model results (not including cross validation)
|
|
43
|
+
model_results = model.main_results.model_results
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Underlying Process
|
|
47
|
+
AutoTS works in the following way at present:
|
|
48
|
+
* It begins by taking long data and converting it to a wide dataframe with DateTimeIndex
|
|
49
|
+
* An initial train/test split is generated where the test is the most recent data, of forecast_length
|
|
50
|
+
* A random template of models is generated and tested on the initial train/test
|
|
51
|
+
* Models consist of a pre-transformation step (fill na options, outlier removal options, etc), and algorithm (ie ETS) and model paramters (trend, damped, etc)
|
|
52
|
+
* The top models (selected by a combination of SMAPE, MAE, RMSE) are recombined with random mutations for n_generations
|
|
53
|
+
* A handful of the best models from this process go to cross validation, where they are re-assessed on new train/test splits.
|
|
54
|
+
* The best model in validation is selected as best_model and used in the .predict() method to generate forecasts.
|
|
55
|
+
|
|
56
|
+
## Caveats and Advice
|
|
57
|
+
|
|
58
|
+
#### Short Training History
|
|
59
|
+
How much data is 'too little' depends on the seasonality and volatility of the data.
|
|
60
|
+
But less than half a year of daily data or less than two years of monthly data are both going to be tight.
|
|
61
|
+
Minimal training data most greatly impacts the ability to do proper cross validation. Set num_validations = 0 in such cases.
|
|
62
|
+
Since ensembles are based on the test dataset, it would also be wise to set ensemble = False if num_validations = 0.
|
|
63
|
+
|
|
64
|
+
#### Too much training data.
|
|
65
|
+
Too much data is already handled to some extent by 'context_slicer' in the transformations, which tests using less training data.
|
|
66
|
+
That said, large datasets will be slower and more memory intensive, for high frequency data (say hourly) it can often be advisable to roll that up to a higher level (daily, hourly, etc.).
|
|
67
|
+
Rollup can be accomplished by specifying the frequency = your rollup frequency, and then setting the agg_func = 'sum' or 'mean' or other appropriate statistic.
|
|
68
|
+
|
|
69
|
+
#### Lots of NaN in data
|
|
70
|
+
Various NaN filling techniques are tested in the transformation. Rolling up data to a lower frequency may also help deal with NaNs.
|
|
71
|
+
|
|
72
|
+
#### More than one preord regressor
|
|
73
|
+
'Preord' regressor stands for 'Preordained' regressor, to make it clear this is data that will be know with high certainy about the future.
|
|
74
|
+
Such data about the future is rare, one example might be number of stores that will be (planned to be) open each given day in the future when forecast sales.
|
|
75
|
+
Since many algorithms do not handle more than one regressor, only one is handled here. If you would like to use more than one,
|
|
76
|
+
manually select the best variable or use dimensionality reduction to reduce the features to one dimension.
|
|
77
|
+
However, the model can handle quite a lot of parallel time series. Additional regressors can be passed through as additional time series to forecast.
|
|
78
|
+
The regression models here can utilize the information they provide to help improve forecast quality.
|
|
79
|
+
To prevent forecast accuracy for considering these additional series too heavily, input series weights that lower or remove their forecast accuracy from consideration.
|
|
80
|
+
|
|
81
|
+
#### Categorical Data
|
|
82
|
+
Categorical data is handled, but it is handled poorly. For example, optimization metrics do not currently include any categorical accuracy metrics.
|
|
83
|
+
For categorical data that has a meaningful order (ie 'low', 'medium', 'high') it is best for the user to encode that data before passing it in,
|
|
84
|
+
thus properly capturing the relative sequence (ie 'low' = 1, 'medium' = 2, 'high' = 3).
|
|
85
|
+
|
|
86
|
+
#### Custom Metrics
|
|
87
|
+
Implementing new metrics is rather difficult. However the internal 'Score' that compares models can easily be adjusted by passing through custom metric weights.
|
|
88
|
+
Higher weighting increases the importance of that metric.
|
|
89
|
+
`metric_weighting = {'smape_weighting' : 9, 'mae_weighting' : 1, 'rmse_weighting' : 5, 'containment_weighting' : 1, 'runtime_weighting' : 0.5}`
|
|
90
|
+
sMAPE is generally the most versatile across multiple series, but doesn't handle forecasts with lots of zeroes well.
|
|
91
|
+
Contaiment measures the percent of test data that falls between the upper and lower forecasts.
|
|
92
|
+
|
|
93
|
+
## To-Do
|
|
94
|
+
* Smaller
|
|
95
|
+
* Recombine best two of each model, if two or more present
|
|
96
|
+
* Duplicates still seem to be occurring in the genetic template runs
|
|
97
|
+
* Inf appearing in MAE and RMSE (possibly all NaN in test)
|
|
98
|
+
* Na Tolerance for test in simple_train_test_split
|
|
99
|
+
* Relative/Absolute Imports and reduce package reloading
|
|
100
|
+
* User regressor to sklearn model regression_type
|
|
101
|
+
* Import/export template
|
|
102
|
+
* ARIMA + Detrend fails
|
|
103
|
+
* Things needing testing:
|
|
104
|
+
* Confirm per_series weighting works properly
|
|
105
|
+
* Passing in Start Dates - (Test)
|
|
106
|
+
* Different frequencies
|
|
107
|
+
* Various verbose inputs
|
|
108
|
+
* Test holidays on non-daily data
|
|
109
|
+
* Handle categorical forecasts where forecast leaves known values
|
|
110
|
+
* Speed improvements, Profiling, Parallelization, and Distributed options for general greater speed
|
|
111
|
+
* Generate list of functional frequences, and improve usability on rarer frequenices
|
|
112
|
+
* Warning/handling if lots of NaN in most recent (test) part of data
|
|
113
|
+
* Figures: Add option to output figures of train/test + forecast, other performance figures
|
|
114
|
+
* Input and Output saved templates as .csv and .json
|
|
115
|
+
* 'Check Package' to check if optional model packages are installed
|
|
116
|
+
* Pre-clustering on many time series
|
|
117
|
+
* If all input are Int, convert floats back to int
|
|
118
|
+
* Trim whitespace on string inputs
|
|
119
|
+
* Hierachial correction (bottom-up to start with)
|
|
120
|
+
* Improved verbosity controls and options. Replace most 'print' with logging.
|
|
121
|
+
* Export as simpler code (as TPOT)
|
|
122
|
+
* AIC metric, other accuracy metrics
|
|
123
|
+
* Analyze and return inaccuracy patterns (most inaccurate periods out, days of week, most inaccurate series)
|
|
124
|
+
* Used saved results to resume a search partway through
|
|
125
|
+
* Generally improved probabilistic forecasting
|
|
126
|
+
* Option to drop series which haven't had a value in last N days
|
|
127
|
+
* Option to change which metric is being used for model selections
|
|
128
|
+
* Use quantile of training data to provide upper/lower forecast for Last Value Naive (so upper forecast might be 95th percentile largest number)
|
|
129
|
+
* More thorough use of setting random seed
|
|
130
|
+
* For monthly data account for number of days in month
|
|
131
|
+
* Option to run generations until generations no longer see improvement of at least X % over n generations
|
|
132
|
+
|
|
133
|
+
#### New Ensembles:
|
|
134
|
+
best 3 (unique algorithms not just variations)
|
|
135
|
+
forecast distance 30/30/30
|
|
136
|
+
best per series ensemble
|
|
137
|
+
best point with best probalistic containment
|
|
138
|
+
#### New models:
|
|
139
|
+
Seasonal Naive
|
|
140
|
+
Last Value + Drift Naive
|
|
141
|
+
Simple Decomposition forecasting
|
|
142
|
+
GluonTS Models
|
|
143
|
+
Simulations
|
|
144
|
+
Sklearn + TSFresh
|
|
145
|
+
Sklearn + polynomial features
|
|
146
|
+
Sktime
|
|
147
|
+
Ta-lib
|
|
148
|
+
tslearn
|
|
149
|
+
pydlm
|
|
150
|
+
Isotonic regression
|
|
151
|
+
TPOT if it adds multioutput functionality
|