時間序列相關的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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM