Time Series Forecasting Using Facebook FbProphet
Key Takeaways
Demonstrates time series forecasting using Facebook's FbProphet library
Full Transcript
hello all my name is Krishna and welcome to my YouTube channel so guys today in this video we are actually going to see how we can actually do forecasting with the help of FB profit library now guys if you don't know about FB profit it is an open source library that has been provided by Facebook so you can also search in this it is a wonderful library for doing the forecasting and all so this is basically the facebook. github.io here you can actually find out some of the explanation regarding it uh but an amazing Library altogether and it is completely open source you and use it for the forecasting purpose so to begin with what I'm going to do is guys first of all you need to install the FB profit Library try to install by writing pip install pan and then you have to write cond install minus ca- Forge profit so uh this particular information will be given in this particular uh jupyter notebook file uh and this will be available in the GitHub link itself so initially I will try to load this and after loading it you see that I'm having some Airline passenger. CSV file so I'm just going to execute this and going to see the DF do head now here I have some data set which has thousands of passengers over here and this is basically my month column now if I go and see my DF do tail what I'm going to see over here is that guys uh okay uh let me just see DF do head and this is basically a DF do tail and here you can see that there's 144 record which is not having a proper value so what we'll do is that we'll try to remove this because since this is a bad data so I can also do DF dopl plot and basically you can see that how a seasonal information is basically coming over here right it is increasing the variance is increasing as we go ahead so first of all I'm just going to drop this particular column uh not column sorry row because this is a bad data remember this point and one more thing that I have to do is that guys right now the column names is basically months and thousands of passengers right we need to rename this column the reason we need to rename this colum is that because this uh FB profit requires some different value with respect to this so what we do is that we will be taking this column as DS and this particular column as y okay so they the FB profit requires our date time uh column to be named as DS and my output feature that is the airline passenger whatever feature it is into y so if I just go set this and if I write DF do head you'll be able to see this particular value then I'm dropping this 144th row index because I don't require it because that is a bad data altogether and here you can see all my values over here now the next guys if you go and see this particular date it is of an object type that is of a string type I will try to convert that into date time so once we do this uh DF of it should not be date it should be DS because I changed the column name so now if I go and CDF do head okay so I could had used DS only and probably I have also converted DS so one one more step what I can do is that basically drop it drop date column because I don't require it so for that I will write date but I think it will not be required if you uh instead of in place I'll just say axis equal to one first of all I have to provide the axis and then provide the in place is equal to true I think now it will be dropped and now I'm just going to do DF do head anyhow this will not be required when you are executing from The Notebook so I'm going to remove that then uh this is again my DF do tail you can see this is pretty much important by it's the column name I have to specify the date time column as DS and this is why now I'm going to import FB profit uh and from that I'm going to import this profit class and then here you can see a lot of inbuilt function inside this profit class which we are going to use uh in order to do the forecasting right so the first step guys we will be initializing the model so here it is uh profit is equal to model I've initialized it again uh if I go and see my DF do columns it is DS and Y um again again I have actually assigned it but it's not required over here so I let me just remove it quickly so that uh I will not be requiring okay so this is basically my DF do head uh then what I do is that whatever I have initialized this particular profit which is my model uh I'm going to just do fit on DF so here you can see that it is running Prospect with fonality uh so it it is saying that it has disabled weekly seasonality because it is not weekly seasonal right it is yearly seasonal so here you can see that it is monthly seasonal right it is going up and down up and down up and down and with respect to this not monthly sorry yearly so this is yearly season automatically it has determined and it is basically saying that it is disabling the weekly seasonality and daily seasonality so that in short it is taking the yearly seasonality now if you really want to check out whether it has done correctly or not you can just write something like model do uh component modes if I execute this here you can see that the additive term that is used is here and uh probably one more feature is there which is called as uh let me just see this something will be there definitely uh components make holidays features seasonality change points I think oh plot component so if I go and see this okay plot components is not there I guess uh this is not that specific feature but I think there was some like uh daily seasonality no no no make seasonality features uh no so probably I'll just try to show you it uh show to you that uh what kind of is there but I think it was with C I guess so component modes yeah so this component modes has additive term as yearly and all so uh what I will do now is that once I've have fitted my model model you know I'll try to create future dates and future dates for the next 365 days now remember one thing guys if I go and show you my DF do tail right DF do tail is basically the last date is still 1960 right and this make future data frames what it will do it will next create the next 365 days and it'll append to this particular DS uh feature you know so you can see that over here uh once I execute this future dates and the function that we are going to use is make uncore futurecore data frame so once I execute this if I go and see my futurecore dates futurecore dates uh tail let me just show you tail now you'll be able to see that now I have data till 1961 that what it has done whatever data I had till 1960 it has again appended 365 days on top of it now we are able to see 1961 till 1961 till this particular Year all the data is actually present so the next one year I'm going to make the prediction and for that this function we actually use to create the new dates itself pretty much easy otherwise you can also do it manually with the help of python code then what I'm doing is that I'm doing model. predict on this future dates and finally I will be able to see the predictions the predictions that usually comes guys it has features like Trend y hat lower y hat upper Trend lower Trend upper additive terms additive term lower upper yearly yearly lower and uh and finally you you will be able to see that there will be something called as y hat this y hat is basically the output feature now if I just consider y hat lower y hat upper this is basically the lower and the upper value with respect to Y hat okay so within this particular value only your y hat will actually be falling and these are some other properties that probably Facebook may be using in order to compute a y hat now this is done we can also use model. predict uh model do plot to actually uh do the pro project ition of this particular prediction so in this the dotted points that you see is the real data the Blue Line the blue dark blue line that you see is basically the projection and this light blue space that you see it is basically the trend space right so here this point you can see is my future prediction over here right so for the next one year this is basically the prediction and this looks pretty much good okay this looks pretty much good but still we cannot just compare with respect to this we also need to check uh with the help of cross validation how much accuracy we are getting mean absolute error mean squ error that also we need to check so in the next statement and remember Guys these two are same plot I don't know why it is getting displayed by two but when I tested it this particular model. plot is basically displaying this two same plots and you can see the projection is almost same now there is also something called as plot uncore components and if you do this predictions it'll give you the trend and the weekly uh predictions okay so here you can see that uh the the trend so this is not weekly this is yearly sorry because here my seasonality is basically yearly so if I go and execute this so this trend says that as we go ahead in 1962 it is going to increase the airlines passengers are going to take more ammo and they're going to join they're going to go through the flights and all and yearly with respect to each and every month this is basically the graph uh that is actually shown and this again is getting displayed two times I don't know for what reason this plot underscore component is also getting displayed for two times but you can definitely check it out now this is pretty much important guys what is cross validation now very important thing to note over here guys in Time series analysis right in time series analysis uh the cross validation is basically performed in some different way now how it is basically performed so suppose if I take an example in this uh how how the cross validation uh is basically applied just understand guys suppose I have a data set like train um and or suppose if I I have a data set of all my values from 19 1960 to 1962 okay so I have this particular data set so usually with respect to time series analysis cross validation gets applied like this see this from 1960 to 1961 this goes as your train data set suppose I'm taking this goes as your train data set okay then from 1961 to 62 this goes as your test data for which we have to do the prediction okay and whichever new data field that I'm actually creating it will be from 1962 to 1963 uh which will actually be my validation data set for which is the complete new data set for which I'm actually going to do the pred prediction or projection so what we do is that in order to do the cross validation and check out your mean squar error mean absolute error I'll be taking this two values that is your train and test data set and it will be divided based on year right years and dat and that is what this particular FB profit has a uh Library which is called as cross validation and here you will be able to see that we use this cross validation and they are some parameters we need to provide so first of all what for how many days we have we have basically 365 days then there is also a parameter which is called as period in period we usually give the half of this particular Horizon value okay and initial days basically says that how many total number of days we actually want uh there is also a very important feature which is called as you can see this guys uh it computes forecast from historical cutof points beginning from the end minus origin okay horigan is basically this 365 days so as you know that I've have added 365 days from the last date till the 365 day I'm just going to compute the uh I'm going to make the cross validation with respect to that so here you can see that uh I'm just executing this uh you just have to see DV DC DF cv. head and probably this will take some amount of time because uh you'll be able to see that I'm trying to make 19 forecast with cut off between 1951 to 1959 right so that data I have I have the data set between that value till 1959 and I'm actually trying to do a cross validation of train and test so this will probably take some time and probably we can actually wait after this what we do is that we take this performance metrics and remember guys this output that we seen DF CV has y had value y value it also has y upper and y lower value okay so all these particular values we'll be having and this performance metrix what it takes is that and this this is also a separate library that is present in FB profit. diagnostic so what we do is that we uh this performance metrix it takes the Y and the Yad value it Compares and then it finds out the mean squar error root mean square error mean absolute error and mdap all these particular values it actually tries to find out and by that you will be able to see uh like what will be the graph you know this kind of graph this is basically the mean absolute error graph or sorry RMS root mean square error graph you can also take mean square error and actually try to plot this particular graph like this so this is probably taking some amount of time till then we can actually wait but remember guys this cross validation and this performance metrics all are different different libraries you know that are present inside FB profit isn't it amazing because Facebook is providing all this particular information and one more question that I usually get from people is that Krish whether we should use arima RNN FB profit which one is best guys what I have seen is that FB profile provides provides you a very good results because it does that forecasting it has a lot of parameters where you can actually check so here as I said that guys GF cv. head you're having y hat y hat lower upper and Y so I when when your performance Matrix is getting computed they will take this y column and this y hat column so guys you can see that at 1951 this was your predicted value this was your real value right and 1951 like this so if I go and see my DF do head see this I'll show you DF do head right inside this DF do head it has started from 1949 so that basically means that from 1949 to 1950 that data set went to the training data set right and for the test data set which has actually started from 1951 we are doing the prediction so this is the Y this is the Y hat and now what we are going to do is that we are going to give this DF CV over here inside the performance Matrix and this performance Matrix in in by default takes y hat and Y from that and it'll then compute your parameters like msse rmsc mean uh mean uh absolute error and uh and mdap okay so this is what it is there and you can see that as soon as I execute this here you can see 40 days right Horizon 40 days and here you are getting all this particular values and if I try to see DF P whole value it'll be showing with respect to 365 days guys all 365 records will be actually there DF P now here if you if I try to show you see till 365 days it will be available right so here you can see 40 42 46 47 this this this this and with respect to 365 you are getting this and this and finally and one more thing that you have to note over here guys this coverage is basically probably U the this coverage uh I think no not over here yeah so so this coverage is basically the difference between the Y hat lower and Y hat upper with respect to that this particular coverage is getting calculated and again there is a different formula for that that is what was said in the documentation page uh in the FB profit now uh let me just execute this DF p. head but at amazing this is how we can actually check it out when we see the mean squ error R msse ma map and all we are actually getting smaller smaller values but if you say mean squ is a little bit bigger value but with respect to this we can also plot this particular value so let me just plot with respect to root mean square error and this is how our Trend looks like with respect to the error and the main thing is that all the points that are scattered are away guys it is in the middle of that particular point so that basically means that this particular uh objective that we had to do was done in a pretty much better way but uh an amazing library because just imagine if I want to create uh the next the data for the 365 days which I was doing for ARA in my one of my previous video I had to do a lot of I have to write a lot of code but because of this Library most of the functions are inbuilt and you'll be able to do a whole lot of things so yes guys uh just check out this particular uh uh material that I'll be giving in my GitHub and yes this was all about this particular video I hope you like it please do subscribe to the channel if you're not already subscribed I'll see you in the next video have a great day ahead thank you one and all bye-bye
Original Description
github: https://github.com/krishnaik06/FbProphet
In this video we will have a look how we can perform Time Series Forecasting Using Facebook FbProphet
⭐ Kite is a free AI-powered coding assistant that will help you code faster and smarter. The Kite plugin integrates with all the top editors and IDEs to give you smart completions and documentation while you’re typing. I've been using Kite for a few months and I love it! https://www.kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campaign=krishnaik&utm_content=description-only
All Playlist In My channel
Interview Playlist: https://www.youtube.com/playlist?list=PLZoTAELRMXVM0zN0cgJrfT6TK2ypCpQdY
Complete DL Playlist: https://www.youtube.com/watch?v=9jA0KjS7V_c&list=PLZoTAELRMXVPGU70ZGsckrMdr0FteeRUi
Julia Playlist: https://www.youtube.com/watch?v=Bxp1YFA6M4s&list=PLZoTAELRMXVPJwtjTo2Y6LkuuYK0FT4Q-
Complete ML Playlist :https://www.youtube.com/playlist?list=PLZoTAELRMXVPBTrWtJkn3wWQxZkmTXGwe
Complete NLP Playlist:https://www.youtube.com/playlist?list=PLZoTAELRMXVMdJ5sqbCK2LiM0HhQVWNzm
Docker End To End Implementation: https://www.youtube.com/playlist?list=PLZoTAELRMXVNKtpy0U_Mx9N26w8n0hIbs
Live stream Playlist: https://www.youtube.com/playlist?list=PLZoTAELRMXVNxYFq_9MuiUdn2YnlFqmMK
Machine Learning Pipelines: https://www.youtube.com/playlist?list=PLZoTAELRMXVNKtpy0U_Mx9N26w8n0hIbs
Pytorch Playlist: https://www.youtube.com/playlist?list=PLZoTAELRMXVNxYFq_9MuiUdn2YnlFqmMK
Feature Engineering :https://www.youtube.com/playlist?list=PLZoTAELRMXVPwYGE2PXD3x0bfKnR0cJjN
Live Projects :https://www.youtube.com/playlist?list=PLZoTAELRMXVOFnfSwkB_uyr4FT-327noK
Kaggle competition :https://www.youtube.com/playlist?list=PLZoTAELRMXVPiKOxbwaniXjHJ02bdkLWy
Mongodb with Python :https://www.youtube.com/playlist?list=PLZoTAELRMXVN_8zzsevm1bm6G-plsiO1I
MySQL With Python :https://www.youtube.com/playlist?list=PLZoTAELRMXVMd3RF7p-u7ezEysGaG9JmO
Deployment Architectures:https://www.youtube.com/playlist?list=PLZoT
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: ML Pipelines
View skill →
🎓
Tutor Explanation
DeepCamp AI