Transcription of: Time Series Forecasting Made Easy Using Dart Library - Perform Multivariate Forecasting In No Time




hello all my name is krishnak and welcome to my youtube channel so guys i know after many many days i'm uploading a video i was relatively busy with family work and all so in this particular video we are going to see time series how easy it has now become with the help of this particular library that is darts now guys i know many people face difficulties with arima auto arima sari max different kind of techniques even time series forecasting with the help of deep learning techniques so many many trouble i have seen for many people many people have also raised questions regarding krish how to perform multivariate analysis you know multivariate forecasting can a single model to time series multivariate forecasting so all those things will we will be able to do it with the help of this particular library that is darts again guys uh this is an amazing library over here you can see darts is a python library for easy manipulation and forecasting of time series it contains a variety of models from classics such as arima to deep neural networks the model can all be used in the same way using fit and predict functions and it is similar to the sky kit lock and remember guys it supports both univariate and multivariate time series and mod so you may be happy now you don't have to worry much about it just focus more on the theoretical part and then try to implement with the help of this particular library the neural network can be trained on multiple time series and some of the model even offers probabilistic forecast now here you can see some of the examples i'm just going to show you over here what all it focus it you can actually perform with the help of this particular library that is exponential smoothing theta 4 theta profit and all i'll also be showing you an amazing example that is available from this specific library itself so i'm going to show you this and they are also deep learning models like rnn model block rnn model n beats a model tcn model transform model and all all the research papers are there you can actually have and look what we'll do is that we'll try to use this n bits model and we'll try to do the forecasting for multiple uh you know data sets or multiple features it's just like multivariate forecasting we'll try to do that okay and if you really want to know more things you can go and check out the example and tutorials and all so let's see one example first of all in order to start with you just have to install pip install dots so do this i have already done the installation i'm actually doing it in google collab pro and remember i'll be sharing you this entire notebook so i've installed this entirely people install dots this is the library that which you are actually using so please make sure that you install this okay so after doing the installation the next thing is that we will try to use some kind of inbuilt data set so here you will be seeing that i'm using two data set one is air passenger data set and monthly milk data set so this is what i'm actually going to execute and after this i'll just make a code if you want to upload this or if you want to see this particular data set just you write like this and you will be able to see the specific data set here you can see all the values inside this particular array and this you have something called as month in which will basically be of a date time okay so this is a different kind of format it is a combination of array and there is also something uh like this kind of coordinates over here and where you'll be able to access this particular data and again this is based on the number of data that you actually have you also have something called as uh i guess pd.dataframe you can also convert this into pd.data frame and probably you'll be able to see your data set looks something like this so two features one is component month and passenger so you can definitely check it out if you want series you can check it out and usually usually when you're doing forecasting you usually have a date column and probably a data which is specifically specifying some value okay so i'm going to basically use this particular data set i'll be using in that particular format if you want you can actually change it to data frame but i'll not change it to data frame and i'll load two data set one is air passenger monthly mil data set now what i'll do is that i'll create one model that will be doing the forecasting of both this particular data set for the next 36 months and multi mil data said this is also a famous data set where probably it will be showing from 1965 to 2015 or 16 every month how much milk is basically been generated by the cows sorry produced by the cow itself right so over here you have this so i'm just going to load this two and probably you have to convert this entire data set into series so if you want to convert it manually you can write pd dot series okay and you'll be able to convert it so this will be your series data set where you have this and this particular value and that is what this particular thing is actually coming so series air series milk okay two things and if you want to do the plotting you can do it by using the matplotlib library so once you do the plotting here you will be able to see this black line that you see it is nothing but number of air passengers this blue line is nothing but pounds of milk produced per cow so this two data are completely different what we are going to do we are just going to create one model that will be doing the forecasting of both this particular data now let's go ahead how to do it now first of all it's very simple you have to do standard scaling first of all always remember whenever you have a time series data you have to make sure that you bring it to the same scale for both the data set okay so that is what is basically done from this dart.datapreprocessing.transformers where you're importing scala this scalar is basically used for standard scalar so then you initialize it for air and milk and then you do fit underscore transform now interview question what is the basic difference between fit and fit underscore transform trying to write down that particular answer in the comment section i'll try to have a look so over here i'm giving the data set for series underscore a and here i'm actually giving the data for series underscore once i do this i'm just going to plot this scale data now you'll be able to see both will be coming in the same scale now here you can see right 0 to 1 0 to 1 right now it is basically in the same scale you can see the graph over here now now it is very very much simple to just create a model which will be able to do the prediction for both of them and for this uh before that here i'm just going to write it down this is the split for the train and validation so here i'm just going to write it down for train and validation split okay trade and validation split perfect so train and validation speed for the first 36 data will basically be going to the 30s train data the next 36 will basically be going to the validation data and similarly for milk it is the same thing so here i have executed this i have my train and this now they are different different models which i have already told you rnn model tcn model transform model and bits model drop rn model all you have to go and see that what features it has inside a specific library that is what you have to basically check it out and again you can check out the documentation of darts and probably have a look on to that i'm going to use n-bits model probably in the upcoming videos i'll try to use rn model tcs model any model that i really want okay now this is very much important guys here are some of the features and if i talk about n bits model what is this n bits model it is also a deep learning model probably internally it uses rnn kind of techniques itself and here you have all the information regarding that you can actually check it out along with the research paper so if you go and see nbits model you can actually check out the paper over here and what this n bit models is all about neural basis expansion analysis for interpretation time series forecasting again a state of art algorithm again an amazing research paper that has come on 20 2019 and yes it is being very very much important for time series forecasting so it is an amazing one to start with here you have to give two parameters input chunk length and output chunk length now input chunk length means what see in time series data here if i'm giving input chunk length as 24 that basically means it is going to take the first 24 months data as our training data and the next 2l data which is my output chunk length will be my output data okay so input will be the first 24 then output will be 12 then what will happen in time series forecasting one more step it will go ahead in the next epoch the next 24 data will be our input the next 12 data will basically be our output so something like this we are going to take that particular model the loss will be calculated and the number of epochs that is basically performed is 100 okay so i am just going to execute this perfect now i have already trained this particular model guys so i have taken some time and basically trained this particular model for you also it will take two to three minutes i again don't want to do fit and probably wait for two to three minutes so here you can see after taking this model underscore air underscore mill dot fit i'm doing it on training air and train milk so both the data set i'm actually doing and verbose is equal to true so that you'll be able to see the specific data here you can see the training data contains 194 samples this this all the information are basically displayed and probably in the 100 epoch i've just given 100 epochs so within 100 epochs you'll be able to see some accuracy now you have trained the model now we are going to predict it so i'm going to use the same model model underscored underscore milk and i'm going to say dot predict n is equal to 36 and my series suppose if i want for training data set i'll just give train underscore right once i get the output for this particular training data what i'll do i will go and use this map map is basically for checking how good your model has basically performed so whatever output you are getting tread you are basically going to compare it with the series air scale right that's scale data you are going to compare and probably you have to see what is what value what accuracy what metrics you are actually using based on that what percentage you are getting and then i'm also forecasting this particular thing for the upcoming 6 36 months see n is equal to 36 is there for the upcoming 36 months so once you execute this particular data for train air here you'll be able to see the amazing forecasting in this blue color this is for the validations data set and yes the accuracy just by visually when you see it looks pretty much good similarly if you want to do it for the milk data set again you just have to use the same model dot predict n is equal to 36 and just change your input data set so your input data set here i'm going to just write train underscore milk and everything will almost be same and here i'm going to use the same metrics that is map once i execute it probably here you have got 13.84 and again you can see the forecasting it looks pretty much good in short you are able to do multivariate analysis or time series forecasting sorry not analysis time series forecasting with the use of same model for both your a data set and for your milk data set which looks pretty much amazing so this was an amazing library altogether and probably i'm exploring more about this particular library i'll try to see the power of all these things how we can actually use it here you can see lstm and gre used and all because many people find difficulties with respect to setting the param parameters configuring different different things and this kind of libraries have definitely made the process pretty much easy so i hope you like this particular video please do make sure that you subscribe to channel and yes i'll be coming up with more amazing videos on this particular topic till then stay tuned and yes please do subscribe the channel bye bye have a great day