Skip to content

Commit

Permalink
Dev ktrx rebase (#453)
Browse files Browse the repository at this point in the history
* Prediction Plot Bug Fix and Enhance (#428)

* Update plot.py

* fix bug and refine prediction plot

* Update quick_start.ipynb

* Update plot.py

* Predicion refactor (#430)

* resolve conflicts

* resolve conflicts

* rebase commit

* Prediction Plot Bug Fix and Enhance (#428)

* Update plot.py

* fix bug and refine prediction plot

* Update quick_start.ipynb

* Update plot.py

* rebase commit

* Refine KTRLite plotting and tutorial (#431)

* rebase from dev

* temp

* Update build_your_own_model.ipynb

* refine tutorials and ktrlite knots plotting

* Update ktrlite.ipynb

* palette and docstring

* more verbiage

Co-authored-by: Zhishi Wang <zhishiw@uber.com>

* Update build_your_own_model.ipynb

* Update build_your_own_model.ipynb

* Feat arviz (#433)

* arviz

* get_posterior_samples

* arviz plotting

* arviz demo

* rename

* fix kwargs

* refine plotting

* more robust way to extract signatures of orbit models (#438)

* more robust way to extract signatures of orbit models

* unit test for grid search

* replace regressor beta prior tuning with other params

* ktr lite house keeping (#440)

* ktr lite house keeping

- revert level knots plot
- refine tutorial
- refine some plotting code

* more house keeping

- [x] enhance unit test
- [x] relable pool
- [x] initializer of ktrlite

* notebook update

* Update test_ktrlite.py

* Update test_ktrlite.py

* add comment for stan_extract cleaning

Co-authored-by: Zhishi Wang <zhishiw@uber.com>

* ELBO Loss Extraction (#443)

* refine estimator to include training metrics for NUTS and SVI

* Update pyro_basic.ipynb

* add comment for stan_extract cleaning

Co-authored-by: Zhishi Wang <zhishiw@uber.com>

Co-authored-by: Zhishi Wang <wangzhishi@users.noreply.github.com>
Co-authored-by: Zhishi Wang <zhishiw@uber.com>

* use newly written arviz wrappers for diagnostic tutorial (#446)

* resolve conflicts

* rebase

* rebase with dev

* Update template.py

Co-authored-by: Zhishi Wang <zhishiw@uber.com>
Co-authored-by: Zhishi Wang <wangzhishi@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 3, 2021
1 parent 853d575 commit c791d50
Show file tree
Hide file tree
Showing 36 changed files with 3,199 additions and 1,597 deletions.
247 changes: 182 additions & 65 deletions docs/tutorials/build_your_own_model.ipynb

Large diffs are not rendered by default.

514 changes: 307 additions & 207 deletions docs/tutorials/ktrlite.ipynb

Large diffs are not rendered by default.

69 changes: 31 additions & 38 deletions docs/tutorials/lgt.ipynb

Large diffs are not rendered by default.

448 changes: 354 additions & 94 deletions docs/tutorials/model_diagnostics.ipynb

Large diffs are not rendered by default.

185 changes: 82 additions & 103 deletions docs/tutorials/pyro_basic.ipynb

Large diffs are not rendered by default.

27 changes: 17 additions & 10 deletions docs/tutorials/quick_start.ipynb

Large diffs are not rendered by default.

395 changes: 310 additions & 85 deletions examples/build_your_own_model.ipynb

Large diffs are not rendered by default.

179 changes: 100 additions & 79 deletions examples/ets_example.ipynb

Large diffs are not rendered by default.

279 changes: 145 additions & 134 deletions examples/hyper_parameters_tuning.ipynb

Large diffs are not rendered by default.

504 changes: 317 additions & 187 deletions examples/ktrlite.ipynb

Large diffs are not rendered by default.

File renamed without changes.
621 changes: 621 additions & 0 deletions examples/mcmc_diagnostic_arviz.ipynb

Large diffs are not rendered by default.

17 changes: 3 additions & 14 deletions orbit/constants/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,14 @@ class EstimatorOptionsMapper(Enum):
}


# TODO: consider combining this with PredictedComponents
class PredictionColumnNames(Enum):
"""
In the output of SLGTModel.transform() and SLGT.predict(), the column names if
'return_decomposed_components' = True.
"""
PREDICTED_RESPONSE = 'predicted'
LEVEL = 'level'
SEASONALITY = 'seasonality'
REGRESSOR = 'regressor'
ACTUAL_RESPONSE = 'actual'


class PredictedComponents(Enum):
class PredictionKeys(Enum):
""" column names for the data frame of predicted result with decomposed components
"""
TREND = 'trend'
SEASONALITY = 'seasonality'
REGRESSION = 'regression'
REGRESSOR = 'regressor'
PREDICTION = 'prediction'


class PlotLabels(Enum):
Expand Down
3 changes: 1 addition & 2 deletions orbit/constants/ktrlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class DataInputMapper(Enum):
KERNEL_COEFFICIENTS = 'K_COEF'
NUM_OF_REGRESSORS = 'P'
REGRESSOR_MATRIX = 'REGRESSORS'
COEFFICIENTS_KNOT_POOLING_LOC = 'COEF_KNOT_POOL_LOC'
COEFFICIENTS_KNOT_POOLING_SCALE = 'COEF_KNOT_POOL_SCALE'
COEFFICIENTS_INITIAL_KNOT_SCALE = 'COEF_INIT_KNOT_SCALE'
COEFFICIENTS_KNOT_SCALE = 'COEF_KNOT_SCALE'


Expand Down
16 changes: 13 additions & 3 deletions orbit/constants/palette.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@ class QualitativePalette(Enum):
PostQ = ['#1fc600', '#ff4500']
# large amount of stacking series
Stack = ["#12939A", "#F15C17", "#DDB27C", "#88572C", "#FF991F", "#DA70BF", "#125C77",
"#4DC19C", "#776E57", "#17B8BE", "#F6D18A", "#B7885E", "#FFCB99", "#F89570",
"#829AE3", "#E79FD5", "#1E96BE", "#89DAC1", "#B3AD9E"]
"#4DC19C", "#776E57", "#17B8BE", "#F6D18A", "#B7885E", "#FFCB99", "#F89570",
"#829AE3", "#E79FD5", "#1E96BE", "#89DAC1", "#B3AD9E"]
# bar plot
Bar5 = ["#ef476fff", "#ffd166ff", "#06d6a0ff", "#118ab2ff", "#073b4cff"]
Bar5 = ["#ef476fff", "#ffd166ff", "#06d6a0ff", "#118ab2ff", "#073b4cff"]


class OrbitPalette(Enum):
Black = '#000000'
DarkGrey = '#333131'
SafetyBlue = '#276EF1'
LightBlue = '#5B91F5'
Green = '#05A357'
Orange = '#05A357'
Yellow = '#FFC043'
44 changes: 31 additions & 13 deletions orbit/diagnostics/backtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
from copy import deepcopy
import inspect
import tqdm
from itertools import product

from .metrics import smape, wmape, mape, mse, mae, rmsse
from ..exceptions import BacktestException
from ..constants.constants import TimeSeriesSplitSchemeNames
from ..constants.palette import QualitativePalette

from itertools import product
from collections.abc import Mapping, Iterable
from orbit.diagnostics.metrics import smape, mape, wmape


class TimeSeriesSplitter(object):
Expand Down Expand Up @@ -427,18 +425,38 @@ def grid_search_orbit(param_grid, model, df, min_train_len,
data frame of tuning results
"""
def _get_params(model):
# get all the model params for orbit typed models
params = {}
for key, val in model.__dict__.items():
if not key.startswith('_') and key != 'estimator':
params[key] = val
# def _get_params(model):
# # get all the model params for orbit typed models
# params = {}
# for key, val in model.__dict__.items():
# if not key.startswith('_') and key != 'estimator':
# params[key] = val

# for key, val in model.__dict__['estimator'].__dict__.items():
# if not key.startswith('_') and key != 'stan_init':
# params[key] = val

for key, val in model.__dict__['estimator'].__dict__.items():
if not key.startswith('_') and key != 'stan_init':
params[key] = val
# return params.copy()

return params.copy()
def _get_params(model):
init_args = dict()

# get all the parent classes and their signatures
for cls in inspect.getmro(model.__class__):
sig = inspect.signature(cls)
for key in sig.parameters.keys():
if key != 'kwargs':
if hasattr(model, key):
init_args[key] = getattr(model, key)
# deal with the estimator separately
for cls in inspect.getmro(model.estimator_type):
sig = inspect.signature(cls)
for key in sig.parameters.keys():
if key != 'kwargs':
if hasattr(model.estimator, key):
init_args[key] = getattr(model.estimator, key)

return init_args.copy()

def _yield_param_grid(param_grid):
# an internal function to mimic the ParameterGrid from scikit-learn
Expand Down
Loading

0 comments on commit c791d50

Please sign in to comment.