Recurrent Neural Network (RNN) in R | A Rstudio Tutorial on Keras and Tensorflow

  Рет қаралды 27,242

LiquidBrain Bioinformatics

LiquidBrain Bioinformatics

4 жыл бұрын

Using a public data provided from a weather station, let us go through the journey of using Rstudio/keras/tensorflow to create a model that could predict the upcoming temperature using past data.
Download the Code here:
github.com/brandonyph
Subtopic list:
1. Understand the dataset
2. What, when and why RNN?
3. Example 1(non RNN):Flatten Layers to NN
4. Example 2:Single Layer LSTM to NN, using custom data unrolling
5. Example 3:Single Layer Gru/LSTM to NN, using generator function
6. Data Reduction + Data Remodeling
7. Neural Network Model Optimization
Source Material
blogs.rstudio.com/tensorflow/...
Email: liquidbrain.r@gmail.com
Website: www.liquidbrain.org/videos
Patreon: / liquidbrain

Пікірлер: 80
@znagy1041
@znagy1041 4 жыл бұрын
Good job, Sir! You have established the Liquid Brain Academy. Everybody can read the tutorial examples and repeat, but you can exlain all details to an audience. Great lecture. It could be a good next step to explain the sunspots dataset LSTM example.
@karthick2254
@karthick2254 3 жыл бұрын
Good insightful video found after long days of search on RNN time series, thanks!
@FredericMoreau86
@FredericMoreau86 2 жыл бұрын
Slightly off topic, I just want to mention my favorite, and underestimated, R function, which is embed(). x
@chandrasekarramanvelayudam4393
@chandrasekarramanvelayudam4393 3 жыл бұрын
An excellent explanation.Great job.
@tatomans1982
@tatomans1982 3 жыл бұрын
I love the video. Please more videos like this about this topic
@joaoperin8313
@joaoperin8313 2 жыл бұрын
Nice class! Thank you very much
@MrMiharan
@MrMiharan 9 ай бұрын
Thank you! Great video.
@jasonyao3762
@jasonyao3762 3 жыл бұрын
Great Job!
@francycharuto
@francycharuto 4 жыл бұрын
That was the best explanation on RNN inputs I've ever seen. Any plan for a LSTM showcase?
@LiquidBrain
@LiquidBrain 3 жыл бұрын
working on it for sometime now, havent got the time to compile those into a video
@diegovirano
@diegovirano 4 жыл бұрын
thanks for the video... very useful. I would like to have a little cheat sheet about the different definitions such as epoch, lookback, etc... I am 100% new and self-learning.
@taohuang3092
@taohuang3092 Жыл бұрын
Thanks for your great video. I'd like to ask why does the 'delay' differ between training (delay = 44) and testing (delay = 0)?
@lyubovdoroshenko7564
@lyubovdoroshenko7564 Жыл бұрын
Thank you for a great video ! I was wondering, when you are explaining the lookback, you say we are looking at 240 observations back and predict 1. Once 1 observation is predicted, and we are predicting the following one, is the one that has been predicted now included in those 240 observations we look back at? Is it possible to add the really observed values until time (t-1) each time we predict time t, so we are looking back at the real 240 observations at each prediction step? Thank you
@cattocat7846
@cattocat7846 Жыл бұрын
Hi, thank you so much for all your work. I would like to ask how to transform the scaled values back to their original range? Please help me, thank you so much and have a nice day.
@Suzanna2012Jan
@Suzanna2012Jan 3 жыл бұрын
Good job. Can you do a video for GAN in r regression? Thanks
@opentilartey3089
@opentilartey3089 4 жыл бұрын
Great work...
@user-px2os2rd9p
@user-px2os2rd9p 2 жыл бұрын
Dear Liquid brain, great video. Thank you. Please advise how to change code of last model (after data optimisation) if I want to have more than 2 variables. I spend a lot of time buy it doesnt work;(
@damla3843
@damla3843 4 жыл бұрын
Great video. I have a question: How can I incorporate 'lookback' and 'step' elements like you used in the video to time series classification with Support Vector Machines?
@LiquidBrain
@LiquidBrain 4 жыл бұрын
The lookback and step actually just affects the generator functions. You can just change the machine learning model in the model definitions to SVM instead of the lstm shown in the video 😀
@josefaccin
@josefaccin 3 жыл бұрын
Excellent explanation, thanks for sharing your knowledge. Are there possibilities for applying this method to forecast catches with other variables? Type: Catch ~ SST + CHL + NINO3.4, etc.
@LiquidBrain
@LiquidBrain 3 жыл бұрын
I mean I would just export the target data using a specific function,and train on those target. But I believe there's can be ways to integrate then into the network with some data transformation before the network layers.
@KS-zv1wj
@KS-zv1wj 4 жыл бұрын
can we use RNN with ARIMA to forecast covid?
@christopherbrown576
@christopherbrown576 Жыл бұрын
How do I interpret the results? I.e. the final graph does not give a temperature reading but it shows the predicted values vs the actual values. My question is: how to interpret the end result?
@shahrinislam1453
@shahrinislam1453 3 жыл бұрын
Great comprehensive content! Can you please make a video on how to make hybrid model with LSTM and other predicting models (preferably regressive model like ARIMA)?
@LiquidBrain
@LiquidBrain 3 жыл бұрын
Not very experienced in ARIMA, but sure will check it out
@shahrinislam1453
@shahrinislam1453 3 жыл бұрын
@@LiquidBrain many many thanks. Can you please direct me to some contents on how to develop hybrid lstm ?
@LiquidBrain
@LiquidBrain 3 жыл бұрын
I am not too sure about those since network structure are usually super project specific. I found one good repo here from github you might be able to check it out. github.com/perseus784/Vehicle_Collision_Prediction_Using_CNN-LSTMs
@francycharuto
@francycharuto 4 жыл бұрын
Don't we have risk of data leakage when scaling and normalizing the data before the train test split? I was expecting the generators to use train data and test data rather than data in the script as well.
@rahulnaga5010
@rahulnaga5010 4 жыл бұрын
I have a request for you...can u please do a video on APAlyzer
@lulumink0
@lulumink0 4 жыл бұрын
Great explanation of the RNN tutorial. This is the only multivariate RNN complete tutorial for R on the internet. How did you make the plot and chart show in the coding window? Thanks.
@LiquidBrain
@LiquidBrain 4 жыл бұрын
Most of the plot are done in ggplot2, when done in RMD format ( you can choose it from the new->R notebook on the file tab), the output of each code chuck will appear below.
@lulumink0
@lulumink0 4 жыл бұрын
@@LiquidBrain thanks for the quick reply. I don't get. What do you mean by RMD format? Where should I click exactly to make the plot appear right under each code blocks?
@LiquidBrain
@LiquidBrain 4 жыл бұрын
@@lulumink0 the run button on the top right corner of each chuck, you can also try to use plot(cars) to plot a simple scatter plot using the buld in dataset. RMD format is an ipython style coding interface instead of the normal scripting sheet, so you can test the code in chunks instead of using the line execute thingy you have in R
@lulumink0
@lulumink0 4 жыл бұрын
@@LiquidBrain gotcha, thanks again. One last question, this might not be easy to answer. What if you have say 50 explanatory variables in the dataset, how will you feed all those data into the model the same way as you would do in this video or do you need to use some kind of PCA to get the weights right first?
@LiquidBrain
@LiquidBrain 4 жыл бұрын
@@lulumink0 PCA would be a great way to do data reduction prior to the model training, you can also try TSNE, or just do a corrplot to the data you want to predict. I think Computerphile did a great breakdown of the data reduction process, you can search for their video tittle "Data Analysis 5: Data Reduction - Computerphile" :)
@zinmaroo6757
@zinmaroo6757 2 жыл бұрын
Thanks for your explanation. How can we get feature importance of RNN/LSTM model in R?
@LiquidBrain
@LiquidBrain 2 жыл бұрын
RNN would be a little more complicate to understand, but for MLP you can try to search for a video I made titled "Visualise a Neural Network", which grabs the weights from each epoch and superimpose onto the network diagrams. for RNN I believe you will just need a much bigger graphs or some other way of presentation.
@ignacio4654
@ignacio4654 3 жыл бұрын
How can I makr further predictions? For example, 1 year ahead
@farshadahmadi806
@farshadahmadi806 3 жыл бұрын
Are these codes work for electricity consumption forecasting as well? if no how we should change it or do we need just data transformation? Thanks for this amazing tutorial
@LiquidBrain
@LiquidBrain 3 жыл бұрын
Hard to say, these code is more for demonstration purposes and would not work that well in the real work. I would suggest a much longer prediction period with a longer look back, but models are also quite data specific
@joedifrancesco8182
@joedifrancesco8182 4 жыл бұрын
Have you figured out how to get around the fit_generator depreciation in the latest Keras?
@LiquidBrain
@LiquidBrain 4 жыл бұрын
I haven't encounter the problem since i have been exporting my data into the list 1st before feeding them into the model.fit. I will try to explore the option and maybe make another video about this. Thanks for the heads up.
@kadourkadouri3505
@kadourkadouri3505 Жыл бұрын
Great content ! however, why you didn't use logarithmic transformation to standardize the data ?
@LiquidBrain
@LiquidBrain Жыл бұрын
I usually uses log to transform data with a heavy skewness (such as gene expression), so I can get them all roughly on the same scale. For this example, most of the values are already in the same scale so I don't think it is needed. However, do feel free to add that in and check if it works better with your NN.
@briancostello939
@briancostello939 3 жыл бұрын
Great video! Any suggestions on how to predict new data (I.e. beyond the test data)?
@LiquidBrain
@LiquidBrain 3 жыл бұрын
You can always use the predict () function to load in the new data, and you should be able to get a prediction from any data that have the same Input dimensions
@briancostello939
@briancostello939 3 жыл бұрын
@@LiquidBrain sure makes sense and I assumed as much. I think another way to phrase it/be more specific, is how do you get the lags for going out into the future where data theoretically isn’t available? Do you use predictions as lag values?
@LiquidBrain
@LiquidBrain 3 жыл бұрын
For that i think you will need a model that can take the input and predict the output with the same amount of dimension. i.e. 5input node- > neurons -> 5 output nodes, after the training you can essential fit the output back as input and continuously generate new data based on a single input. I have actually try this previously, but it didn't work well for the dataset i am trying. Perhaps it will work in some other scenario or with a much larger model size.
@briancostello939
@briancostello939 3 жыл бұрын
@@LiquidBrain that’s helpful thanks so much for the detailed response
@marcoesteves4367
@marcoesteves4367 3 жыл бұрын
Is there anyway to get forecast values with this approach like we get in timeseries forecasting?
@LiquidBrain
@LiquidBrain 3 жыл бұрын
Yap, you can use the predict() fuction to feed the data back into the model to get the output
@opentilartey3089
@opentilartey3089 4 жыл бұрын
I don't understand the batch_size_plot calculation...
@zaynahchummun668
@zaynahchummun668 2 жыл бұрын
hello. Can you please tell me how long did Rstudio takes to run the codes please? Mine is taking like an eternity to run the simple keras_model_sequential() one. Any possible solution please?
@LiquidBrain
@LiquidBrain 2 жыл бұрын
You can try to reduce the size of the network, or the input? I am running mine on gpu so it was quite fast, few mins max I believe?
@nerdguru8511
@nerdguru8511 2 жыл бұрын
Hello, how does the model know that "temperature" is the response variable when it is located in the 2nd column? I do not see where you are targeting it.
@LiquidBrain
@LiquidBrain 2 жыл бұрын
In the data generation function, I have chosen the temperature column to be output~ so when data is generated it will grab that columns as the target 😃
@businessintelligenceanalyt9934
@businessintelligenceanalyt9934 2 жыл бұрын
@@LiquidBrain I now see where the "targets" object is being created. Thanks!
@muhdadamcrpt
@muhdadamcrpt 4 жыл бұрын
When i run the feedforward they asked me to download python. How could i troubleshoot this?
@LiquidBrain
@LiquidBrain 4 жыл бұрын
Try to download Python
@sojanprajapati5217
@sojanprajapati5217 4 жыл бұрын
@@LiquidBrain good suggestion. hahaha
@kseniyapak3086
@kseniyapak3086 Жыл бұрын
hello, pls help....do all like in ur code but i use wind speed data to predict it. and i cant get why for lines 241-246 of ur R code, my r got stuck every single time.
@LiquidBrain
@LiquidBrain Жыл бұрын
Is it ok for you put the code here ? It's much easier to troubleshoot
@kseniyapak3086
@kseniyapak3086 Жыл бұрын
@@LiquidBrain thanks a lot for reply! before i insurt my code....i found one difference... i have wind speed in xts format ( time series time steps) - is that the reason why it doesnt work?
@kseniyapak3086
@kseniyapak3086 Жыл бұрын
there s one thing that doesnt work: with keras: > library(keras), Attaching package: ‘keras’,The following object is masked _by_ ‘.GlobalEnv’: normalize....i googed and it says that there s smth else with the same name or so ,but how to fix it, cant find. may be you have some suggestions?
@muhammadkafiansyah9773
@muhammadkafiansyah9773 2 жыл бұрын
hii, so sorry im newkids here and my english probably bad...but anyway my question is how to return the original value of prediction data? because its between 0 -1. thanks
@LiquidBrain
@LiquidBrain 2 жыл бұрын
For that you will need to check how's the data is being normalised in the beginning and multiple the scaled data into the original data. (You will have the keep the data used for the minmax normalization and the means stddev used for the scaling)
@pinusahu
@pinusahu 3 жыл бұрын
Hi Brandon... I'm a civil engineering grad hence I'm new in this field... Due to covid, I chose a project which can be done without lab access so I wanted to incorporate data science into my domain.. I have been working on my college project on LSTM for forecasting Water Demand... I got to learn so much from your video sir... I want to tell you that, after modifying the code when I tried to run it, I'm getting an error while integrating miniconda to my R Studio... It's saying "Can't install miniconda to a path containing spaces"... Could you please help me with this... I tried to fix it but I failed so far.. Please help..!!
@LiquidBrain
@LiquidBrain 3 жыл бұрын
Can you do a getwd(), and is one of the folder in your computer have a space in the folder name? Try to remove all spaces that works with the RStudio, and see if the installation work
@pinusahu
@pinusahu 3 жыл бұрын
@@LiquidBrain yes... Actually the user folder does have a space it was named as "Asus PC"... And I'm unable to change that now😣
@abuzarpatel3295
@abuzarpatel3295 2 жыл бұрын
Is each observation unique? What if I have data in which observations are repeated. For example customer purchasing data with dates but same customers can make multiple purchases and hence customers are repeated
@abuzarpatel3295
@abuzarpatel3295 2 жыл бұрын
How can we work when observations are repeated as in multiple purchases at different times. Thank you
@LiquidBrain
@LiquidBrain 2 жыл бұрын
As in the weather data, the input are actually not unique. A cyclic patterns is actually preferred in a RNN since it's much easier to predict the output. You can just tag in the date data to make sure order of the data is preserved
@aliakbarkaramvand4963
@aliakbarkaramvand4963 2 жыл бұрын
Hi, can I ask why I get an Error of miniconda installation? What should I do?
@LiquidBrain
@LiquidBrain 2 жыл бұрын
What's your error code?
@aliakbarkaramvand4963
@aliakbarkaramvand4963 2 жыл бұрын
@@LiquidBrain there is no error code, just this message : Error: Valid installation of TensorFlow not found. Python environments searched for 'tensorflow' package: C:\Users\asus\miniconda3\python.exe
@aliakbarkaramvand4963
@aliakbarkaramvand4963 2 жыл бұрын
@@LiquidBrain I did solve it. it seem to be a version problem I have used the below code to install packages again : #devtools::install_github("rstudio/tensorflow") #devtools::install_github("rstudio/keras") #Execute the below #tensorflow::install_tensorflow() #tensorflow::tf_config()
@amishsharma7578
@amishsharma7578 4 жыл бұрын
I have a daily data, and I want to predict a target variable 1 day ahead i.e. one day in future. What should be my lookback in this case?
@LiquidBrain
@LiquidBrain 4 жыл бұрын
Hi, it is generally not recommend to predict data only one in the future since you might run into the nearest neighbor pitfall, where the algorithm might just take the previous data and project it forward. I would suggest increase your output network size and predict a long period into the future. The size of the look back is really dependent on the data and how you can get a repeatable patterns in the data history, hard to say exactly.
@amishsharma7578
@amishsharma7578 4 жыл бұрын
@@LiquidBrain Yes I see. Actually I am working on Flood prediction system. I found a research paper of china where the authors have applied LSTM model to predict discharge (Flow rate) on Hoa Binh station of Da river Basin, 1 day, 2 days and 3 days ahead. I am using R to apply LSTM on the river in india. The data has 6400 rows and 4 variables (including One target). I am taking 1 to 5844 rows for training and rest for testing. My xtrain is 2D matrix (5844, 3) and ytrain is 1D matrix (5844). I am not able to understand what should be my input shape. Can you please tell me what dimensions of xtrain I should reshape before I fed it to LSTM layer. I found that it should be [batch_size, time_steps, num_features]. So in my case, will it be correct if I keep it as [5844, 1, 3] or should it be [1, 5844, 3] or [5844*3, 1, 1]. Please guide me a little. Thank you.
Keras Preprocessing Layers
37:14
TensorFlow
Рет қаралды 33 М.
MISS CIRCLE STUDENTS BULLY ME!
00:12
Andreas Eskander
Рет қаралды 19 МЛН
Я обещал подарить ему самокат!
01:00
Vlad Samokatchik
Рет қаралды 9 МЛН
I'm Excited To see If Kelly Can Meet This Challenge!
00:16
Mini Katana
Рет қаралды 23 МЛН
Nastya and SeanDoesMagic
00:16
Nastya
Рет қаралды 38 МЛН
(Simplified) Linear Mixed Model in R with lme()
26:17
LiquidBrain Bioinformatics
Рет қаралды 66 М.
8 Tips and Tricks on R Markdown & Where have I been
10:01
LiquidBrain Bioinformatics
Рет қаралды 1,2 М.
Variational Autoencoder | Introduction and Workshop
29:15
LiquidBrain Bioinformatics
Рет қаралды 1,3 М.
Machine Learning with R and TensorFlow
59:44
Posit PBC
Рет қаралды 98 М.
Bayesian Network | Introduction and Workshop
24:22
LiquidBrain Bioinformatics
Рет қаралды 13 М.
Time Series Forecasting With RNN(LSTM)| Complete Python Tutorial|
13:58
Nachiketa Hebbar
Рет қаралды 176 М.
$1 vs $100,000 Slow Motion Camera!
0:44
Hafu Go
Рет қаралды 28 МЛН
Лучший браузер!
0:27
Honey Montana
Рет қаралды 1 МЛН
Todos os modelos de smartphone
0:20
Spider Slack
Рет қаралды 64 МЛН
Запрещенный Гаджет для Авто с aliexpress 2
0:50
Тимур Сидельников
Рет қаралды 961 М.
İĞNE İLE TELEFON TEMİZLEMEK!🤯
0:17
Safak Novruz
Рет қаралды 1,8 МЛН