Stock Market Predictor


Background: Python project with the purpose of familiarizing myself with machine learning, specifically the Keras and Sklearn packages. This project used publicly available historical data supplied from Nasdaq with the purpose of predicting the next day/week/month closing prices of a given stock. The model was trained under the assumption that previous opening/closing prices and historical trends were the only context that mattered.

Notes: Because of the over-simplification of factors (i.e. that closing price is solely based on previous prices/trends), success was measured by the models ability to predict positive or negative changes in a stock’s closing price, though it occasionally predicted a stock within $0.1 which is exciting. Here are some snippets from the project:

Figure 1: Models in training. The goal was to minimize loss without overtraining, which was difficult with so much data. I played around with weights and number of epochs, as well as determined the decay factor (the amount to decrease the impact of a price based on date. In other words, the older the datapoint, the less impact it should have on tomorrow’s price).

Figure 2: Output

Output from the training in Figure 1. Note the sign of the error indicates whether or not the model’s predicted closing price was above (positive) or below (negative) the actual value, and it does not actually mean good or bad. Not pictured – multiple models were trained to predict based on different timestamps (tomorrow/next week/next month).

Takeaway: The main takeaway from this project was successful. I gained experience with the Keras and sci-kitlearn modules and sharpened my Python skills. I also gained experience training a machine learning model and testing parameters to improve the model. Looking back at the project, I definitely see signs of overtraining, which is likely caused by my desire to get accurate results for closing prices with such a naive model. I look forward to revisiting this project.