Skip to content

Commit

Permalink
add acf plot; change eda notebook; (tinkoff-ai#318)
Browse files Browse the repository at this point in the history
* add acf plot; change eda notebook;

* add changed to changelog

Co-authored-by: an.alekseev <an.alekseev@tinkoff.ru>
  • Loading branch information
iKintosh and an.alekseev authored Nov 26, 2021
1 parent 38623dc commit c074d3b
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 414 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- ACF plot ([#318](https://github.com/tinkoff-ai/etna/pull/318))

### Changed
- Add `ts.inverse_transform` as final step at `Pipeline.fit` method ([#316](https://github.com/tinkoff-ai/etna/pull/316))

## [1.3.3] - 2021-11-24
### Added
Expand Down
1 change: 1 addition & 0 deletions etna/analysis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from etna.analysis.eda_utils import cross_corr_plot
from etna.analysis.eda_utils import distribution_plot
from etna.analysis.eda_utils import sample_acf_plot
from etna.analysis.eda_utils import sample_pacf_plot
from etna.analysis.feature_relevance.relevance import ModelRelevanceTable
from etna.analysis.feature_relevance.relevance import RelevanceTable
Expand Down
35 changes: 35 additions & 0 deletions etna/analysis/eda_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,41 @@ def cross_corr_plot(ts: "TSDataset", n_segments: int = 10, maxlags: int = 21, se
plt.show()


def sample_acf_plot(ts: "TSDataset", n_segments: int = 10, lags: int = 21, segments: Sequence = None):
"""
Autocorrelation plot for multiple timeseries.
Parameters
----------
ts:
TSDataset with timeseries data
n_segments:
number of random segments to plot
lags:
number of timeseries shifts for cross-correlation
segments:
segments to plot
Notes
-----
https://en.wikipedia.org/wiki/Autocorrelation
"""
if not segments:
segments = sorted(ts.segments)

k = min(n_segments, len(segments))
columns_num = min(2, k)
rows_num = math.ceil(k / columns_num)
fig, ax = plt.subplots(rows_num, columns_num, figsize=(20, 5 * rows_num), constrained_layout=True, squeeze=False)
ax = ax.ravel()
fig.suptitle("Partial Autocorrelation", fontsize=16)
for i, name in enumerate(sorted(np.random.choice(segments, size=k, replace=False))):
df_slice = ts[:, name, :][name]
plot_acf(x=df_slice["target"].values, ax=ax[i], lags=lags)
ax[i].set_title(name)
plt.show()


def sample_pacf_plot(ts: "TSDataset", n_segments: int = 10, lags: int = 21, segments: Sequence = None):
"""
Partial autocorrelation plot for multiple timeseries.
Expand Down
Loading

0 comments on commit c074d3b

Please sign in to comment.