How to Predict Stock Prices with a Multilayer Perceptron (MLP) Neural Network

Predicting stock prices is one of the simple applications of AI in finance. Here I'm using Keras, which is a high-level deep learning API in TensorFlow.

I have attempted to predict the future stock price of Padini, a fashion company in Malaysia, and the following graph shows the results of my prediction:


It's tiring to train an AI, since you need to test the model with different parameters and settings. I have spent a few hours to adjust the model and find its best settings. It really requires a good intuition. But when you done it, you will feel excited!

Disclaimer: This AI model's prediction results are not completely accurate, please do not invest according to the prediction results, otherwise you would lose money and I will not be responsible.

Here I will explain the mathematical algorithms behind the MLP Model and provide the Python code in Jupyter to train the AI.


Model Updated:

The number of neurons in the input layer is reduced to 150. Also, the number of hidden layers is reduced to 18 and the number of neurons in the hidden layers is reduced to 180.


The training result is



The prediction result is


By executing the code below in Jupyter, you can find the minimum stock price and when does it happen.


The total number of parameters in the new model is less than the total number of parameters in the old model. However, the model error is further minimized. This shows that in MLP models, a larger neural network does not mean better training results.

Comments

Popular posts from this blog

AI Explained: The Most Common Questions and Answers for Newbies

The Role of Mathematics in Artificial Intelligence