Skip to content

This is a tool to ease the creation, data shaping, training and usage of Long Short Term Memory Neural Networks using Keras and Tensorflow

Notifications You must be signed in to change notification settings

luizmlo/EasyLSTM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EasyLSTM

EasyLSTM is a tool that eases the creation of LSTM's and shaping/slicing data to the correct shape.

With EasyLSTM you can go from import to prediction in less than 10 lines of python code!

Requirements

  • TensorFlow >= 2.0
  • Scikit-learn
  • Keras
  • Pandas
  • Numpy

Usage

from easy_lstm import EasyLSTM

helper = EasyLSTM(data, timesteps)
model, X_train, y_train, X_test, y_test = helper.do_magic()

The do_magic() method returns both a compiled model and the train/test split and reshaped data.

The data goes through a series of processes that transform a pandas DataFrame into numpy arrays, with the X being an array of time windows of size n_steps from the dataframe feature columns, and the y being the corresponding labels in the dataset's ['y'] column.

Data format

The data provided to the EasyLSTM's __init__ method has to be a pandas dataframe in the following format:

The number of features/feature columns can be any number, as long as there is a at least one feature and a 'y' column

Sample DataFrame

Note: All feature columns can be named freely, just the label column that needs to be named 'y'

feature_0 feature_1 some_other_feature y
0.1 2.12 1600 0.2
0.2 3.15 3000 0.3
0.3 3.98 400 0.4

7 Lines from import to prediction example

from easy_lstm import EasyLSTM
import pandas
dataset = pandas.read_csv('./path_to_dataset.csv')
dataset['y'] = dataset['feature'].shift(-1, axis=0)[:-1] #Turning a time series into a supervised learning problem
model, X_train, y_train, X_test, y_test = EasyLSTM(data=dataset, n_steps=4).do_magic()
model.fit(X_train, y_train, epochs=20)
predictions = model.predict(X_test)