时间序列相关的python 包

https://zhuanlan.zhihu.com/p/425224434

时间序列

  • 参考网址 (资源整合网址)

zhuanlan.zhihu.com/p/39

zhuanlan.zhihu.com/p/38

analyticsindiamag.com/t

machinelearningmastery.com

github.com/MaxBenChrist

包列表

package name 标签 bref introduction
Arrow 时间格式修改 方便修改时间表示形式
Featuretools 自动特征工程 固定特征模板,不一定有业务意义
TSFRESH 自动特征工程 自动抽取时间序列特征
PyFlux 模型,传统模型 传统的时间序列模型
TimeSynth 模拟数据 用于模拟时间序列的生成
Sktime 模型,机器学习 类sklearn调佣方式的时间序列处理器,模型偏机器学习
Darts 模型,传统模型 传统模型到深度学习模型都有,
Orbit 模型,贝叶斯 贝叶斯模型 ,Uber出品
AutoTS 模型,深度学习,AutoML 自动化 测试多种模型 并给出预测结果,包括深度学习
Prophet 模型,季节性特征 facebook的开源时间序列处理,适合有季节性 的数据
AtsPy 模型,深度学习,传统模型 自动化实现多个模型,传统及深度学习
kats 模型 传统模型及facebook自己的模型,深度学习暂时少
gluon-ts 模型,深度学习 亚马逊 的包,基于MXNET ,深度学习模型多
AutoGluon 模型,AutoML,深度学习 亚马逊的包,基于MXNET,AutoML,文本、图像、表格数据都可以。
GENDIS 模型,shaplet shaplet构建距离特征,进行分类
Flow Forecast 模型,深度学习 深度学习为主,pytorch框架,都是常见STOA模型
pandas-ta quant,特征工程 技术指标 计算,基于ta-lib搭建
PyTorch_Forecasting 模型,深度学习 将时间序列的STOA模型基于pytorch实现
statsmodels 模型,传统模型 基于scipy,传统的时间序列模型,模型很全
stumpy 特征工程 用于构造时间序列的特征,能够为某一个特定的时间序列构造特征向量。
TA-Lib quant,特征工程 技术指标 计算
ta quant,特征工程 技术指标 计算
tslearn 模型,传统模型 传统的模型,类似sklearn的处理方法。
tsmoothie 数据预处理,模型 用于对时间序列进行平滑,去除异常点。

 

tsmoothie

Description

用于对时间序列进行平滑,去除异常点。

A python library for time-series smoothing and outlier detection in a vectorized way.

数据预处理目的:

installation

pip install --upgrade tsmoothie

document

github.com/cerlymarco/t

tslearn

Description

传统的模型,类似sklearn的处理方法。

功能包括:

|data|processing|clustering|classification|regression|metrics| |---|---|---|---|---|---| |UCR Datasets|Scaling|TimeSeriesKMeans|KNN Classifier|KNN Regressor|Dynamic Time Warping| |Generators|Piecewise|KShape|TimeSeriesSVC|TimeSeriesSVR|Global Alignment Kernel| |Conversion(12)| |KernelKmeans|LearningShapelets|MLP|Barycenters| | | | |Early Classification| |Matrix Profile|

installation

There are different alternatives to install tslearn:

  • PyPi: python -m pip install tslearn<br />
  • Conda: conda install -c conda-forge tslearn<br />
  • Git: python -m pip install https://github.com/tslearn-team/tslearn/archive/main.zip

document

github.com/tslearn-team

ta

Description

用于技术指标的计算。

  • 可以计算的技术指标

Volume

  • Money Flow Index (MFI)
  • Accumulation/Distribution Index (ADI)
  • On-Balance Volume (OBV)
  • Chaikin Money Flow (CMF)
  • Force Index (FI)
  • Ease of Movement (EoM, EMV)
  • Volume-price Trend (VPT)
  • Negative Volume Index (NVI)
  • Volume Weighted Average Price (VWAP)

Volatility

  • Average True Range (ATR)
  • Bollinger Bands (BB)
  • Keltner Channel (KC)
  • Donchian Channel (DC)
  • Ulcer Index (UI)

Trend

  • Simple Moving Average (SMA)
  • Exponential Moving Average (EMA)
  • Weighted Moving Average (WMA)
  • Moving Average Convergence Divergence (MACD)
  • Average Directional Movement Index (ADX)
  • Vortex Indicator (VI)
  • Trix (TRIX)
  • Mass Index (MI)
  • Commodity Channel Index (CCI)
  • Detrended Price Oscillator (DPO)
  • KST Oscillator (KST)
  • Ichimoku Kinkō Hyō (Ichimoku)
  • Parabolic Stop And Reverse (Parabolic SAR)
  • Schaff Trend Cycle (STC)

Momentum

  • Relative Strength Index (RSI)
  • Stochastic RSI (SRSI)
  • True strength index (TSI)
  • Ultimate Oscillator (UO)
  • Stochastic Oscillator (SR)
  • Williams %R (WR)
  • Awesome Oscillator (AO)
  • Kaufman's Adaptive Moving Average (KAMA)
  • Rate of Change (ROC)
  • Percentage Price Oscillator (PPO)
  • Percentage Volume Oscillator (PVO)

Others

  • Daily Return (DR)
  • Daily Log Return (DLR)
  • Cumulative Return (CR)

installation

pip install --upgrade ta

document

github.com/bukosabino/t

technical-analysis-library-in-python.readthedocs.io

TA-Lib

Description

用于计算金融时间序列的各项指标。

from talib import abstract

# directly
SMA = abstract.SMA

# or by name
SMA = abstract.Function('sma')

installation

安装问题参考:

github.com/mrjbq7/ta-li

You can install from PyPI:

$ pip install TA-Lib
Or checkout the sources and run `setup.py` yourself:

$ python [setup.py](http://setup.py) install


It also appears possible to install via [Conda Forge](https://anaconda.org/conda-forge/ta-lib):

$ conda install -c conda-forge ta-lib

document

github.com/mrjbq7/ta-li

stumpy

Description

用于构造时间序列的特征,能够为某一个特定的时间序列构造特征向量。

特征向量含义:stumpy.readthedocs.io/e

installation

python -m pip install stumpy
conda install -c conda-forge stumpy

document

github.com/TDAmeritrade

stumpy.readthedocs.io/e

statsmodels

Description

基于scipy,传统的时间序列模型,模型很全

Contains a submodule for classical time series models and hypothesis tests

installation

statsmodels.org/dev/ins

pip install statsmodels
conda install -c conda-forge statsmodels

document

statsmodels.org/devel/

github.com/statsmodels/

PyTorch_Forecasting

Description

将时间序列的STOA模型基于pytorch实现

PyTorch Forecasting is a PyTorch-based package for forecasting time series with state-of-the-art network architectures. It provides a high-level API for training networks on pandas data frames and leverages PyTorch Lightning for scalable training on (multiple) GPUs, CPUs and for automatic logging.

适用模型:

github.com/jdb78/pytorc

|Name|Covariates|Multiple targets|Regression|Classification|Probabilistic|Uncertainty|Interactions between series|Flexible history length|Cold-start|Required computational resources (1-5, 5=most)| |---|---|---|---|---|---|---|---|---|---|---| |RecurrentNetwork|x|x|x| | | | |x| |2| |DecoderMLP|x|x|x|x| |x| |x|x|1| |NBeats| | |x| | | | | | |1| |DeepAR|x|x|x| |x|x| |x| |3| |TemporalFusionTransformer|x|x|x|x| |x| |x|x|4|

installation

pip install pytorch-forecasting
# 或者
conda install pytorch-forecasting pytorch -c pytorch>=1.7 -c conda-forge

document

github.com/jdb78/pytorc

pytorch-forecasting.readthedocs.io

pandas-ta

Description

基于TA Lib 的封装,金融时间序列的技术指标,比如macd等。

An easy to use Python 3 Pandas Extension with 130+ Technical Analysis Indicators

installation

pip install pandas_ta

或者最新版

pip install -U git+github.com/twopirllc/pa

document

github.com/twopirllc/pa

指标说明:

github.com/twopirllc/pa

Flow Forecast

Description

基本都是深度学习模型,基于pytorch

Flow Forecast is a deep learning for time series forecasting , classification , and anomaly detection framework built in PyTorch
Models currently supported
  1. Vanilla LSTM : A basic LSTM that is suitable for multivariate time series forecasting and transfer learning.
  2. Full transformer : The full original transformer with all 8 encoder and decoder blocks. Requires passing the target in at inference.
  3. Simple Multi-Head Attention : A simple multi-head attention block and linear embedding layers. Suitable for transfer learning.
  4. Transformer with a linear decoder: A transformer with n-encoder blocks (this is tunable) and a linear decoder.
  5. DA-RNN: A well rounded model with which utilizes a LSTM + attention.
  6. Enhancing the Locality and Breaking the Memory Bottleneck of Transformer on Time Series Forecasting:
  7. Transformer XL:
  8. Informer: Beyond Efficient Transformer for Long Sequence Time-Series Forecasting
  9. DeepAR

installation

pip install flood-forecast

document

github.com/AIStream-Pee

flow-forecast.atlassian.net

flow-forecast.atlassian.net

AutoGluon

Description

AutoML的包,用于自动化的学习,包括文本、图像、表格数据;

示例

from autogluon.tabular import TabularDataset, TabularPredictor
train_data = TabularDataset('https://autogluon.s3.amazonaws.com/datasets/Inc/train.csv')
test_data = TabularDataset('https://autogluon.s3.amazonaws.com/datasets/Inc/test.csv')
predictor = TabularPredictor(label='class').fit(train_data, time_limit=120)  # Fit models for 120s
leaderboard = predictor.leaderboard(test_data)

installation

# First install package from terminal:
python3 -m pip install -U pip
python3 -m pip install -U setuptools wheel
python3 -m pip install -U "mxnet<2.0.0"
python3 -m pip install autogluon  # autogluon==0.3.1

document

github.com/awslabs/auto

auto.gluon.ai/stable/tu

GENDIS

Description

能够自动识别出shaplet(时间序列的子序列),并将与各个序列的距离作为特征,根据特征进行序列的分类处理。

installation

github.com/IBCNServices

document

github.com/IBCNServices

gluon-ts

Description

较多深度学习模型 的模块,亚马逊的包,基于MXNET。

模型参考:github.com/awslabs/gluo

installation

pip install --upgrade mxnet~=1.7 gluonts

document

github.com/awslabs/gluo

github.com/awslabs/gluo

kats

Description

facebook轻量级,可以工业使用的框架,支持模型SARIMA,Prophet,Holt-Winters

支持模型:github.com/facebookrese

Kats is a toolkit to analyze time series data, a lightweight , easy-to-use, and generalizable framework to perform time series analysis. Time series analysis is an essential component of Data Science and Engineering work at industry, from understanding the key statistics and characteristics, detecting regressions and anomalies, to forecasting future trends. Kats aims to provide the one-stop shop for time series analysis , including detection, forecasting, feature extraction/embedding , multivariate analysis, etc.
Important links

installation

pip install --upgrade pip
pip install kats

If you need only a small subset of Kats, you can install a minimal version of Kats with

MINIMAL_KATS=1 pip install kats

document

AtsPy

Description

自动化实现多个模型。

Easily develop state of the art time series models to forecast univariate data series. Simply load your data and select which models you want to test. This is the largest repository of automated structural and machine learning time series models . Please get in contact if you want to contribute a model. This is a fledgling project, all advice appreciated.

Automated Models

  1. ARIMA - Automated ARIMA Modelling
  2. Prophet - Modeling Multiple Seasonality With Linear or Non-linear Growth
  3. HWAAS - Exponential Smoothing With Additive Trend and Additive Seasonality
  4. HWAMS - Exponential Smoothing with Additive Trend and Multiplicative Seasonality
  5. NBEATS - Neural basis expansion analysis (now fixed at 20 Epochs)
  6. Gluonts - RNN-based Model (now fixed at 20 Epochs)
  7. TATS - Seasonal and Trend no Box Cox
  8. TBAT - Trend and Box Cox
  9. TBATS1 - Trend, Seasonal (one), and Box Cox
  10. TBATP1 - TBATS1 but Seasonal Inference is Hardcoded by Periodicity
  11. TBATS2 - TBATS1 With Two Seasonal Periods

installation

pip install atspy

document

github.com/firmai/atspy

Prophet

Description

facebook的开源时间序列处理,适用于有季节性 的数据。

It works best with time series that have strong seasonal effects and several seasons of historical data. (github文档说明)
Prophet是Facebook研究团队开发的知名时间序列软件包,于2017年首次发布,适用于具有强烈季节性影响 的数据和多个季节 的历史数据。它具有高度的用户友好性和可定制性,只需进行最少的设置。
# Loading the library
import pandas as pd
import matplotlib.pyplot as plt
from fbprophet import Prophet


# Loading the data from the repo:
df = pd.read_csv("https://raw.githubusercontent.com/facebook/prophet/master/examples/example_wp_log_peyton_manning.csv")

# Fitting the model
model = Prophet() 
model.fit(df) #fit the  model.

# Predict
future = model.make_future_dataframe(periods=730) # predicting for ~ 2 years
forecast = model.predict(future) # Predict future

# Plot results
fig1 = model.plot(forecast) # Plot the fit to past data and future forcast.
fig2 = model.plot_components(forecast) # Plot breakdown of components.
plt.show()
forecast # Displaying various results in table format.

installation

pip install prophet

document

github.com/facebook/pro

machinelearningmastery.com

facebook.github.io/prop

pypi.org/project/prophe

AutoT S

Description

AutoTS 是一个自动化的时间序列预测库,可以使用简单的代码训练多个时间序列模型,此库的一些最佳功能包括:

  • 利用遗传规划 优化方法寻找最优时间序列预测模型。
  • 提供置信区间 预测值的下限和上限。
  • 训练各种各样的模型 ,如统计的,机器学习以及深度学习模型
  • 它还可以执行最佳模型的自动集成
  • 它还可以通过学习最优NaN插补和异常值去除 来处理混乱的数据
  • 它可以运行单变量和多变量 时间序列
# also: _hourly, _daily, _weekly, or _yearly
from autots.datasets import load_monthly

df_long = load_monthly(long=True)

from autots import AutoTS

model = AutoTS(
    forecast_length=3,
    frequency='infer',
    ensemble='simple',
    max_generations=5,
    num_validations=2,
)
model = model.fit(df_long, date_col='datetime', value_col='value', id_col='series_id')

# Print the name of the best model
print(model)

installation

pip install autots

document

winedarksea.github.io/A

github.com/winedarksea/

Orbit

Description

Uber开发的时间序列预测包,使用贝叶斯方法,比较特别

目前支持模型

Currently, it supports concrete implementations for the following models : - Exponential Smoothing (ETS) - Local Global Trend (LGT) - Damped Local Trend (DLT) - Kernel Time-based Regression (KTR)

支持优化方法

It also supports the following sampling/optimization methods for model estimation/inferences:

Markov-Chain Monte Carlo (MCMC) as a full sampling method Maximum a Posteriori (MAP) as a point estimate method Variational Inference (VI) as a hybrid-sampling method on approximate distribution

installation

pip install orbit-ml

document

For details, check out our documentation and tutorials:

Darts

Description

传统模型到深度学习模型都有。支持多元时间序列。

支持的模型类型:

|Model|Univariate|Multivariate|Probabilistic|Multiple-series training|Past-observed covariates support|Future-known covariates support|Reference| |---|---|---|---|---|---|---|---| |ARIMA|x| |x| | | | | |VARIMA|x|x| | | | | | |AutoARIMA|x| | | | | | | |ExponentialSmoothing|x| |x| | | | | |Theta and FourTheta|x| | | | | |Theta & 4 Theta| |Prophet|x| |x| | |x|Prophet repo| |FFT (Fast Fourier Transform)|x| | | | | | | |RegressionModel (incl RandomForestLinearRegressionModel and LightGBMModel)|x|x| |x|x|x| | |RNNModel (incl. LSTM and GRU); equivalent to DeepAR in its probabilistic version|x|x|x|x| |x|DeepAR paper| |BlockRNNModel (incl. LSTM and GRU)|x|x| |x|x| | | |NBEATSModel|x|x| |x|x| |N-BEATS paper| |TCNModel|x|x|x|x|x| |TCN paperDeepTCN paperblog post| |TransformerModel|x|x| |x|x| | | |Naive Baselines|x| | | | | | |

项目features

Forecasting Models: A large collection of forecasting models; from statistical models (such as ARIMA) to deep learning models (such as N-BEATS). See table of models below.

Data processing: Tools to easily apply (and revert) common transformations on time series data (scaling, boxcox, …)

Metrics: A variety of metrics for evaluating time series' goodness of fit; from R2-scores to Mean Absolute Scaled Error.

Backtesting: Utilities for simulating historical forecasts, using moving time windows.

Regression Models: Possibility to predict a time series from lagged versions of itself and of some external covariate series, using arbitrary regression models (e.g. scikit-learn models).

Multiple series training: All neural networks, as well as RegressionModels (incl. LinearRegressionModel and RandomForest) support being trained on multiple series.

Past and Future Covariates support: Some models support past-observed and/or future-known covariate time series as inputs for producing forecasts.

Multivariate Support: Tools to create, manipulate and forecast multivariate time series.

Probabilistic Support: TimeSeries objects can (optionally) represent stochastic time series; this can for instance be used to get confidence intervals.

Filtering Models: Darts offers three filtering models: KalmanFilterGaussianProcessFilter, and MovingAverage, which allow to filter time series, and in some cases obtain probabilistic inferences of the underlying states/values.

installation

pip install darts

document

analyticsindiamag.com/h

github.com/unit8co/dart

Sktime

Description

类sklearn的时间序列处理包

About: Sktime is a unified python framework that provides API for machine learning with time series data. The framework also provides scikit-learn compatible tools to build, tune and validate time series models for multiple learning problems, including time series classification, time series regression and forecasting.
from sktime.datasets import load_airline
from sktime.forecasting.base import ForecastingHorizon
from sktime.forecasting.model_selection import temporal_train_test_split
from sktime.forecasting.theta import ThetaForecaster
from sktime.performance_metrics.forecasting import mean_absolute_percentage_error

y = load_airline()
y_train, y_test = temporal_train_test_split(y)
fh = ForecastingHorizon(y_test.index, is_relative=False)
forecaster = ThetaForecaster(sp=12)  # monthly seasonal periodicity
forecaster.fit(y_train)
y_pred = forecaster.predict(fh)
mean_absolute_percentage_error(y_test, y_pred)
>>> 0.08661467738190656

installation

pip

pip install sktime

安装额外依赖

pip install sktime[all_extras]

conda安装

conda install -c conda-forge sktime

安装依赖

conda install -c conda-forge sktime-all-extras

document

sktime.org/en/latest/ap

github.com/alan-turing-

TimeSynth

Description

可以用于生成时间序列的模拟数据

Signal Types

  • Harmonic functions(sin, cos or custom functions )
  • Gaussian processes with different kernels
  • Constant
  • Squared exponential
  • Exponential
  • Rational quadratic
  • Linear
  • Matern
  • Periodic
  • Pseudoperiodic signals
  • Autoregressive(p) process
  • Continuous autoregressive process (CAR)
  • Nonlinear Autoregressive Moving Average model (NARMA)

installation

git clone https://github.com/TimeSynth/TimeSynth.git
cd TimeSynth
python setup.py install

document

github.com/TimeSynth/Ti

PyFlux

Description

提供传统的时间序列方法

About: PyFlux is an open source library for time series analysis and prediction. In this library, users can choose from a flexible range of modelling and inference options , and use the output for forecasting and retrospection. The library allows for a probabilistic approach to time series modelling. The latest release version of PyFlux is available on PyPi. Python 2.7 and Python 3.5 are supported, but development occurs primarily on 3.5.

installation

pip install pyflux

document

github.com/RJT1990/pyfl

TSFRESH

Description

About: TSFRESH or Time Series Feature extraction based on scalable hypothesis tests is a Python package with various feature extraction methods and a robust feature selection algorithm. The package automatically calculates a large number of time series characteristics and contains methods to evaluate the explaining power and importance of such characteristics for regression or classification tasks. Advantages include: It is compatible with sklearn, pandas and numpy It allows anyone to easily add their favorite features * It both runs on the local machine or even on a cluster

installation

pip install tsfresh
docker pull nbraun/tsfresh

document

github.com/blue-yonder/

Featuretools

Description

时间序列相关的自动化特征工程。

About: Featuretools is an open source Python library for automated feature engineering. The framework excels at transforming temporal and relational datasets into feature matrices for machine learning. Featuretools references generated features through the feature name. In order to make features easier to understand, Featuretools offers two additional tools, featuretools.graph_feature() and featuretools.describe_feature(), to help explain what a feature is and the steps Featuretools took to generate it.

installation

pip install featuretools

featuretools.alteryx.com

document

featuretools.alteryx.com

github.com/alteryx/feat

Arrow

Description

Arrow is a Python library that offers a sensible and human-friendly approach to creating, manipulating, formatting and converting dates, times and timestamps

用于时间的格式转换,可以转换为便于人阅读的格式。

installation

pip install -U arrow

document

github.com/arrow-py/arr

>>> utc = utc.shift(hours=-1)
>>> utc
<Arrow [2013-05-11T20:23:58.970460+00:00]>

>>> local = utc.to('US/Pacific')
>>> local
<Arrow [2013-05-11T13:23:58.970460-07:00]>

>>> local.timestamp()
1368303838.970460

>>> local.format()
'2013-05-11 13:23:58 -07:00'

>>> local.format('YYYY-MM-DD HH:mm:ss ZZ')
'2013-05-11 13:23:58 -07:00'

>>> local.humanize()
'an hour ago'

>>> local.humanize(locale='ko-kr')
'한시간 전'

ithub: github.com/winedarksea/

pip install --upgrade pip pip install kats

原文地址:https://www.cnblogs.com/dhcn/p/15476133.html