Microsoft Stock Price Prediction with Machine Learning

Microsoft is today one of the largest technology companies with more than 163,000 employees worldwide. It is known for the Windows operating system which is one of the most popular computer operating systems. If you want to learn how to predict the future stock prices of Microsoft, this article is for you. In this article, I will walk you through the task of Microsoft stock price Prediction with machine learning using Python.

Microsoft Stock Price Prediction

Windows 10 is one of the operating systems that so many people love about Microsoft. When Microsoft released Windows 10, it was announced that it would be the last version of windows and then Microsoft will only work on its updates. But now Microsoft has once again garnered a lot of attention from the world as the release of Windows 11 is just around the corner. So now will be a good time to predict Microsoft’s stock price as it is getting a lot of attention.

In the section below, I will take you through the task of Microsoft stock price prediction with Machine Learning by using the Python programming language.

Microsoft Stock Price Prediction using Python

To get started with the task of forecasting the Microsoft stock prices, you first need to have a dataset. So, to get a dataset for this task, just follow the steps mentioned below:

  1. Visit Yahoo Finance
  2. Search for “MSFT”
  3. Click on “Historical Data”
  4. Click on “Download”

After completing the steps mentioned above you will find a dataset about the historical stock prices of Microsoft in your downloads folder. Now let’s get started with the task of predicting the stock prices of Microsoft by importing the necessary Python libraries and the dataset:

         Date        Open        High         Low       Close   Adj Close    Volume
0  2020-06-22  195.789993  200.759995  195.229996  200.570007  198.646606  32818900
1  2020-06-23  202.089996  203.949997  201.429993  201.910004  199.973740  30917400
2  2020-06-24  201.600006  203.250000  196.559998  197.839996  195.942780  36740600
3  2020-06-25  197.800003  200.610001  195.470001  200.339996  198.418793  27803900
4  2020-06-26  199.729996  199.889999  194.880005  196.330002  194.447235  54675800

In this dataset, the Close column contains the values whose future values we want to predict. So let’s have a closer look at the historical close prices of Microsoft’s stock price:

Microsoft Stock Price Prediction
Historical Stock Prices of Microsoft (Close)

Now let’s have a look at the correlation between the features of this dataset:

               Open      High       Low     Close  Adj Close    Volume
Open       1.000000  0.994944  0.993882  0.987180   0.987345 -0.268401
High       0.994944  1.000000  0.994191  0.993900   0.993907 -0.242671
Low        0.993882  0.994191  1.000000  0.995327   0.995499 -0.309895
Close      0.987180  0.993900  0.995327  1.000000   0.999823 -0.286731
Adj Close  0.987345  0.993907  0.995499  0.999823   1.000000 -0.288618
Volume    -0.268401 -0.242671 -0.309895 -0.286731  -0.288618  1.000000
Correlation between the features

Now I’ll prepare the data to fit into the machine learning model. In this step, I will first add the most important features to x and the target column to y, and then I will divide the dataset into training and test sets:

Now let’s use the Decision Tree Regression Algorithm to train the Microsoft Stock Price prediction model and have a look at the predicted stock prices for the next 5 days:

   Predicted Rate
0      243.119995
1      201.300003
2      243.080002
3      209.190002
4      216.339996

Summary

So this is how you can predict the stock prices of Microsoft with Machine Learning by using the Python programming language. Microsoft has once again garnered a lot of attention from the world as the release of Windows 11 is just around the corner. So this will be a good time to predict Microsoft’s stock price as it is getting a lot of attention. I hope you liked this article on the task of Microsoft Stock Price Prediction with Machine Learning using Python. Feel free to ask your valuable questions in the comments section below.

Default image
Aman Kharwal
Coder with the ♥️ of a Writer || Data Scientist | Solopreneur | Founder
Articles: 1054

2 Comments

  1. Hi Aman, I was able to run the MSFT exercise, it was great experience, just a quick question. Is there a link to look for the explanation of each library, just to understand better the code. Warm regards

Leave a Reply