Stock Market prediction using LSTM

Data Science Projects


About the project


Investment is the key/main source of income for majority of population around the world. Data shows almost 56% of U.S. population invests in stock market and out of this a large number of people have investments in shares and mutual funds. Prediction of stock trend has long been an intriguing topic and is extensively studied by researchers from different fields. Simple statistical analysis of financial data provides some insights but, in recent years, investment companies have increasingly used various forms of artificial intelligence (AI) systems to look for patterns in massive amounts of real time equity and economic data. There are many existing models which use methods like LSTM, EMA, SMA and all but all models have credibility with their accuracy level. One of the important factor and variable that affect the stock market is sentiments and various efforts have been done to break the boundaries by incorporating external information through fresh financial news or personal internet posts such as Twitter. These approaches, known as sentiment analysis, replies on the attitudes of several key figures or successful analysts in the markets to interpolate the minds of general investors. Here in this investment decision is made using machine learning LSTM technique which is very famous and trusted technique for predicting stock market for company BMW. Patterns of daily change is being analysed and then LSTM is performed for almost 10,000 samples for a year that 252 working market days. And main objective was to try to reduce the error in current LSTM models and find lowest percentile just being on safer side to analyse what could be the loss in worst possible situation. Also what percentage of investment should be invested and what can be the expected return.

SKILLS: Machine Learning, Python (Keras, Sklearn, Numpy, Pandas, Matplotlib)


This machine learning project focused on predicting the stock market prices for any given stock, using the long short term memory method from Keras library. Than the root mean squared error (RMSE) was calculated to check for the accuracy of the model. The project started of with gathering the data, and doing some data wrangling to prepare the data for the model, followed by building the model using LSTM from Keras library.


As we performed and designed our whole model using LSTM technique it seems this is a very accurate technique for prediction of stockmarket analysis, and we use root mean square error method to calculate the error which is also called as RMSE score. Here the analysis is done on the BMW stock. After analyzing it seems that the length of the dataset also plays an important role in the accuracy of the model. On analyzing the basic trends, there was a bit of a change in the closing price over the period.

Statistical results were as follows, we got RMSE score of 1.72, lower the RMSE score more accurate the model and it can’t be negative as we are using mean square method and RMSE score of 0 means the model is perfect. As for the BMW dataset our score was 1.72 which implies 90% accuracy of the model. Here almost 20% of the dataset is used for validation with the actual market value. Taking a random date of 29th April and comparing price it was found the actual price was $78.51 and our predicted price was $77.85 which is close with much less error margin.

link to the project code:

Project File