{"id":47374,"date":"2021-03-10T06:14:30","date_gmt":"2021-03-10T06:14:30","guid":{"rendered":"https:\/\/www.bridge-global.com\/blog\/blog\/?p=47374"},"modified":"2021-03-10T06:17:14","modified_gmt":"2021-03-10T06:17:14","slug":"how-to-develop-predictions-using-lstm","status":"publish","type":"post","link":"https:\/\/www.bridge-global.com\/blog\/how-to-develop-predictions-using-lstm\/","title":{"rendered":"A Simple Way to Perform Prediction on Continuous Data Using LSTM"},"content":{"rendered":"<div class=\"vce-row-container\" data-vce-boxed-width=\"true\"><div class=\"vce-row vce-row--col-gap-30 vce-row-equal-height vce-row-columns--top vce-row-content--top\" id=\"el-19b846c0\" data-vce-do-apply=\"all el-19b846c0\"><div class=\"vce-row-content\" data-vce-element-content=\"true\"><div class=\"vce-col vce-col--md-auto vce-col--xs-1 vce-col--xs-last vce-col--xs-first vce-col--sm-last vce-col--sm-first vce-col--md-last vce-col--lg-last vce-col--xl-last vce-col--md-first vce-col--lg-first vce-col--xl-first\" id=\"el-9239f214\"><div class=\"vce-col-inner\" data-vce-do-apply=\"border margin background  el-9239f214\"><div class=\"vce-col-content\" data-vce-element-content=\"true\" data-vce-do-apply=\"padding el-9239f214\"><div class=\"vce-text-block\"><div class=\"vce-text-block-wrapper vce\" id=\"el-33b2312c\" data-vce-do-apply=\"all el-33b2312c\"><p>Long Short-Term Memory networks - usually just called \"LSTM\" - are a special type of Recurrent Neural Network or RNN, which can learn long-term dependencies.<\/p><p>They were introduced by Hochreiter &amp; Schmidhuber and were refined and made popular by many in their work. They work incredibly well on a variety of problems and are now widely used. LSTM is specifically designed to avoid dependency problems. Remembering information for a long time is almost their default behavior, not something they have a hard time learning!<\/p><p>All RNNs have the form of a chain of repeating neural network units. In standard RNNs, this repeating unit will have a very simple structure, such as a tanh layer.<\/p><\/div><\/div><\/div><\/div><\/div><\/div><\/div><\/div><div class=\"vce-row-container\" data-vce-boxed-width=\"true\"><div class=\"vce-row vce-row--col-gap-30 vce-row-equal-height vce-row-columns--top vce-row-content--top\" id=\"el-f7b31e95\" data-vce-do-apply=\"all el-f7b31e95\"><div class=\"vce-row-content\" data-vce-element-content=\"true\"><div class=\"vce-col vce-col--md-auto vce-col--xs-1 vce-col--xs-last vce-col--xs-first vce-col--sm-last vce-col--sm-first vce-col--md-last vce-col--lg-last vce-col--xl-last vce-col--md-first vce-col--lg-first vce-col--xl-first\" id=\"el-ae68b63d\"><div class=\"vce-col-inner\" data-vce-do-apply=\"border margin background  el-ae68b63d\"><div class=\"vce-col-content\" data-vce-element-content=\"true\" data-vce-do-apply=\"padding el-ae68b63d\"><div class=\"vce-text-block\"><div class=\"vce-text-block-wrapper vce\" id=\"el-b350fc69\" data-vce-do-apply=\"all el-b350fc69\"><h2 dir=\"ltr\" style=\"line-height: 1.38; text-align: justify; margin-top: 12pt; margin-bottom: 12pt;\">&nbsp;A step-by-step guide<\/h2>\n<p dir=\"ltr\" style=\"line-height: 1.38; text-align: justify; margin-top: 12pt; margin-bottom: 12pt;\"><span style=\"font-size: 12pt; font-family: inherit; color: #202124; background-color: transparent; font-variant-numeric: normal; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;\">To import the continuous data, first we need to train the model. Here in the example, I have shown an empty list in which you can populate your required data.<\/span><\/p><\/div><\/div><\/div><\/div><\/div><\/div><\/div><\/div><div class=\"vce-row-container\" data-vce-boxed-width=\"true\"><div class=\"vce-row vce-row--col-gap-30 vce-row-equal-height vce-row-columns--top vce-row-content--top\" id=\"el-83de5bbd\" data-vce-do-apply=\"all el-83de5bbd\"><div class=\"vce-row-content\" data-vce-element-content=\"true\"><div class=\"vce-col vce-col--md-auto vce-col--xs-1 vce-col--xs-last vce-col--xs-first vce-col--sm-last vce-col--sm-first vce-col--md-last vce-col--lg-last vce-col--xl-last vce-col--md-first vce-col--lg-first vce-col--xl-first\" id=\"el-42d9098e\"><div class=\"vce-col-inner\" data-vce-do-apply=\"border margin background  el-42d9098e\"><div class=\"vce-col-content\" data-vce-element-content=\"true\" data-vce-do-apply=\"padding el-42d9098e\"><div class=\"vce-text-block\"><div class=\"vce-text-block-wrapper vce\" id=\"el-87498aea\" data-vce-do-apply=\"all el-87498aea\"><\/div><\/div><div class=\"vce-single-image-container vce-single-image--align-center\"><div class=\"vce vce-single-image-wrapper\" id=\"el-ad0f851c\" data-vce-do-apply=\"all el-ad0f851c\"><figure><div class=\"vce-single-image-inner vce-single-image--absolute\" style=\"padding-bottom: 56.25%; width: 512px;\"><img loading=\"lazy\" decoding=\"async\" class=\"vce-single-image\" width=\"512\" height=\"288\" src=\"https:\/\/www.bridge-global.com\/blog\/wp-content\/uploads\/2021\/03\/Perform-Prediction-on-Continuous-Data-Using-LSTM-create-trining-data-set-512x288.jpg\" srcset=\"https:\/\/www.bridge-global.com\/blog\/wp-content\/uploads\/2021\/03\/Perform-Prediction-on-Continuous-Data-Using-LSTM-create-trining-data-set-320x180.jpg 320w,https:\/\/www.bridge-global.com\/blog\/wp-content\/uploads\/2021\/03\/Perform-Prediction-on-Continuous-Data-Using-LSTM-create-trining-data-set-480x270.jpg 480w,https:\/\/www.bridge-global.com\/blog\/wp-content\/uploads\/2021\/03\/Perform-Prediction-on-Continuous-Data-Using-LSTM-create-trining-data-set-512x288.jpg 512w\" data-img-src=\"https:\/\/www.bridge-global.com\/blog\/wp-content\/uploads\/2021\/03\/Perform-Prediction-on-Continuous-Data-Using-LSTM-create-trining-data-set.jpg\" alt=\"Develop &amp; Make Predictions Using LSTM Networks\" title=\"Perform Prediction on Continuous Data Using LSTM-create training data set\" \/><\/div><figcaption hidden=\"\"><\/figcaption><\/figure><\/div><\/div><div class=\"vce-text-block\"><div class=\"vce-text-block-wrapper vce\" id=\"el-0789dc46\" data-vce-do-apply=\"all el-0789dc46\"><p>Also, you can set the training rate as well. I recommend setting it to 80. I am also using a Min-Max scaler in this program. The Min-Max scaler is a way to normalize the input features\/variables. By doing so, all features will be transformed into a range [0,1] which means that the minimum and maximum value of a feature \/ variable are 0 and 1, respectively.<\/p><\/div><\/div><div class=\"vce-single-image-container vce-single-image--align-center\"><div class=\"vce vce-single-image-wrapper\" id=\"el-5b5abf1d\" data-vce-do-apply=\"all el-5b5abf1d\"><figure><div class=\"vce-single-image-inner vce-single-image--absolute\" style=\"padding-bottom: 36.7188%; width: 512px;\"><img loading=\"lazy\" decoding=\"async\" class=\"vce-single-image\" width=\"512\" height=\"188\" src=\"https:\/\/www.bridge-global.com\/blog\/wp-content\/uploads\/2021\/03\/Perform-Prediction-on-Continuous-Data-Using-LSTM-Build-LSTM-NEtwork-512x188.jpg\" srcset=\"https:\/\/www.bridge-global.com\/blog\/wp-content\/uploads\/2021\/03\/Perform-Prediction-on-Continuous-Data-Using-LSTM-Build-LSTM-NEtwork-320x118.jpg 320w,https:\/\/www.bridge-global.com\/blog\/wp-content\/uploads\/2021\/03\/Perform-Prediction-on-Continuous-Data-Using-LSTM-Build-LSTM-NEtwork-480x176.jpg 480w,https:\/\/www.bridge-global.com\/blog\/wp-content\/uploads\/2021\/03\/Perform-Prediction-on-Continuous-Data-Using-LSTM-Build-LSTM-NEtwork-512x188.jpg 512w\" data-img-src=\"https:\/\/www.bridge-global.com\/blog\/wp-content\/uploads\/2021\/03\/Perform-Prediction-on-Continuous-Data-Using-LSTM-Build-LSTM-NEtwork.jpg\" alt=\"Perform Prediction on Continuous Data Using LSTM-Build LSTM Network\" title=\"Perform Prediction on Continuous Data Using LSTM-Build LSTM NEtwork\" \/><\/div><figcaption hidden=\"\"><\/figcaption><\/figure><\/div><\/div><div class=\"vce-text-block\"><div class=\"vce-text-block-wrapper vce\" id=\"el-83c561f4\" data-vce-do-apply=\"all el-83c561f4\"><p>Now&nbsp; we can build our LSTM network. Here I have built four layers, in which the fourth one is the output layer which does the prediction part. Here we have used <a href=\"https:\/\/machinelearningmastery.com\/adam-optimization-algorithm-for-deep-learning\/#:~:text=Adam%20is%20a%20replacement%20optimization,sparse%20gradients%20on%20noisy%20problems.\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Adam as our optimizer<\/a>. Adam is a continuation of the stochastic gradient values \u200b\u200bthat have recently been observed in the application of in-depth studies in computer vision and natural language processing.<\/p><p>We can set the epoch count as well. It\u2019s a good idea to visualize the learning curve as well in order to prevent overfitting of the model.&nbsp;<\/p><\/div><\/div><div class=\"vce-single-image-container vce-single-image--align-center\"><div class=\"vce vce-single-image-wrapper\" id=\"el-d0cf4ce0\" data-vce-do-apply=\"all el-d0cf4ce0\"><figure><div class=\"vce-single-image-inner vce-single-image--absolute\" style=\"padding-bottom: 34.7656%; width: 512px;\"><img loading=\"lazy\" decoding=\"async\" class=\"vce-single-image\" width=\"512\" height=\"178\" src=\"https:\/\/www.bridge-global.com\/blog\/wp-content\/uploads\/2021\/03\/Perform-Prediction-on-Continuous-Data-Using-LSTM-generate-test-data-set-512x178.jpg\" srcset=\"https:\/\/www.bridge-global.com\/blog\/wp-content\/uploads\/2021\/03\/Perform-Prediction-on-Continuous-Data-Using-LSTM-generate-test-data-set-320x111.jpg 320w,https:\/\/www.bridge-global.com\/blog\/wp-content\/uploads\/2021\/03\/Perform-Prediction-on-Continuous-Data-Using-LSTM-generate-test-data-set-480x167.jpg 480w,https:\/\/www.bridge-global.com\/blog\/wp-content\/uploads\/2021\/03\/Perform-Prediction-on-Continuous-Data-Using-LSTM-generate-test-data-set-512x178.jpg 512w\" data-img-src=\"https:\/\/www.bridge-global.com\/blog\/wp-content\/uploads\/2021\/03\/Perform-Prediction-on-Continuous-Data-Using-LSTM-generate-test-data-set.jpg\" alt=\"Perform Prediction on Continuous Data Using LSTM-generate test data set\" title=\"Perform Prediction on Continuous Data Using LSTM-generate test data set\" \/><\/div><figcaption hidden=\"\"><\/figcaption><\/figure><\/div><\/div><div class=\"vce-text-block\"><div class=\"vce-text-block-wrapper vce\" id=\"el-840266ae\" data-vce-do-apply=\"all el-840266ae\"><p>We have set our training data length on our previous step. The remaining will be assigned as test data in this step.<\/p><\/div><\/div><div class=\"vce-single-image-container vce-single-image--align-center\"><div class=\"vce vce-single-image-wrapper\" id=\"el-ca6a1577\" data-vce-do-apply=\"all el-ca6a1577\"><figure><div class=\"vce-single-image-inner vce-single-image--absolute\" style=\"padding-bottom: 16.4062%; width: 512px;\"><img loading=\"lazy\" decoding=\"async\" class=\"vce-single-image\" width=\"512\" height=\"84\" src=\"https:\/\/www.bridge-global.com\/blog\/wp-content\/uploads\/2021\/03\/Perform-Prediction-on-Continuous-Data-Using-LSTM-Prediction-512x84.jpg\" srcset=\"https:\/\/www.bridge-global.com\/blog\/wp-content\/uploads\/2021\/03\/Perform-Prediction-on-Continuous-Data-Using-LSTM-Prediction-320x53.jpg 320w,https:\/\/www.bridge-global.com\/blog\/wp-content\/uploads\/2021\/03\/Perform-Prediction-on-Continuous-Data-Using-LSTM-Prediction-480x79.jpg 480w,https:\/\/www.bridge-global.com\/blog\/wp-content\/uploads\/2021\/03\/Perform-Prediction-on-Continuous-Data-Using-LSTM-Prediction-512x84.jpg 512w\" data-img-src=\"https:\/\/www.bridge-global.com\/blog\/wp-content\/uploads\/2021\/03\/Perform-Prediction-on-Continuous-Data-Using-LSTM-Prediction.jpg\" alt=\"Perform Prediction on Continuous Data Using LSTM-Prediction\" title=\"Perform Prediction on Continuous Data Using LSTM-Prediction\" \/><\/div><figcaption hidden=\"\"><\/figcaption><\/figure><\/div><\/div><div class=\"vce-text-block\"><div class=\"vce-text-block-wrapper vce\" id=\"el-a418c500\" data-vce-do-apply=\"all el-a418c500\"><p>After the training part we can do our prediction on the test data to check the accuracy of our model. After the prediction it is important to rescale the values as we have used a scaler previously.<\/p><\/div><\/div><div class=\"vce-text-block\"><div class=\"vce-text-block-wrapper vce\" id=\"el-16e0c567\" data-vce-do-apply=\"all el-16e0c567\"><h2><span style=\"font-size: 24px;\">Wrapping Up<\/span><\/h2><p>&nbsp;LSTMs are a big step towards what we can accomplish with RNN. It is important to think, is there another big step? One of the greatest thoughts of any researcher...Yes! There is a next step and it is attention! The idea is to allow every step of the RNN to store data for viewing on some large file.&nbsp;<\/p><\/div><\/div><div class=\"vce-text-block\"><div class=\"vce-text-block-wrapper vce\" id=\"el-88080d15\" data-vce-do-apply=\"all el-88080d15\"><h2 dir=\"ltr\" style=\"line-height: 1.38; margin-top: 12pt; margin-bottom: 12pt;\">&nbsp;<\/h2><\/div><\/div><div class=\"vce-text-block\"><div class=\"vce-text-block-wrapper vce\" id=\"el-4eef78fa\" data-vce-do-apply=\"all el-4eef78fa\"><\/div><\/div><div class=\"vce-text-block\"><div class=\"vce-text-block-wrapper vce\" id=\"el-130f5e85\" data-vce-do-apply=\"all el-130f5e85\"><\/div><\/div><\/div><\/div><\/div><\/div><\/div><\/div><div class=\"vce-row-container\" data-vce-boxed-width=\"true\"><div class=\"vce-row vce-row--col-gap-30 vce-row-equal-height vce-row-columns--top vce-row-content--top vcv-state--show-resizer\" id=\"el-34841ec9\" data-vce-do-apply=\"all el-34841ec9\"><div class=\"vce-row-content\" data-vce-element-content=\"true\"><div class=\"vce-col vce-col--md-auto vce-col--xs-1 vce-col--xs-last vce-col--xs-first vce-col--sm-last vce-col--sm-first vce-col--md-last vce-col--lg-last vce-col--xl-last vce-col--md-first vce-col--lg-first vce-col--xl-first\" id=\"el-0c41c3c4\"><div class=\"vce-col-inner\" data-vce-do-apply=\"border margin background  el-0c41c3c4\"><div class=\"vce-col-content\" data-vce-element-content=\"true\" data-vce-do-apply=\"padding el-0c41c3c4\"><\/div><\/div><\/div><\/div><\/div><\/div><div class=\"vce-row-container\" data-vce-boxed-width=\"true\"><div class=\"vce-row vce-row--col-gap-30 vce-row-equal-height vce-row-columns--top vce-row-content--top\" id=\"el-ec6b9d37\" data-vce-do-apply=\"all el-ec6b9d37\"><div class=\"vce-row-content\" data-vce-element-content=\"true\"><div class=\"vce-col vce-col--md-auto vce-col--xs-1 vce-col--xs-last vce-col--xs-first vce-col--sm-last vce-col--sm-first vce-col--md-last vce-col--lg-last vce-col--xl-last vce-col--md-first vce-col--lg-first vce-col--xl-first\" id=\"el-6bc22b2c\"><div class=\"vce-col-inner\" data-vce-do-apply=\"border margin background  el-6bc22b2c\"><div class=\"vce-col-content\" data-vce-element-content=\"true\" data-vce-do-apply=\"padding el-6bc22b2c\"><\/div><\/div><\/div><\/div><\/div><\/div>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Understanding the patterns in the sequence of data is important to predict the future. Here\u2019s a crisp guide to developing predictions using LSTM networks.<br \/>\n<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":154,"featured_media":47384,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[127,174,317],"tags":[361,362,363,364],"class_list":["post-47374","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-artificial-intelligence","category-machine-learning","category-technology-tips","tag-lstm","tag-ai","tag-machine-learning","tag-long-short-term-memory-networks"],"featured_image_src":"https:\/\/www.bridge-global.com\/blog\/wp-content\/uploads\/2021\/03\/How-to-Develop-Make-Predictions-Using-LSTM-Networks_.jpg","author_info":{"display_name":"Sanjay Sabu","author_link":"https:\/\/www.bridge-global.com\/blog\/author\/sanjaysabu\/"},"_links":{"self":[{"href":"https:\/\/www.bridge-global.com\/blog\/wp-json\/wp\/v2\/posts\/47374","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bridge-global.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bridge-global.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bridge-global.com\/blog\/wp-json\/wp\/v2\/users\/154"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bridge-global.com\/blog\/wp-json\/wp\/v2\/comments?post=47374"}],"version-history":[{"count":11,"href":"https:\/\/www.bridge-global.com\/blog\/wp-json\/wp\/v2\/posts\/47374\/revisions"}],"predecessor-version":[{"id":47391,"href":"https:\/\/www.bridge-global.com\/blog\/wp-json\/wp\/v2\/posts\/47374\/revisions\/47391"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bridge-global.com\/blog\/wp-json\/wp\/v2\/media\/47384"}],"wp:attachment":[{"href":"https:\/\/www.bridge-global.com\/blog\/wp-json\/wp\/v2\/media?parent=47374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bridge-global.com\/blog\/wp-json\/wp\/v2\/categories?post=47374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bridge-global.com\/blog\/wp-json\/wp\/v2\/tags?post=47374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}