Skip to content

Commit

Permalink
Merge branch 'master' into issue-425
Browse files Browse the repository at this point in the history
  • Loading branch information
brsnw250 authored Jul 30, 2024
2 parents 5601e99 + 3553761 commit aaa3687
Show file tree
Hide file tree
Showing 9 changed files with 702 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add `get_anomalies_mad` function for anomaly detection ([#398](https://github.com/etna-team/etna/pull/398))
- Add `TSDataset.features` property to get list of all features in a dataset ([#405](https://github.com/etna-team/etna/pull/405))
- Add `MADOutlierTransform` class for anomaly detection ([#415](https://github.com/etna-team/etna/pull/415))
- Add `MeanEncoderTransform` ([#413](https://github.com/etna-team/etna/pull/413))
- Add `FourierDecomposeTransform` transform for series decomposition using DFT ([#430](https://github.com/etna-team/etna/pull/430))

### Changed
Expand All @@ -34,7 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix rendering in 210 tutorial ([#386](https://github.com/etna-team/etna/pull/386))
- Fix typo in 103 tutorial ([#408](https://github.com/etna-team/etna/pull/408))
- Remove sorting of `ts.df` by timestamps in `plot_forecast` and `plot_forecast_decomposition` ([#410](https://github.com/etna-team/etna/pull/410))
-
- Fix forecast visualization with `horizon=1` ([#426](https://github.com/etna-team/etna/pull/426))
-
-
- Fix passing custom model to `STLTransform` ([#412](https://github.com/etna-team/etna/pull/412))
Expand Down
1 change: 1 addition & 0 deletions docs/source/api_reference/transforms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Categorical encoding transforms:
:template: class.rst

SegmentEncoderTransform
MeanEncoderTransform
MeanSegmentEncoderTransform
LabelEncoderTransform
OneHotEncoderTransform
Expand Down
23 changes: 17 additions & 6 deletions etna/analysis/forecast/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,27 @@ def plot_forecast(
plot_df = pd.DataFrame(columns=["timestamp", "target", "segment"])

if (train_ts is not None) and (n_train_samples != 0):
ax[i].plot(plot_df.index.values, plot_df.target.values, label="train")
marker = None if len(plot_df) > 1 else "o"
ax[i].plot(plot_df.index.values, plot_df.target.values, label="train", marker=marker)
if test_ts is not None:
ax[i].plot(segment_test_df.index.values, segment_test_df.target.values, color="purple", label="test")
marker = None if len(segment_test_df) > 1 else "o"
ax[i].plot(
segment_test_df.index.values, segment_test_df.target.values, color="purple", label="test", marker=marker
)

# plot forecast plot for each of given forecasts
for forecast_name, forecast in forecast_results.items():
legend_prefix = f"{forecast_name}: " if num_forecasts > 1 else ""

segment_forecast_df = forecast[:, segment, :][segment]
marker = None if len(segment_forecast_df) > 1 else "o"

line = ax[i].plot(
segment_forecast_df.index.values,
segment_forecast_df.target.values,
linewidth=1,
label=f"{legend_prefix}forecast",
marker=marker,
)
forecast_color = line[0].get_color()

Expand All @@ -182,7 +189,8 @@ def plot_forecast(
segment_borders_df.index.values,
values_low,
values_high,
facecolor=forecast_color,
linewidth=3,
color=forecast_color,
alpha=alpha[interval_idx],
label=f"{legend_prefix}{low_border}-{high_border}",
)
Expand All @@ -196,7 +204,8 @@ def plot_forecast(
segment_borders_df.index.values,
values_low,
values_next,
facecolor=forecast_color,
linewidth=3,
color=forecast_color,
alpha=alpha[interval_idx],
label=f"{legend_prefix}{low_border}-{high_border}",
)
Expand All @@ -205,17 +214,19 @@ def plot_forecast(
segment_borders_df.index.values,
values_high,
values_prev,
facecolor=forecast_color,
linewidth=3,
color=forecast_color,
alpha=alpha[interval_idx],
)
# when we can't find pair for border, we plot it separately
if len(prediction_intervals_names) % 2 != 0:
remaining_border = prediction_intervals_names[len(prediction_intervals_names) // 2]
values = segment_borders_df[remaining_border].values
marker = "--" if len(values) > 1 else "d"
ax[i].plot(
segment_borders_df.index.values,
values,
"--",
marker,
color=forecast_color,
label=f"{legend_prefix}{remaining_border}",
)
Expand Down
1 change: 1 addition & 0 deletions etna/transforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from etna.transforms.embeddings import EmbeddingSegmentTransform
from etna.transforms.embeddings import EmbeddingWindowTransform
from etna.transforms.encoders import LabelEncoderTransform
from etna.transforms.encoders import MeanEncoderTransform
from etna.transforms.encoders import MeanSegmentEncoderTransform
from etna.transforms.encoders import OneHotEncoderTransform
from etna.transforms.encoders import SegmentEncoderTransform
Expand Down
1 change: 1 addition & 0 deletions etna/transforms/encoders/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from etna.transforms.encoders.categorical import LabelEncoderTransform
from etna.transforms.encoders.categorical import OneHotEncoderTransform
from etna.transforms.encoders.mean_encoder import MeanEncoderTransform
from etna.transforms.encoders.mean_segment_encoder import MeanSegmentEncoderTransform
from etna.transforms.encoders.segment_encoder import SegmentEncoderTransform
Loading

0 comments on commit aaa3687

Please sign in to comment.