{"id":1783,"date":"2018-01-19T01:41:50","date_gmt":"2018-01-19T01:41:50","guid":{"rendered":"http:\/\/intelligentonlinetools.com\/blog\/?p=1783"},"modified":"2018-03-02T01:36:43","modified_gmt":"2018-03-02T01:36:43","slug":"machine-learning-stock-prediction-lstm-keras","status":"publish","type":"post","link":"http:\/\/intelligentonlinetools.com\/blog\/2018\/01\/19\/machine-learning-stock-prediction-lstm-keras\/","title":{"rendered":"Machine Learning Stock Prediction with LSTM and Keras"},"content":{"rendered":"<p>In this post I will share experiments on machine learning stock prediction with <b>LSTM<\/b> and Keras with one step ahead. I tried to do  first multiple steps ahead with few techniques described in the papers on the web.  But I discovered that I need fully understand and test the simplest model &#8211; prediction for one step ahead. So I put here the example of prediction of stock price data time series for one next step.<\/p>\n<h3>Preparing Data for Neural Network Prediction<\/h3>\n<p>Our first task is feed the data into LSTM. Our data is <b>stock price<\/b> data time series that were downloaded from the web.<br \/>\nOur interest is closed price for the next day so target variable will be <b>closed price<\/b> but shifted to left (back) by one step.<\/p>\n<p>Figure below is showing how do we prepare X, Y data.<br \/>\nPlease note that I put X Y horizontally for convenience but still calling X, Y as columns.<br \/>\nAlso on this figure only one variable (closed price) is showed for X but in the code it is actually more than one variable (it is closed price, open price, volume and high price).    <\/p>\n<figure id=\"attachment_1787\" aria-describedby=\"caption-attachment-1787\" style=\"width: 726px\" class=\"wp-caption alignnone\"><img data-attachment-id=\"1787\" data-permalink=\"http:\/\/intelligentonlinetools.com\/blog\/2018\/01\/19\/machine-learning-stock-prediction-lstm-keras\/lstm-data-input-2\/#main\" data-orig-file=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/lstm-data-input-2.png\" data-orig-size=\"736,841\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"LSTM data input\" data-image-description=\"&lt;p&gt;LSTM data input &#8211; preparing data for input&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;LSTM data input&lt;\/p&gt;\n\" data-medium-file=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/lstm-data-input-2-263x300.png\" data-large-file=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/lstm-data-input-2.png\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/lstm-data-input-2.png\" alt=\"LSTM data input\" width=\"736\" height=\"841\" class=\"size-full wp-image-1787\" srcset=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/lstm-data-input-2.png 736w, http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/lstm-data-input-2-263x300.png 263w\" sizes=\"(max-width: 736px) 100vw, 736px\" \/><figcaption id=\"caption-attachment-1787\" class=\"wp-caption-text\">LSTM data input<\/figcaption><\/figure>\n<p>Now we have the data that we can feed for LSTM neural network prediction. Before doing this we need also do the following things:<\/p>\n<p>1. Decide how many data we want to use. For example if we have data for 10 years but want use only last 200 rows of data we would need specify start point because the most recent data will be in the end.<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n#how many data we will use \r\n# (should not be more than dataset length )\r\ndata_to_use= 100\r\n\r\n# number of training data\r\n# should be less than data_to_use\r\ntrain_end =70\r\n\r\n\r\ntotal_data=len(data_csv)\r\n\r\n#most recent data is in the end \r\n#so need offset\r\nstart=total_data - data_to_use\r\n<\/pre>\n<p>2. Rescale (normalize) data as below. Here feature_range  is tuple (min, max), default=(0, 1)  is desired range of transformed data. [1]<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nscaler_x = preprocessing.MinMaxScaler ( feature_range =( -1, 1))\r\nx = np. array (x).reshape ((len( x) ,len(cols)))\r\nx = scaler_x.fit_transform (x)\r\n\r\n\r\nscaler_y = preprocessing. MinMaxScaler ( feature_range =( -1, 1))\r\ny = np.array (y).reshape ((len( y), 1))\r\ny = scaler_y.fit_transform (y)\r\n<\/pre>\n<p>3. Divide data into training and testing set. <\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nx_train = x [0: train_end,]\r\nx_test = x[ train_end +1:len(x),]    \r\ny_train = y [0: train_end] \r\ny_test = y[ train_end +1:len(y)]  \r\n<\/pre>\n<h3>Building and Running LSTM<\/h3>\n<p>Now we need to define our LSTM neural network layers ,  parameters and run neural network to see how it works.<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nfit1 = Sequential ()\r\nfit1.add (LSTM (  1000 , activation = 'tanh', inner_activation = 'hard_sigmoid' , input_shape =(len(cols), 1) ))\r\nfit1.add(Dropout(0.2))\r\nfit1.add (Dense (output_dim =1, activation = 'linear'))\r\n\r\nfit1.compile (loss =&quot;mean_squared_error&quot; , optimizer = &quot;adam&quot;)   \r\nfit1.fit (x_train, y_train, batch_size =16, nb_epoch =25, shuffle = False)\r\n<\/pre>\n<p>The first run was not good &#8211; prediction was way below actual.<\/p>\n<p>However by changing the number of neurons in LSTM neural network prediction code, it was possible to improve MSE and get predictions much closer to actual data.  Below are screenshots of plots of prediction and actual data for LSTM with 5, 60 and 1000 neurons. Note that the plot is showing only testing data. Training data is not shown on the plots. Also you can find below the data for MSE and number of neurons. As the number neorons in LSTM layer is changing there were 2 minimums (one around 100 neurons and another around 1000 neurons)<\/p>\n<figure id=\"attachment_1791\" aria-describedby=\"caption-attachment-1791\" style=\"width: 378px\" class=\"wp-caption alignnone\"><img data-attachment-id=\"1791\" data-permalink=\"http:\/\/intelligentonlinetools.com\/blog\/2018\/01\/19\/machine-learning-stock-prediction-lstm-keras\/lstm5_one_steap_ahead_prediction\/#main\" data-orig-file=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/LSTM5_one_steap_ahead_prediction.jpg\" data-orig-size=\"388,284\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Leo&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1516458540&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"LSTM5_one_steap_ahead_prediction\" data-image-description=\"&lt;p&gt;Results of prediction on LSTM with 5 neurons&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Results of prediction on LSTM with 5 neurons&lt;\/p&gt;\n\" data-medium-file=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/LSTM5_one_steap_ahead_prediction-300x220.jpg\" data-large-file=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/LSTM5_one_steap_ahead_prediction.jpg\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/LSTM5_one_steap_ahead_prediction.jpg\" alt=\"Results of prediction on LSTM with 5 neurons\" width=\"388\" height=\"284\" class=\"size-full wp-image-1791\" srcset=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/LSTM5_one_steap_ahead_prediction.jpg 388w, http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/LSTM5_one_steap_ahead_prediction-300x220.jpg 300w\" sizes=\"(max-width: 388px) 100vw, 388px\" \/><figcaption id=\"caption-attachment-1791\" class=\"wp-caption-text\">Results of prediction on LSTM with 5 neurons<\/figcaption><\/figure>\n<figure id=\"attachment_1951\" aria-describedby=\"caption-attachment-1951\" style=\"width: 362px\" class=\"wp-caption alignnone\"><img data-attachment-id=\"1951\" data-permalink=\"http:\/\/intelligentonlinetools.com\/blog\/2018\/01\/19\/machine-learning-stock-prediction-lstm-keras\/forecasting-one-step-ahead-lstm-60-3_1_2018\/#main\" data-orig-file=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/Forecasting-one-step-ahead-LSTM-60-3_1_2018.png\" data-orig-size=\"372,287\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Forecasting one step ahead LSTM 60 3_1_2018\" data-image-description=\"&lt;p&gt;Forecasting one step ahead LSTM 60 &lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Forecasting one step ahead LSTM 60 &lt;\/p&gt;\n\" data-medium-file=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/Forecasting-one-step-ahead-LSTM-60-3_1_2018-300x231.png\" data-large-file=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/Forecasting-one-step-ahead-LSTM-60-3_1_2018.png\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/Forecasting-one-step-ahead-LSTM-60-3_1_2018.png\" alt=\"Forecasting one step ahead LSTM 60 \" width=\"372\" height=\"287\" class=\"size-full wp-image-1951\" srcset=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/Forecasting-one-step-ahead-LSTM-60-3_1_2018.png 372w, http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/Forecasting-one-step-ahead-LSTM-60-3_1_2018-300x231.png 300w\" sizes=\"(max-width: 372px) 100vw, 372px\" \/><figcaption id=\"caption-attachment-1951\" class=\"wp-caption-text\">Results of prediction on LSTM with 60 neurons<\/figcaption><\/figure>\n<figure id=\"attachment_1948\" aria-describedby=\"caption-attachment-1948\" style=\"width: 388px\" class=\"wp-caption alignnone\"><img data-attachment-id=\"1948\" data-permalink=\"http:\/\/intelligentonlinetools.com\/blog\/2018\/01\/19\/machine-learning-stock-prediction-lstm-keras\/forecasting-one-step-ahead-3_1_2018\/#main\" data-orig-file=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/forecasting-one-step-ahead-3_1_2018.png\" data-orig-size=\"398,289\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Forecasting one step ahead\" data-image-description=\"&lt;p&gt;Forecasting one step ahead&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Forecasting one step ahead&lt;\/p&gt;\n\" data-medium-file=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/forecasting-one-step-ahead-3_1_2018-300x218.png\" data-large-file=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/forecasting-one-step-ahead-3_1_2018.png\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/forecasting-one-step-ahead-3_1_2018.png\" alt=\"Forecasting one step ahead\" width=\"398\" height=\"289\" class=\"size-full wp-image-1948\" srcset=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/forecasting-one-step-ahead-3_1_2018.png 398w, http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/forecasting-one-step-ahead-3_1_2018-300x218.png 300w\" sizes=\"(max-width: 398px) 100vw, 398px\" \/><figcaption id=\"caption-attachment-1948\" class=\"wp-caption-text\">Results of prediction on LSTM with 1000 neurons<\/figcaption><\/figure>\n<p>LSTM 5<br \/>\n in train MSE =  0.0475<br \/>\n in test MSE =  0.2714831660102521<\/p>\n<p>LSTM 60<br \/>\n in train MSE =  0.0127<br \/>\n in test MSE =  0.02227417068206705 <\/p>\n<p>LSTM 100<br \/>\n in train MSE =  0.0126<br \/>\n in test MSE =  0.018672733913263073 <\/p>\n<p>LSTM 200<br \/>\n in train MSE =  0.0133<br \/>\n in test MSE =  0.020082660237026824<\/p>\n<p>LSTM 900<br \/>\n in train MSE =  0.0103<br \/>\n in test MSE =  0.015546535929778267 <\/p>\n<p>LSTM 1000<br \/>\n in train MSE =  0.0104<br \/>\n in test MSE =  0.015037054958075455  <\/p>\n<p>LSTM 1100<br \/>\n in train MSE =  0.0113<br \/>\n in test MSE =  0.016363980411369994 <\/p>\n<h3>Conclusion<\/h3>\n<p>The final LSTM was running with testing MSE 0.015 and accuracy 97%. This was obtained by changing number of neurons in LSTM. This example will serve as baseline for further possible improvements on machine learning stock prediction with LSTM. If you have any tips or anything else to add, please leave a comment the comment box. The full source code for LSTM neural network prediction can be found <a href=\"http:\/\/intelligentonlinetools.com\/blog\/2018\/01\/20\/machine-learning-stock-prediction-lstm-keras-python-source-code\/\" target=\"_blank\">here<\/a><\/p>\n<p><strong>References<\/strong><br \/>\n1. <a href=http:\/\/scikit-learn.org\/stable\/modules\/generated\/sklearn.preprocessing.MinMaxScaler.html target=\"_blank\">sklearn.preprocessing.MinMaxScaler<\/a><br \/>\n2. <a href=\"https:\/\/faroit.github.io\/keras-docs\/2.0.4\/layers\/recurrent\/\" target=\"_blank\">Keras documentation &#8211; RNN Layers<\/a><br \/>\n3. <a href=https:\/\/machinelearningmastery.com\/reshape-input-data-long-short-term-memory-networks-keras\/ target=\"_blank\">How to Reshape Input Data for Long Short-Term Memory Networks in Keras<\/a><br \/>\n4. <a href=https:\/\/keras.io\/getting-started\/faq\/#what-does-sample-batch-epoch-mean target=\"_blank\">Keras FAQ: Frequently Asked Keras Questions<\/a><br \/>\n5. <a href=https:\/\/machinelearningmastery.com\/time-series-prediction-lstm-recurrent-neural-networks-python-keras\/ target=\"_blank\">Time Series Prediction with LSTM Recurrent Neural Networks in Python with Keras<\/a><br \/>\n6.<a href=https:\/\/www.amazon.com\/Deep-Time-Forecasting-Python-Introduction\/dp\/1540809080 target=\"_blank\">Deep Time Series Forecasting with Python: An Intuitive Introduction to Deep Learning for Applied Time Series Modeling<\/a><br \/>\n7. <a href=\"http:\/\/intelligentonlinetools.com\/blog\/2018\/01\/20\/machine-learning-stock-prediction-lstm-keras-python-source-code\/\" target=\"_blank\">Machine Learning Stock Prediction with LSTM and Keras &#8211; Python Source Code<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post I will share experiments on machine learning stock prediction with LSTM and Keras with one step ahead. I tried to do first multiple steps ahead with few techniques described in the papers on the web. But I discovered that I need fully understand and test the simplest model &#8211; prediction for one &#8230; <a title=\"Machine Learning Stock Prediction with LSTM and Keras\" class=\"read-more\" href=\"http:\/\/intelligentonlinetools.com\/blog\/2018\/01\/19\/machine-learning-stock-prediction-lstm-keras\/\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":[]},"categories":[9,10,3],"tags":[42,49,48,18,51,52,16],"jetpack_publicize_connections":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Machine Learning Stock Prediction with LSTM and Keras - Machine Learning Applications<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/intelligentonlinetools.com\/blog\/2018\/01\/19\/machine-learning-stock-prediction-lstm-keras\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Machine Learning Stock Prediction with LSTM and Keras - Machine Learning Applications\" \/>\n<meta property=\"og:description\" content=\"In this post I will share experiments on machine learning stock prediction with LSTM and Keras with one step ahead. I tried to do first multiple steps ahead with few techniques described in the papers on the web. But I discovered that I need fully understand and test the simplest model &#8211; prediction for one ... Read more\" \/>\n<meta property=\"og:url\" content=\"http:\/\/intelligentonlinetools.com\/blog\/2018\/01\/19\/machine-learning-stock-prediction-lstm-keras\/\" \/>\n<meta property=\"og:site_name\" content=\"Machine Learning Applications\" \/>\n<meta property=\"article:published_time\" content=\"2018-01-19T01:41:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-03-02T01:36:43+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/lstm-data-input-2.png\" \/>\n<meta name=\"author\" content=\"owygs156\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"owygs156\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/intelligentonlinetools.com\/blog\/2018\/01\/19\/machine-learning-stock-prediction-lstm-keras\/\",\"url\":\"http:\/\/intelligentonlinetools.com\/blog\/2018\/01\/19\/machine-learning-stock-prediction-lstm-keras\/\",\"name\":\"Machine Learning Stock Prediction with LSTM and Keras - Machine Learning Applications\",\"isPartOf\":{\"@id\":\"http:\/\/intelligentonlinetools.com\/blog\/#website\"},\"datePublished\":\"2018-01-19T01:41:50+00:00\",\"dateModified\":\"2018-03-02T01:36:43+00:00\",\"author\":{\"@id\":\"http:\/\/intelligentonlinetools.com\/blog\/#\/schema\/person\/7a886dc5eb9758369af2f6d2cb342478\"},\"breadcrumb\":{\"@id\":\"http:\/\/intelligentonlinetools.com\/blog\/2018\/01\/19\/machine-learning-stock-prediction-lstm-keras\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/intelligentonlinetools.com\/blog\/2018\/01\/19\/machine-learning-stock-prediction-lstm-keras\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/intelligentonlinetools.com\/blog\/2018\/01\/19\/machine-learning-stock-prediction-lstm-keras\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/intelligentonlinetools.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Machine Learning Stock Prediction with LSTM and Keras\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/intelligentonlinetools.com\/blog\/#website\",\"url\":\"http:\/\/intelligentonlinetools.com\/blog\/\",\"name\":\"Machine Learning Applications\",\"description\":\"Artificial intelligence, data mining and machine learning for building web based tools and services.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/intelligentonlinetools.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/intelligentonlinetools.com\/blog\/#\/schema\/person\/7a886dc5eb9758369af2f6d2cb342478\",\"name\":\"owygs156\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/intelligentonlinetools.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/2.gravatar.com\/avatar\/b351def598609cb4c0b5bca26497c7e5?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/2.gravatar.com\/avatar\/b351def598609cb4c0b5bca26497c7e5?s=96&d=mm&r=g\",\"caption\":\"owygs156\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Machine Learning Stock Prediction with LSTM and Keras - Machine Learning Applications","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/intelligentonlinetools.com\/blog\/2018\/01\/19\/machine-learning-stock-prediction-lstm-keras\/","og_locale":"en_US","og_type":"article","og_title":"Machine Learning Stock Prediction with LSTM and Keras - Machine Learning Applications","og_description":"In this post I will share experiments on machine learning stock prediction with LSTM and Keras with one step ahead. I tried to do first multiple steps ahead with few techniques described in the papers on the web. But I discovered that I need fully understand and test the simplest model &#8211; prediction for one ... Read more","og_url":"http:\/\/intelligentonlinetools.com\/blog\/2018\/01\/19\/machine-learning-stock-prediction-lstm-keras\/","og_site_name":"Machine Learning Applications","article_published_time":"2018-01-19T01:41:50+00:00","article_modified_time":"2018-03-02T01:36:43+00:00","og_image":[{"url":"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/01\/lstm-data-input-2.png"}],"author":"owygs156","twitter_card":"summary_large_image","twitter_misc":{"Written by":"owygs156","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/intelligentonlinetools.com\/blog\/2018\/01\/19\/machine-learning-stock-prediction-lstm-keras\/","url":"http:\/\/intelligentonlinetools.com\/blog\/2018\/01\/19\/machine-learning-stock-prediction-lstm-keras\/","name":"Machine Learning Stock Prediction with LSTM and Keras - Machine Learning Applications","isPartOf":{"@id":"http:\/\/intelligentonlinetools.com\/blog\/#website"},"datePublished":"2018-01-19T01:41:50+00:00","dateModified":"2018-03-02T01:36:43+00:00","author":{"@id":"http:\/\/intelligentonlinetools.com\/blog\/#\/schema\/person\/7a886dc5eb9758369af2f6d2cb342478"},"breadcrumb":{"@id":"http:\/\/intelligentonlinetools.com\/blog\/2018\/01\/19\/machine-learning-stock-prediction-lstm-keras\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/intelligentonlinetools.com\/blog\/2018\/01\/19\/machine-learning-stock-prediction-lstm-keras\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/intelligentonlinetools.com\/blog\/2018\/01\/19\/machine-learning-stock-prediction-lstm-keras\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/intelligentonlinetools.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Machine Learning Stock Prediction with LSTM and Keras"}]},{"@type":"WebSite","@id":"http:\/\/intelligentonlinetools.com\/blog\/#website","url":"http:\/\/intelligentonlinetools.com\/blog\/","name":"Machine Learning Applications","description":"Artificial intelligence, data mining and machine learning for building web based tools and services.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/intelligentonlinetools.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/intelligentonlinetools.com\/blog\/#\/schema\/person\/7a886dc5eb9758369af2f6d2cb342478","name":"owygs156","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/intelligentonlinetools.com\/blog\/#\/schema\/person\/image\/","url":"http:\/\/2.gravatar.com\/avatar\/b351def598609cb4c0b5bca26497c7e5?s=96&d=mm&r=g","contentUrl":"http:\/\/2.gravatar.com\/avatar\/b351def598609cb4c0b5bca26497c7e5?s=96&d=mm&r=g","caption":"owygs156"}}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7h1IJ-sL","jetpack-related-posts":[{"id":1754,"url":"http:\/\/intelligentonlinetools.com\/blog\/2018\/02\/27\/time-series-prediction-lstm-keras\/","url_meta":{"origin":1783,"position":0},"title":"Time Series Prediction with LSTM and Keras for Multiple Steps Ahead","date":"February 27, 2018","format":false,"excerpt":"In this post I will share experiment with Time Series Prediction with LSTM and Keras. LSTM neural network is used in this experiment for multiple steps ahead for stock prices data. The experiment is based on the paper [1]. The authors of the paper examine independent value prediction approach. With\u2026","rel":"","context":"In &quot;Machine Learning&quot;","img":{"alt_text":"Multiple step prediction with separate neural networks","src":"https:\/\/i0.wp.com\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/02\/multiple-step-prediction.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1798,"url":"http:\/\/intelligentonlinetools.com\/blog\/2018\/01\/20\/machine-learning-stock-prediction-lstm-keras-python-source-code\/","url_meta":{"origin":1783,"position":1},"title":"Machine Learning Stock Prediction with LSTM and Keras &#8211; Python Source Code","date":"January 20, 2018","format":false,"excerpt":"Python Source Code for Machine Learning Stock Prediction with LSTM and Keras - Python Source Code with LSTM and Keras Below is the code for machine learning stock prediction with LSTM neural network. References 1. Machine Learning Stock Prediction with LSTM and Keras - Python Source Code with LSTM and\u2026","rel":"","context":"In &quot;Machine Learning&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1974,"url":"http:\/\/intelligentonlinetools.com\/blog\/2018\/04\/03\/machine-learning-stock-market-prediction-lstm-keras\/","url_meta":{"origin":1783,"position":2},"title":"Machine Learning Stock Market Prediction with LSTM Keras","date":"April 3, 2018","format":false,"excerpt":"In the previous posts [1,2] I created script for machine learning stock market price on next day prediction. But it was pointed by readers that in stock market prediction, it is more important to know the trend: will the stock go up or down. So I updated the script to\u2026","rel":"","context":"In &quot;Machine Learning&quot;","img":{"alt_text":"Stock Data Prices Prediction with LSTM","src":"https:\/\/i0.wp.com\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/04\/timeseries_differenced_and_inverted_back.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1995,"url":"http:\/\/intelligentonlinetools.com\/blog\/2018\/04\/17\/lstm-neural-network-training-techniques-tuning-hyperparameters\/","url_meta":{"origin":1783,"position":3},"title":"LSTM Neural Network Training &#8211; Few Useful Techniques for Tuning Hyperparameters and Saving Time","date":"April 17, 2018","format":false,"excerpt":"Neural networks are among the most widely used machine learning techniques.[1] But neural network training and tuning multiple hyper-parameters takes time. I was recently building LSTM neural network for prediction for this post Machine Learning Stock Market Prediction with LSTM Keras and I learned some tricks that can save time.\u2026","rel":"","context":"In &quot;Machine Learning&quot;","img":{"alt_text":"LSTM NN Training Value Loss Charts with High Number and Adjusted","src":"https:\/\/i0.wp.com\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/04\/LSTM-NN-Training-Value-Loss-with-High-Number-and-adjusted-e1524097124417.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1178,"url":"http:\/\/intelligentonlinetools.com\/blog\/2017\/05\/14\/time-series-prediction-with-convolutional-neural-networks\/","url_meta":{"origin":1783,"position":4},"title":"Forecasting Time Series Data with Convolutional Neural Networks","date":"May 14, 2017","format":false,"excerpt":"Convolutional neural networks(CNN) is increasingly important concept in computer science and finds more and more applications in different fields. Many posts on the web are about applying convolutional neural networks for image classification as CNN is very useful type of neural networks for image classification. But convolutional neural networks can\u2026","rel":"","context":"In &quot;Artificial Intelligence&quot;","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2017\/05\/time-series-LSTM-300x164.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1628,"url":"http:\/\/intelligentonlinetools.com\/blog\/2017\/12\/17\/time-series-analysis-python-prophet\/","url_meta":{"origin":1783,"position":5},"title":"Time Series Analysis with Python and Prophet","date":"December 17, 2017","format":false,"excerpt":"Recently Facebook released Prophet - open source software tool for forecasting time series data. Facebook team have implemented in Prophet two trend models that can cover many applications: a saturating growth model, and a piecewise linear model. [4] With growth model Prophet can be used for prediction growth\/decay - for\u2026","rel":"","context":"In &quot;Machine Learning&quot;","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2017\/12\/time-series-analysis-python-300x180.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/posts\/1783"}],"collection":[{"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/comments?post=1783"}],"version-history":[{"count":24,"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/posts\/1783\/revisions"}],"predecessor-version":[{"id":1959,"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/posts\/1783\/revisions\/1959"}],"wp:attachment":[{"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/media?parent=1783"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/categories?post=1783"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/tags?post=1783"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}