Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arrigonialberto86/deepar
Tensorflow implementation of Amazon DeepAR
https://github.com/arrigonialberto86/deepar
Last synced: about 1 month ago
JSON representation
Tensorflow implementation of Amazon DeepAR
- Host: GitHub
- URL: https://github.com/arrigonialberto86/deepar
- Owner: arrigonialberto86
- License: mit
- Created: 2018-11-19T20:13:08.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-10-03T20:28:24.000Z (about 3 years ago)
- Last Synced: 2024-08-04T04:01:54.473Z (5 months ago)
- Language: Python
- Size: 72.3 KB
- Stars: 305
- Watchers: 13
- Forks: 94
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- StarryDivineSky - arrigonialberto86/deepar
README
# deepar
[![Build Status](https://travis-ci.com/arrigonialberto86/deepar.svg?branch=master)](https://travis-ci.com/arrigonialberto86/deepar)
Tensorflow implementation of Amazon DeepAR
## Example usage:
Fit a univariate time series:
```python
%load_ext autoreload
%autoreload 2from tensorflow.python.framework.ops import disable_eager_execution
disable_eager_execution()from deepar.dataset.time_series import MockTs
from deepar.model.lstm import DeepARts = MockTs(dimensions=1) # you can change this for multivariate time-series!
dp_model = DeepAR(ts, epochs=50)
dp_model.instantiate_and_fit()
```Plot results with uncertainty bands:
```python
%matplotlib inline
from numpy.random import normal
import tqdm
import pandas as pd
from matplotlib import pyplot as plt
import numpy as npbatch = ts.next_batch(1, ts.n_steps)
ress = []
for i in tqdm.tqdm(range(300)):
ress.append(np.expand_dims(
dp_model.get_sample_prediction(
batch[0]
), axis=0,
))res_np = np.concatenate(ress, axis=0)
fig = plt.figure(figsize=(12, 10))for dim in range(ts.dimensions):
ax = fig.add_subplot(ts.dimensions, 1, dim+1)
res_df = pd.DataFrame(res_np[:, :, 0]).T
tot_res = res_dfax.plot(batch[1].reshape((ts.n_steps, ts.dimensions))[:, dim], linewidth=6)
tot_res['mu'] = tot_res.apply(lambda x: np.mean(x), axis=1)
tot_res['upper'] = tot_res.apply(lambda x: np.mean(x) + np.std(x), axis=1)
tot_res['lower'] = tot_res.apply(lambda x: np.mean(x) - np.std(x), axis=1)
tot_res['two_upper'] = tot_res.apply(lambda x: np.mean(x) + 2*np.std(x), axis=1)
tot_res['two_lower'] = tot_res.apply(lambda x: np.mean(x) - 2*np.std(x), axis=1)ax.plot(tot_res.mu, 'bo')
ax.plot(tot_res.mu, linewidth=2)
ax.fill_between(x = tot_res.index, y1=tot_res.lower, y2=tot_res.upper, alpha=0.5)
ax.fill_between(x = tot_res.index, y1=tot_res.two_lower, y2=tot_res.two_upper, alpha=0.5)
fig.suptitle('Prediction uncertainty')```
![Image of gaussian](imgs/prediction.png)