Coding LSTM which have Keras and TensorFlow (12.2 or more)

Long Short Term Memory (LSTM) and Gated Recurrent Units (GRU) are two layer types commonly used to build recurrent neural networks in Keras. This video introduces these two network types as a foundation towards Natural Language Processing (NLP) and time series prediction.

Code for This Video:
Course Homepage:

Follow Me/Subscribe:

Support Me on Patreon:
Video Rating: / 5

In this lesson, you will learn a multi-step time series prediction using RNN LSTM for household power consumption prediction. We will predict the power consumption of the coming week based on the power consumption of past weeks.

Download the working file:

Learn Complete Data Science with these 5 video series.
1. Python for Beginners

2. Machine Learning for Beginners

3. Feature Selection in Machine Learning

4. Deep Learning with TensorFlow 2.0 and Keras

5. Natural Language Processing (NLP) Tutorials

The working code is given in the video description of each video. You can download the Jupyter notebook from GitHub.

Please Like and Subscribe to show your support.

### Like Facebook Page:

### Make Your Own Automated Email Marketing Software in Python

15 Antworten auf „Coding LSTM which have Keras and TensorFlow (12.2 or more)“

  1. thank You infinity Time for your videos,
    I want to ask you what happens if you have a data frame where each row of observations on how to convert a data frame of observation to sequence?
    Thank s for advance.

  2. Dear Mr. Heaton, first off, thank you for providing the useful resource. I do have a question for you and that is about evaluating the time series model. In my opinion, I do not think that the correct way to evaluate the model is how you are doing. You took the ground truth values from the dataset to generate the test set. Shouldn't the test set be generated by the model and then compare the values with the ground truth because that's how you will correctly measure the model's performance.
    For example: train_set = [x1, x2, x3, …, xn] was used to train the model (m) and the last 10 sequence [xn-10, xn-9, …, xn] will be fed to the model to predict [xn+1] and further [xn-9,xn-8,…xn+1] will be used to predict [xn+2] and so on…
    And once you do that you will have a set of [xn+1, xn+2,…xn+z] (where z is the future time steps you wanna predict) that will be used to evaluate the model.
    Let me know if my question makes sense.

  3. Hi! just a question, does lstm predict on sequences of FEATURES in ONE SAMPLE or sequences of SAMPLES (outputs) in ONE BATCH? For eg. I need to predict next number as many to one. I fit first sample as x1=1, x2=2 and output y=3, next sample x1=4, x2=5 y=6. NOW Does the model look on sequence of features (x1,x2) or sequence of samples (y, which are output of the model)

  4. Hii
    How to handle persistent model problem. While doing time series analysis i get the output which seems to be one time step ahead of the actual series. How to rectify this problem?? This thing i am getting with several ML, DL, and as well as with statistical algos. Please do reply??

  5. Dear Mr. Heaton, I've searched many times the Internet and YouTube for practical implementations of python, Keras, and TensorFlow, especially regarding time series and LSTM. You're the best: Clear, simple, practical Jupiter notebook examples, the lot. Thank you. Looking forward to your other 2019 courses, especially regarding reinforcement learning.

  6. how to add initial weight and bias into LSTM from csv file into below code
    model = Sequential()

    model.add(LSTM(250, input_shape=(train_X.shape[1], train_X.shape[2]),activation='relu'))

    opt = Adam()

    model.compile(loss='mae', optimizer=opt)#,metrics=['accuracy'])#mean_squared_error

    # Fit the model

    history =, train_y, epochs=20,validation_data=(test_X, test_y),batch_size=24,verbose=2,shuffle=False)

  7. I'm a computer science university student from Italy. This video helped me a lot in understanding how to use LSTM from a practical point of view.

    I have to use LSTM for battery capacity estimation with time series. I have a question, how could I predict only one value at the end of the sequence? In my case I have a series of measurements of Voltage, Temperature and Current and after let's say 5000 measurements I have a calculated capacity value Q. How can I be able to take in count all the measurements to see how they affect the Q and at the same time how can I be able to not give a label to all time steps but the last (which will have the calculated capacity)?
    You are clear and effective, thank you very much for sharing your expertise with us.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.