Package: etna
Predict your time series the easiest wayHomepage|Documentation|Tutorials|Contribution Guide|Release NotesETNA is an easy-to-use time series forecasting framework.
It includes built in toolkits for time series preprocessing, feature generation,
a variety of predictive models with unified interface - from classic machine learning
to SOTA neural networks, models combination methods and smart backtesting.
ETNA is designed to make working with time series simple, productive, and fun.ETNA is the first python open source framework ofTinkoff.ruArtificial Intelligence Center.
The library started as an internal product in our company -
we use it in over 10+ projects now, so we often release updates.
Contributions are welcome - check ourContribution Guide.QuickstartLet's load and prepare the data.importpandasaspdfrometna.datasetsimportTSDataset# Read the datadf=pd.read_csv("examples/data/example_dataset.csv")# Create a TSDatasetdf=TSDataset.to_dataset(df)ts=TSDataset(df,freq="D")# Choose a horizonHORIZON=14# Make train/test splittrain_ts,test_ts=ts.train_test_split(test_size=HORIZON)Define transformations and model:frometna.modelsimportCatBoostMultiSegmentModelfrometna.transformsimportDateFlagsTransformfrometna.transformsimportDensityOutliersTransformfrometna.transformsimportFourierTransformfrometna.transformsimportLagTransformfrometna.transformsimportLinearTrendTransformfrometna.transformsimportMeanTransformfrometna.transformsimportSegmentEncoderTransformfrometna.transformsimportTimeSeriesImputerTransformfrometna.transformsimportTrendTransform# Prepare transformstransforms=[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=f"target_lag_{HORIZON}",window=12,seasonality=7),MeanTransform(in_column=f"target_lag_{HORIZON}",window=7),]# Prepare modelmodel=CatBoostMultiSegmentModel()FitPipelineand make a prediction:frometna.pipelineimportPipeline# Create and fit the pipelinepipeline=Pipeline(model=model,transforms=transforms,horizon=HORIZON)pipeline.fit(train_ts)# Make a forecastforecast_ts=pipeline.forecast()Let's plot the results:frometna.analysisimportplot_forecastplot_forecast(forecast_ts=forecast_ts,test_ts=test_ts,train_ts=train_ts,n_train_samples=50)Print the metric value across the segments:frometna.metricsimportSMAPEmetric=SMAPE()metric_value=metric(y_true=test_ts,y_pred=forecast_ts)metric_value{'segment_a':4.799114474387907,'segment_b':3.271014290441896,'segment_c':6.758606238307858,'segment_d':4.512871862697337}Notebook with this example is availablehere.InstallationETNA is available onPyPI, so you can usepipto install it.Install default version:pipinstall--upgradepip
pipinstalletnaThe default version doesn't contain all the dependencies, because some of them are needed only for specific models, e.g. Prophet, PyTorch.
Available user extensions are the following:prophet: adds prophet model`,torch: adds models based on neural nets,wandb: adds wandb logger,auto: adds AutoML functionality,statsforecast: adds models fromstatsforecastclassiciation: adds time series classification functionality.Install extension:pipinstalletna[extension-name]Install all the extensions:pipinstalletna[all]There are also developer extensions. All the extensions are listed inpyproject.toml.Without the appropriate extension you will get anImportErrortrying to import the model that needs it.
For example,etna.models.ProphetModelneedsprophetextension and can't be used without it.ConfigurationETNA supports configuration files. It means that library will check that all the specified packages are installed prior to script start and NOT during runtime.To set up a configuration for your project you should create a.etnafile at the project's root. To see the available options look atSettings. There is anexampleof configuration file.TutorialsWe have also prepared a set of tutorials for an easy introduction:NotebookInteractive launchGet startedBacktestEDARegressors and exogenous dataDeep learning modelsEnsemblesOutliersAutoMLClusteringFeature selectionForecasting strategiesMechanics of forecastingCustom model and transformInference: using saved pipeline on a new dataHierarchical time seriesForecast interpretationClassificationPrediction intervalsDocumentationETNA documentation is availablehere.CommunityTo ask the questions or discuss the library you can join ourtelegram chat.ResourcesForecasting using ETNA library | 60 lines Catbooston KaggleПрикладные задачи анализа данных, лекция 8 — Временные ряды 2on YouTubeTime Series Forecasting Strategies in ETNAon MediumETNA: Time Series Analysis. What, why and how?on MediumETNA Meetup Jun 2022on YouTubeDUMP May 2022 talkon YouTubeETNA Regressorson MediumTime series forecasting with ETNA: first stepson MediumEDA notebook for Ubiquant Market Predictionon KaggleTabular Playground Series - Mar 2022 (7th place!)on KaggleTabular Playground Series - Jan 2022on KaggleForecasting with ETNA: Fast and Furiouson MediumStore sales prediction with etna libraryon KagglePyCon Russia September 2021 talkon YouTubeAcknowledgmentsETNA.TeamAndrey Alekseev,Nikita Barinov,Dmitriy Bunin,Aleksandr Chikov,Vladislav Denisov,Martin Gabdushev,Sergey Kolesnikov,Artem Makhin,Ivan Mitskovets,Albina Munirova,Julia Shenshina,Yuriy Tarasyuk,Konstantin Vedernikov,Ivan Nedosekov,Rodion PetrovETNA.ContributorsWinstonDovlatov,mvakhmenin,Carlosbogo,Pacman1984,looopka,Artem Levashov,Aleksey PodkidyshevLicenseFeel free to use our library in your commercial and private applications.ETNA is covered byApache 2.0.
Read more about this licenseherePlease note thatetna[prophet]is covered byGPL 2.0due to pystan package.