Lets Implement LSTM RNN Models For Univariate Time Series Forecasting- Deep Learning
Key Takeaways
Implements LSTM RNN models for univariate time series forecasting using deep learning
Full Transcript
[Music] hello my name is Krishna I come welcome to my youtube channel so guys today in this particular video we'll see how can actually develop lsdm models for univariate time series forecasting now many of you have asked this particular question that fish please create videos regarding time series forecasting so considering that requestion I have already explained you about LST M we are going to also create some olicity M models for univariate time series forecasting now before going ahead with respect to this video guys I really want to give a quick shout out to Jason brownie and is amazing blogs in machine learning mastery trust me guys I have learnt a lot from the blogs that are provided by Jason brown and I'd also suggest you many of you basically ask me which our blogs should be referred right this is one of the most important blog that you should prefer because you will be getting a lot of information lot of very nice information from this particular blog regarding machine learning or deep planning so the link will be given in the description and again thank you Jason brownie for this amazing contribution to the data science community so let's go ahead and try to see that how we can actually do this before going ahead guys let me just quickly go and show you what is the problem statement that we are going to start so the problem statement over here is that we are going to do a univariate time series forecasting okay now suppose I have a company and I'm just checking as an example and suppose there is a company and on the first day it has made this much sales okay in the second day it has made this much sales and the third day this much four-day this much fifth day this much sixth day this month seven day this much eight day this much nine day this much and you may be thinking okay Chris why it is not reducing why it is always going into the in the positive direction may also have negative directions right it may also have something less number of values right so you may be think crash while you're just taking this values because this just seems to be increasing as we go and so but just by common sense we can actually see that yes in the future also it will increase it's okay guys you just take your own example try to reduce this particular value and also see it's it's just randomly I've just selected it it is up to you wish that how you want to select this particular value now my problem statement is that considering the previous three days said okay or considering the previous four day sales or 3li let me just take three day sales I need to predict the next day okay so if I consider over here day so I'll just write it down this is my first day this is my first day okay oh just a second okay this is my first year is my second day this is my third day this is my fourth day this is my fifth day this is my sixth day seventh day eighth day and ninety so what I have to do is that I have to do the prediction for my tenth day right considering the previous three values okay considering the previous three one is equitable similarly once I get my 10 day output I similarly have to do for my eleventh day and here now I have to suppose my 10 day output I have got somewhere around like 220 so suppose I just taken an example now for the lemon day what I have to do is that I forget take the previous three values and try to compute it so similarly we will be doing continuously like this for the next ten days you know so something like this up till the next ten days that is up to the 28th day so this is what is my problem statement now first step that I really want to discuss about over here is basically the data pre-processing okay how we have to keep our independent and dependent feature as I told you guys if I just consider this is my x-axis okay now if I'm saying that my previous time step I'm just going to consider three times time so this will be mine t1 type stand this will be my t2 times time this will be my three times and now I also have to create my in dependent so X is my independent features and here you have why is my dependent feature so I also have to create my Y value over here which is my output now how I will be actually creating it now understand this suppose this is my data set initially I have first 10 days values or nine days value okay how we have to divide this suppose I let me consider one 110 125 133 you know as my first independent features so I have 1 1 0 125 133 ok so this is me where first record okay now if I consider my output Y this should be my fourth day output okay so this is basically my first record remember guys this is my first record if I just select this and press the tab oops ok so shift let me just select this whole and press shift so this is my first record okay this is my first record where my first record independent features are 1 1 10 125 123 that basically means on my fourth day this is my output so this is how I'm going to prepare my output now I mean the first record of the data set now in my second record I will now start with 125 because understand I need to now predict 158 right and for this I have to use this past three days data right so I have 125 133 146 and then finally my output will actually be 158 right similarly what I will do I will just go next step now it will become something like 133 146 158 and finally my output will actually be 170 so like this we will continue making all the data okay so similarly if I just go like this and I go on doing this you know so my last record you understand that my last output is 210 right so considering this my 210 output will be looking like this so suppose this is my 210 okay and if I see this is my value as 196 this is my value as 187 and this is my value as 172 so I have all these particular values guys and this is will be my last record but still I have to compute the 10th day for the 10th day my input for the data will be right for the data will be 187 196 and 210 right now this value I don't have it right so this is how we are going to do the data pre-processing so how many number of days we have and trust me guys for every time series problem we have to make or we have to pre-process our data in such a way that we'll be able to create our x and y value that is our independent and dependent features based on the number of time steps that you have taken so they have taken over at 3 times as I've told that based on previous three dates I have to actually calculate now similarly once I get this value for the 10-day that what I'm going to do I'm going to take this 3 as my independent features then I am going to compute for the levant and I'm going to do it similarly in that particularly after doing data pre-processing guys I am going to apply my HTM model a simple lsdm modeler simple lsdm RNN model because understand these all are sequences data so RNA will pretty definitely helpful right so after calculating after doing that then I will be predicting for the future for the future 10 days and finally we will be plotting this so these are the steps that I'm going to show you in this particular video what all we are doing and we'll go one by one okay so let's go in now first of all ah this is the code the code is actually given in the github every information is over there itself now what we have to do is that let me just expand this and make it little bit zoomed in so that you'll be able to see it properly ah perfect now the first thing that I'm going to do is that I'm going to input some of the libraries and remember they this I am working currently in tensorflow 2.0 if you are not working in tensorflow 2.0 you can this tensorflow but the whole implementation is in chaos you tensorflow greater than 2.0 the chaos is integrated within the tensor flow axis right so let's go ahead and try to see this so first of all I am going to input all the libraries that are required like sequential lsdm dense and flatten I'm also going to import an umpire now let's go ahead with my data so I have my time series data which is same values that I've actually shown you over there okay I'm going to choose the number of time steps number of financials basically me that I told you this is my time steps I told you based on the time stamps I have to pre-process my data right so here again I have taken three and you can select your own value can select four five six any number of values that you want okay then you can see that I am preparing my independent and dependent features from this particular function now in French this function takes our time series data all the time series data and my number of features that is three okay now when this is done we'll go inside this particular function so this is my function over here I have my time series data I have my number of features so you can see number of each is is three so here I am going to initialize X and one which will be in the form of list then I am saying for I in range length of time series data so I am just going to see I am going to iterate through all the elements in the time series data and then I'm going to say that for the first time based on the number of features just try to find out the end point and end value okay now suppose in this particular case when I migrating through this fight so my end value will be something like this right so what I will do I will be you taking all this particular value in x-axis and this particular value I will be taking my Y so that is what I am doing over here so you can see that I am checking whether end value is greater than length of time series data minus one if it is greater that basically it has reached the end of this list I will come out by the break strip otherwise what I will do I told you that from time series data from I is equal to end of X so that basically means from this particular value till here I'll be taking that and I'll be storing it in my sequence X value similarly from time series only for the end underscore IX end of the Spoils basically means that for the first iteration this will be zero plus number of features is nothing but three right so third index sequencing so which is the third inside zero one two three right so this is the index this will get stored in the y-axis for the first time okay so that is once done and similarly this will be happening for all the data inside this time series and finally you'll be able to see that I'm appending that in my x and y value and then I'm returning this array of X and my just try to execute by your own guys you will definitely be able to understand this this is pretty much simple because you are if you understood this logic the code is pretty much simple so I have explained you in this particular manner how we are actually doing the data pre-processing now I will execute this quickly so after executing let me print x and y so this is my x values okay this is my Y values this basically means that for this X this is my output Y for this value this record this is my output for this record this is my output for this record this is my own but similarly I am doing all these things now let us see that what is the X dot zip external shape is nothing but 6 comma 3 obviously it should be 2 6 comma 3 because I have 3 features and 6 records 6 records has been created now this is a pretty important step guys understand from this - when I see X dot shape right this is nothing but the number of records this is basically the number of time steps so time steps is pretty much important over here okay and always remember whenever you are implementing a list here you always have to reshape your data in two or three dimensions how what all three dimensions are required one is the number of Records the second one with the shape of this particular how many number of fine steps are there and one should be something like and then the scope features okay so n underscore features don't get confused by this time stamp and this features guys okay time stems I am considering just like a features over here but this feature is just something different where we are just trying to convert this shape into a three dimensional shape even if you want to convert this we just have to use one over here so that it becomes six cross 3 cross 1 okay the same number of element has been just been converted from a two dimension into a 390 okay so that is what this step is done and this is pretty much important you can see where reshape from sample underscore time stands in to sample and its potential and its features okay so just like this kind of example is given over here for you but just understand this reshape is pretty much important okay we are just trying to convert this to dimension to a three dimension so that we will be able to give this as an input to our LST okay and this is pretty much important now the next step after we do this or if I execute this one this you will be able to see that okay let me just see that shape now you can see that X a fist 6 comma 3 comma 1 pretty much simple now let's go ahead and try to define or build the LH TM model this is pretty much C simple guys I hope everybody knows this initially I'm creating a sequential layer then I'm adding Alice TM layer activation is relu because again I'll tell you when works pretty much well with Elissa TM the return sequence is equal to true here is the most important thing now okay guys this is pretty much important in the input shape we have to give n underscore steps and and underscore feature if I try to see what is the N and s Co steps this is basically the three value based on the number of time steps or I can also say this as number of time steps and this is basically what we have actually done with respect to the three dimension conversion right the last feature the last feature which we require we have to give that as an input shape into our lsdm okay so that in the next layer again I'm adding analyst TM layer of 50 hidden neurons and Here I am applying and applying an activation function as Ray Lu and finally this is my output node or the new neural network node basically where I'm keeping the values 1 so that will just need one output then we are doing model dot compiled optimizer is equal to atom and loss is equal to mean squared error finally let us do it for 100 epochs and try to see just let me increase it took 300 epochs and let me quickly flip the model over here so we will be fitting the model let's see will face any errors or not or it will just get executed quickly yes it has got executed quickly if you really want to see verbose with whatever is equal to one you'll be able to see all the epochs that how it is basically taking place and here you can see all the parts so quickly and since the data set is very very small guys and you know the execution time will be very very less okay so this once my fit is done okay now this is the most important step okay guys so the next step is that I'm going to predict for the next ten days after I have actually fitted my model now this step is pretty much important what I am going to do as I've shown you my data set already for the ten-day computation you know I will be taking the previous three days data okay so previous three days data I will be taking over here and then I will be computing the ten day output after getting the 10 day output I will again append this to my input so that I can compute my lemon day so for that I have written this particular logic this will be happening for ten days okay there are two statements if n else first loop it will go to the else block you know because we already have the three days input right in this particular block as soon as it goes we are basically adding suppose we are once output is God we will be appending in this particular list and then we'll be taking this last three values to calculate the next value so similarly we will be going on I would suggest just go through this logic I have written this particular logic to get the output okay so you will be also able to see that I am printing the values also over here like what is the first day input what is the second day output what is the first day output and all like this right so I am printing this I would suggest guys this is a very interesting logic that I have written just go through this and you'll be able to understand but understand the logic is something like this okay suppose this is my ninth day output right I will append this over here to my input and it will start from 186 like this and then I will compute the next day output then again I will be taking this particular value this will become my input and again I will compute then again I will be taking this three as my input so that is what this if and else logic will actually do okay so let me just execute and show it to you so you here you will be seeing that okay the first input is one ninety six to ten to twenty two right so this is my first day input if you really want to see the first day input then what I'm going to do after this is that remember I have given this as my first day right 187 196 210 if I go and see in the else block I have printed Y hat of zero so this is basically my output first day output now what I have done I have appended this over here inside my list and you can see that I skipped this 187 right so it is starting from 196 210 220 to then for this I will be getting this particular output then what I am doing again I am appending this to this particular list and it is starting from 210 till this particular value again I am getting the output as 247 again in the next day my input will be looking something like this you can see that it is clearly given in front of you what are the output I am getting for a specifically day and for the next day input that is actually added at the last and remember always the size of this will be three times tan okay three is timestamp and again will be getting one output again I am adding this 271 over here inside this particular list and again I am taking it from 247 so like this it will continue this is all my final output for the next ten days okay this particular list and this particular list is actually stored in list underscore output now what I am going to do this is my time series data this is the length I am going to create some date for this okay so first I'll create the date of nine days right so this this data that we had right this this paper the whole data that if I show you this whole data was for nine days right so I am just going to create the date for those data just like day 1 day 2 day 3 so here I just write the written n P dot arrange 1 comma 10 then I have written the prediction data is from 10th to 28th day right so two days pattern I have written I have just plotted they come anew with time series data this was my data set that I had and they are the scope red which is basically my predicted data set from 10 to 20 and I am plotting it with my list output now once I execute this you will be seeing this amazing results right now here you can see that this is my data that I had and this is the data that is being forecasted by the Alessia right isn't it amazing I know you'll be thinking that Christian the data will always not be like this yes the data is not always like this and you cannot just here you can also see that right after some point is coming down it is going up it is coming it out and going down right so similarly this is just done some kind of predictions which is pretty much similar to this kind of life right so this is how we have done this particular visual analysis sorry about the visual analysis of the time focus ting and this is how we can actually easily develop analyst TM model for univariate time forecast times it is forecasting now probably this is pretty much good because now we can take the time series forecasting of you know stock prices of Google stock prices or Microsoft stock prices and we can actually implement LST M RN n and see that how it will be doing the prediction so I hope you like this particularly today in the next video I will be coming up with more different kind of multivariate time forecasts time series forecasting also so many of you had also requested to come up with multivariate time series forecasting that also I will be explaining all this particular code will be given in the github that is provided in your description I hope you like this particular video please to subscribe the channel if you're not already subscribe and see L in the next video thank you
Original Description
In this tutorial, we will explore how to develop a suite of different types of LSTM models for time series forecasting.
The models are demonstrated on small contrived time series problems intended to give the flavor of the type of time series problem being addressed. The chosen configuration of the models is arbitrary and not optimized for each problem; that was not the goal.
Github: https://github.com/krishnaik06/Time-Series-Forecasting
Thank you Jason
Ref Link : https://machinelearningmastery.com/how-to-develop-lstm-models-for-time-series-forecasting/
#TIMESERIESFORECASTING
Please do subscribe my other channel too
https://www.youtube.com/channel/UCjWY5hREA6FFYrthD0rZNIw
Connect with me here:
Twitter: https://twitter.com/Krishnaik06
Facebook: https://www.facebook.com/krishnaik06
instagram: https://www.instagram.com/krishnaik06
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Krish Naik · Krish Naik · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Natural Language Processing|Stemming
Krish Naik
Natural Language Processing|BagofWords
Krish Naik
Gaussian distribution or Normal Distribution in statisctics
Krish Naik
Natural Language Processing|TF-IDF for Machine Learning| Text Prerocessing
Krish Naik
Log Normal Distribution in Statistics
Krish Naik
Covariance in Statistics
Krish Naik
Confusion matrix, Precision, Recall| Data Science Interview questions
Krish Naik
Tutorial 44-Balanced vs Imbalanced Dataset and how to handle Imbalanced Dataset
Krish Naik
Implementing a Spam classifier in python| Natural Language Processing
Krish Naik
Tutorial 11-Exploratory Data Analysis(EDA) of Titanic dataset
Krish Naik
Face Recognition using open CV and VGG 16 Transfer Learning
Krish Naik
Pedestrian Detection using OpenCV from Videos
Krish Naik
Face and Eye Detection from Videos using HAAR Cascade Classifier
Krish Naik
Reading, Writing and Displaying images with Opencv| OpenCV Tutorial
Krish Naik
OpenCV Installation | OpenCV tutorial
Krish Naik
Face and Eye Detection from Images using HAAR Cascade Classifier
Krish Naik
Car Detection using HAAR Cascade and Opencv from Videos.
Krish Naik
Using OpenFace for Face recognition in Keras
Krish Naik
OpenPose Tutorial with Tensorflow
Krish Naik
Multiple Linear Regression using python and sklearn
Krish Naik
Dimensional Reduction| Principal Component Analysis
Krish Naik
Movie Recommender System using Python
Krish Naik
TPR,FPR,FNR,TNR, Confusion Matrix
Krish Naik
Precision, Recall and F1-Score
Krish Naik
Artificial Neural Network for Customer's Exit Prediction from Bank
Krish Naik
GridSearchCV- Select the best hyperparameter for any Classification Model
Krish Naik
RandomizedSearchCV- Select the best hyperparameter for any Classification Model
Krish Naik
K Nearest Neighbor classification with Intuition and practical solution
Krish Naik
K Means Clustering Intuition
Krish Naik
Create custom Alexa Skill- Lambda function- Part2
Krish Naik
Hierarchical Clustering intuition
Krish Naik
Implement Transfer Learning with a generic Code Template
Krish Naik
Gender Classifier and Age Estimator using Resnet Convolution Neural Network
Krish Naik
Unlock Your Application With Your Face using OpenCV
Krish Naik
Draw rectangle from webcam and sketch process it on a live feed
Krish Naik
Complete Life Cycle of a Data Science Project
Krish Naik
How we can apply Machine Learning in Finance
Krish Naik
Deep Learning in Medical Science
Krish Naik
How to switch your career to Data Science.
Krish Naik
Linear Regression Mathematical Intuition
Krish Naik
Handle Categorical features using Python
Krish Naik
Machine Learning Algorithm- Which one to choose for your Problem?
Krish Naik
DBSCAN Clustering Easily Explained with Implementation
Krish Naik
Curse of Dimensionality Easily explained| Machine Learning
Krish Naik
Feature Selection Techniques Easily Explained | Machine Learning
Krish Naik
Tutorial 29-R square and Adjusted R square Clearly Explained| Machine Learning
Krish Naik
Cross Validation using sklearn and python | Machine Learning
Krish Naik
Handling Missing Data Easily Explained| Machine Learning
Krish Naik
Deploy Machine Learning Model using Flask
Krish Naik
Deployment of Deep Learning Model using Flask
Krish Naik
How to Visualize Multiple Linear Regression in python
Krish Naik
K Nearest Neighbour Easily Explained with Implementation
Krish Naik
Predicting Heart Disease using Machine Learning
Krish Naik
Predicting Lungs Disease using Deep Learning
Krish Naik
Stock Sentiment Analysis using News Headlines
Krish Naik
Random Forest(Bootstrap Aggregation) Easily Explained
Krish Naik
Voting Classifier(Hard Voting and Soft Voting Classifier)
Krish Naik
Credit Card Fraud Detection using Machine Learning from Kaggle
Krish Naik
Hyperparameter Optimization for Xgboost
Krish Naik
Tutorial 45-Handling imbalanced Dataset using python- Part 1
Krish Naik
More on: Sequence Models
View skill →Related Reads
📰
📰
📰
📰
Help Choosing Neural Network Architecture for Matrix Classification
Reddit r/deeplearning
How to Choose the Best Deep Learning Model for Medical Imaging
Medium · Deep Learning
Another Way to Read Neural Geometry
Medium · Data Science
Another Way to Read Neural Geometry
Medium · Deep Learning
🎓
Tutor Explanation
DeepCamp AI