<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Priti Gupta on Medium]]></title>
        <description><![CDATA[Stories by Priti Gupta on Medium]]></description>
        <link>https://medium.com/@priti.gup17?source=rss-c074d928b495------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*9RCQSv4bfNLpVdDA</url>
            <title>Stories by Priti Gupta on Medium</title>
            <link>https://medium.com/@priti.gup17?source=rss-c074d928b495------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 13:30:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@priti.gup17/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Stock Price Forecasting Concepts and Implementation using LSTM]]></title>
            <link>https://medium.com/@priti.gup17/stock-price-forecasting-concepts-and-implementation-using-lstm-d28d88890fea?source=rss-c074d928b495------2</link>
            <guid isPermaLink="false">https://medium.com/p/d28d88890fea</guid>
            <category><![CDATA[lstm]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[time-series-forecasting]]></category>
            <category><![CDATA[deep-neural-networks]]></category>
            <dc:creator><![CDATA[Priti Gupta]]></dc:creator>
            <pubDate>Tue, 19 Apr 2022 19:11:24 GMT</pubDate>
            <atom:updated>2022-04-19T19:29:28.095Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Stock market forecasting is the act of trying to determine the future value of a company stock. The successful prediction of a stock’s future price could yield significant profit. However, there are so many variables and market dynamics which influences the stock market and make it unpredictable.</p><p>As Artificial Intelligence is magically changing all domains and making sci-fi to reality. It is very interesting to see how a Deep Neural Network can find out the hidden trends and revel insights from past stock price data and make predictions.</p><h4>Disclaimer — Model developed below is for learning and understanding purpose only. Please do not use it for trading purpose.</h4><h3>LSTM</h3><p>Let’s understand what is LSTM. Long Short Term Memory networks are a special kind of RNN, capable of learning long-term dependencies. They were introduced by <a href="http://www.bioinf.jku.at/publications/older/2604.pdf">Hochreiter &amp; Schmidhuber (1997)</a>, and were refined and popularized by many researchers. They work tremendously well on a large variety of problems and are widely used.</p><p>LSTMs are explicitly designed to avoid the long-term dependency problem. Remembering information for long periods of time is practically their default behavior, not something they struggle to learn.</p><p>Please check link mentioned in reference section for in-depth intuition and understanding about LSTM.</p><h3>Data Collection</h3><p>Publicly available Apple stock price data from 18 Apr 2017 till 14 Apr 2022 at TIIGNO ( <a href="https://www.tiingo.com/">https://www.tiingo.com/</a>) are used for training and testing the model. Column close is used to train and forecast.</p><figure><img alt="Stock Price data sample" src="https://cdn-images-1.medium.com/max/1024/1*wH4m5nRkHSUgNuDGGjYlrA.png" /></figure><p>Below line graph depict the close column at y-axis and date at x-axis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*GHPjDFWUxbFKztGm0SS4NQ.png" /></figure><h3>Data Scaling</h3><p>Now let’s transform the raw dataset so that it can fed to LSTM based Deep Neural Network. LSTM is sensitive to scale of the data, so MinMaxScaler is used to scale data between 0 to 1.</p><p>Code :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*a70WWj6I_JdgQo3XWvumGQ.png" /></figure><h3>Train, Cross Validation and Test Split</h3><p>Here dataset is time-series data and it need to split on time axis. Here first 60% data will be used to train, next 20% data to do cross validation and last 20% data to test.</p><p>Code :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fTFuOc0ZyU7xxqiFnfoICQ.png" /></figure><h3>Data Preprocessing</h3><p>Now independent features and label need to create from close column of dataset. Remember that previous sequences of timestep length could be use as independent features and next element of sequence could be used as a label. For example, lets select length of timestep as 100. Now 100 elements of close data will consider as independent features and 101th elements of close column will consider as label while maintaining the order.</p><p>Code :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*otstrUlR6l13cUXhOebObw.png" /></figure><p>LSTM input layer must be 3D. These 3 input dimensions are samples, time-steps, and features. Now, let’s reshape X_train, X_cv and X_test datasets.</p><p>Code :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*rq7NlE9N21j0aHpA0Gaq2w.png" /></figure><h3>LSTM Model creation</h3><p>Below libraries required to create stacked LSTM model.</p><p>Code :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/1*_3o7ueRyzqTjsGJt0sa0bQ.png" /></figure><p>Now without further delay, lets create stacked LSTM model. First create a sequential model using tensorflow followed by LSTM layers with 50 neurons.</p><p>Code :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*5E_bdGKHvUV4vHFkgEGVbQ.png" /></figure><h3>Training and Predictions</h3><p>Now model it created and it is time to train the model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*WGYtVPnE9HBSAS0vTNTRVg.png" /></figure><p>Congratulations that you followed so well till now. Let’s test and see how well model is performing on unexposed test dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*9cLgkwiLFS2Frmz2-kScFw.png" /></figure><p>Mean Squared Error : 37.6984 Undoubtedly, it is impressive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*yOCG0jA9jXKOfubqSBa31Q.png" /></figure><p>Below plot demonstrate actual stock price in blue, predicted price in train set in orange, predicted price in cross-validation set in green and predicted price in test set in red.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*p_D-NeKzNHIFQKwVymCH-g.png" /></figure><p>Now it is time to predict for next 30 days Apple stock price.</p><p>Code :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/1*zhsx9g4hGfN_-fWvdkdA6w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*yVKMV1n65LoJmTI6Grbjmg.png" /></figure><p>Above highlighted area is the next 30 days prediction. I already said in the beginning of the blog that stock price of companies are highly influenced by multiple known and unknown factors. The purpose of the blog is to demonstrate how a state-of-the-art model can be created for forecasting.</p><h3>Conclusion</h3><p>In the blog, we have seen how a LSTM based model can be created and trained for stock price forecasting. Please check my github link given below for complete code.</p><p><a href="https://github.com/PritiGup/DataScience-Self-Projects/tree/master/Stock%20Market%20Forecasting%20using%20LSTM">https://github.com/PritiGup/DataScience-Self-Projects/tree/master/Stock%20Market%20Forecasting%20using%20LSTM</a></p><p>Thank you for your time. I hope you have learn something new.</p><p>Keep learning and help others to learn.</p><h3>Reference</h3><p><a href="https://colah.github.io/posts/2015-08-Understanding-LSTMs/">https://colah.github.io/posts/2015-08-Understanding-LSTMs/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d28d88890fea" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>