![]() |
VOOZH | about |
In this article, we will implement Microsoft Stock Price Prediction with a Machine Learning technique. We will use TensorFlow, an Open-Source Python Machine Learning Framework developed by Google. TensorFlow makes it easy to implement Time Series forecasting data. Since Stock Price Prediction is one of the Time Series Forecasting problems, we will build an end-to-end Microsoft Stock Price Prediction with a Machine learning technique.
Python libraries make it very easy for us to handle the data and perform typical and complex tasks with a single line of code.
Now let's load the dataset which contains the OHLC data about the Microsoft Stock for the tradable days. You can find the download link at the end of the article.
Output:
index date open high low close volume Name
0 390198 2013-02-08 27.35 27.71 27.31 27.55 33318306 MSFT
1 390199 2013-02-11 27.65 27.92 27.50 27.86 32247549 MSFT
2 390200 2013-02-12 27.88 28.00 27.75 27.88 35990829 MSFT
3 390201 2013-02-13 27.93 28.11 27.88 28.03 41715530 MSFT
4 390202 2013-02-14 27.92 28.06 27.87 28.04 32663174 MSFT
Output:
(1259, 8)Output:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1259 entries, 0 to 1258
Data columns (total 8 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 index 1259 non-null int64
1 date 1259 non-null object
2 open 1259 non-null float64
3 high 1259 non-null float64
4 low 1259 non-null float64
5 close 1259 non-null float64
6 volume 1259 non-null int64
7 Name 1259 non-null object
dtypes: float64(4), int64(2), object(2)
memory usage: 78.8+ KB
Output:
EDA is an approach to analyzing the data using visual techniques. It is used to discover trends, and patterns, or to check assumptions with the help of statistical summaries and graphical representations.
Output:
Output:
Output:
Now, let's just plot the Close prices of Microsoft Stock for the time period of 2013 to 2018 which is for a span of 5 years.
Output:
To tackle the Time Series or Stock Price Prediction problem statement, we build a Recurrent Neural Network model, that comes in very handy to memorize the previous state using cell state and memory state. Since RNNs are hard to train and prune to Vanishing Gradient, we use LSTM which is the RNN gated cell, LSTM reduces the problem of Vanishing gradients.
Output:
While compiling a model we provide these three essential parameters:
Output:
We got 0.0791 mean absolute error, which is close to the perfect error score.
Now as we have our model ready letβs evaluate its performance on the validation data using different metrics. For this purpose, we will first predict the class for the validation data using this model and then compare the output with the true labels.
Output:
2/2 [==============================] - 1s 300ms/stepNow let's plot the known data and the predicted price trends in the Microsoft Stock prices and see whether they align with the previous trends or totally different from them.
Output:
You can download the source code and dataset from here: