Welcome to the fascinating world of time series forecasting with ETNA! Whether you’re a data scientist or just someone curious about the future, ETNA makes predicting your data straightforward and intuitive. Let’s dive right into how you can use ETNA to make accurate forecasts.
Getting Started with ETNA
First off, you’ll want to prepare your data. Here’s a quick breakdown of how you can do it:
import pandas as pd
from etna.datasets import TSDataset
# Read the data
df = pd.read_csv('examples/data/example_dataset.csv')
# Create a TSDataset
df = TSDataset.to_dataset(df)
ts = TSDataset(df, freq='D')
# Choose a horizon
HORIZON = 14
# Make train test split
train_ts, test_ts = ts.train_test_split(test_size=HORIZON)
In this code, loading your data is akin to filling your kitchen with ingredients before cooking a new recipe. You gather your raw material (data), prepare it, and plan the number of servings (forecasting horizon) you aim to serve. Once your ingredients are in place, it’s time to add flavor!
Defining Transformations and Models
Next, you prepare your transforms and model. This is where the magic happens:
from etna.models import CatBoostMultiSegmentModel
from etna.transforms import *
# Prepare transforms
transforms = [
DensityOutliersTransform(in_column='target', distance_coef=3.0),
TimeSeriesImputerTransform(in_column='target', strategy='forward_fill'),
LinearTrendTransform(in_column='target'),
TrendTransform(in_column='target', out_column='trend'),
LagTransform(in_column='target', lags=list(range(HORIZON, 122)), out_column='target_lag'),
DateFlagsTransform(week_number_in_month=True, out_column='date_flag'),
FourierTransform(period=360.25, order=6, out_column='fourier'),
SegmentEncoderTransform(),
MeanTransform(in_column='target_lag_HORIZON', window=12, seasonality=7),
MeanTransform(in_column='target_lag_HORIZON', window=7),
]
# Prepare model
model = CatBoostMultiSegmentModel()
Think of these transforms as the specific techniques and flavorings a chef uses to enhance their dish. Each transform adds its unique touch to your data, much like spices elevate the taste of your favorite meal. In the end, you have a well-seasoned data set ready for prediction.
Fitting the Pipeline and Making Predictions
Now it’s time to fit your model and make predictions:
from etna.pipeline import Pipeline
# Create and fit the pipeline
pipeline = Pipeline(model=model, transforms=transforms, horizon=HORIZON)
pipeline.fit(train_ts)
# Make a forecast
forecast_ts = pipeline.forecast()
Fitting the pipeline is like placing your dish in the oven; you need to give it the right amount of time to cook properly. After waiting patiently, you can finally unveil your beautifully forecasted results!
Plotting the Results
Visual representation of your predictions can bring clarity. Use the following code to plot the results:
from etna.analysis import plot_forecast
plot_forecast(forecast_ts=forecast_ts, test_ts=test_ts, train_ts=train_ts, n_train_samples=50)
Measuring Accuracy
Finally, measure the accuracy of your predictions using the SMAPE metric:
from etna.metrics import SMAPE
metric = SMAPE(mode='macro')
metric_value = metric(y_true=test_ts, y_pred=forecast_ts)
This is like tasting your dish to ensure it’s just right; measuring accuracy allows you to assess how well your predictions aligned with actual outcomes.
Installation
ETNA is available on PyPI, and you can install it via pip:
pip install --upgrade pip
pip install etna
Various extensions are available for different functionalities. Just specify the extension name like so:
pip install etna[extension-name]
Troubleshooting
If you encounter issues, ensure all necessary extensions are installed, especially before using models requiring them. For instance, using the ProphetModel necessitates the prophet extension. If absent, you will face an ImportError.
Another common problem could arise from the configuration files. Make sure you have all dependencies outlined in your project’s .etna file. To explore all options, check out the [Settings](https://github.com/tinkoff-ai/etna/blob/master/etna/settings.py#L68).
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
Conclusion
With ETNA, you’re equipped to turn raw data into insightful predictions effortlessly. Follow these steps and embrace the power of time series forecasting!
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

