Skip to main content

Some out-of-the-box lstm-based time series models

Project description

sklean tf plotly pandas

Updates

  • 2023-03-16
    • Support multivariate time forcast
  • 2023-03-08
    • AddCNN_BiLSTM_Attentionmodel

中文文档

Introduce

lymboy-lstm contains several commonly used LSTM models for time series forecasting. Currently only univariate time series forecasting is supported. Currently built-in models are: LSTM BiLSTM CNN_LSTM CNN_BiLSTM CNN_BiLSTM_Attention Other models are under study... (CNN_BiLSTM_Attention, Encoder-Decoder Model, Multivariate Time Prediction Support) Please look forward to it~

Packaging method

python ./setup.py sdist bdist_wheel
pip install dist/lymboy-lstm-[latest-version].tar.gz
# Upload to pypi
# pip install twine
# twine upload dist/*

How to install?

pip install lymboy-lstm

How to use?

Taking LSTM model to predict power consumption as an example

  • Import lib
import pandas as pd
import numpy as np
from lstm import LSTM
from lstm.util import plot
  • Read dataset
file = './dataset/power/power_consumption_A.csv'
df = pd.read_csv(file, index_col=0)
sequence = df.load
  • Modeling
# Use the data of the past 96 times to predict the data of the next 10 times in the future
model = LSTM(n_steps=96, n_output=10)
# Process sequence data as model input, specifying a test set ratio of 20%
model.createXY(sequence, test_size=0.2)
model.fit(epochs=500, verbose=True)
print(model.score()) 

lstm-predict-96to10

plot(model.y_hat[:,0], model.y_test[:,0])

lstm-predict-96to10-plot

CNN_BiLSTM predicts transformer oil temperature

  • Import lib
import pandas as pd
import numpy as np
from lstm import LSTM, BiLSTM, CNN_BiLSTM
from lstm.util import plot
  • Read dataset
file = './dataset/ETT/ETTh1.csv'
df = pd.read_csv(file, index_col=0)
sequence = df.OT
  • Modeling
model = CNN_BiLSTM(n_steps=96, n_output=24, n_seq=6)
model.createXY(sequence)
model.fit(epochs=500, verbose=True)
print(model.score())

cnnbilstm-predict-96to24-plot

Prediction results of LSTM model on multiple data sets (multivariate, multi-step prediction)

Parameter Description

  • n_steps: training step size, representing the step size of historical data, int
  • n_output: predicted output length, int
  • n_seq: subsequence, int (note that n_seq should be divisible by n_steps, the minimum is 1)
  • learning_rate: learning rate for Adm, float

Other parameters are consistent with tensorflow

Error feedback

alayama@163.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lymboy-lstm-1.7.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lymboy_lstm-1.7.1-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file lymboy-lstm-1.7.1.tar.gz.

File metadata

  • Download URL: lymboy-lstm-1.7.1.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.7

File hashes

Hashes for lymboy-lstm-1.7.1.tar.gz
Algorithm Hash digest
SHA256 c2dfbcff2335841d7d325eadafc95f572d4e4f07d35a13fbd98a9657f7a63545
MD5 08dedeac163c615dd1675c6ca7943ad2
BLAKE2b-256 892ff0bb5e73055e067e3008bcc1bec28ab217d0c1b3c435cc1f2a67acbdb1e1

See more details on using hashes here.

File details

Details for the file lymboy_lstm-1.7.1-py3-none-any.whl.

File metadata

  • Download URL: lymboy_lstm-1.7.1-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.7

File hashes

Hashes for lymboy_lstm-1.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 213ca06e5156c5c7971e5745f133ae87394a62cbbf28f0fa496196272983c632
MD5 e5b6a925a416e64d589abc9977168e2e
BLAKE2b-256 cf996e84d9d7eae5e000e8a6db5e5159505663c05edefa7c86600586a58ca250

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page