Skip to main content

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

Project description

sklean tf plotly pandas

Updates

  • 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 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

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)

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.tar.gz (8.2 kB view hashes)

Uploaded Source

Built Distribution

lymboy_lstm-1.7-py3-none-any.whl (8.8 kB view hashes)

Uploaded Python 3

Supported by

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