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:
- Visit Yahoo Finance
- Search for “MSFT”
- Click on “Historical Data”
- 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:

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

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.
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
If you get problems to understand the functions on a library then just search for its documentation on Google. It will help you✌️
Hi Aman,
I am somehow unable to download the dataset from Yahoo, can you please attach the file by editing the article or replying to this comment? Thank you.
click on this link to download: https://query1.finance.yahoo.com/v7/finance/download/MSFT?period1=1596613514&period2=1628149514&interval=1d&events=history&includeAdjustedClose=true
Great learning
Helping for my project
good work
thanks, keep visiting
This Article was really helpful, but is there a way to turn a regression problem to a classification problem to be able to do a confusion matrix and the F-1 SCORE.
I am doing a stock market prediction for MSFT and I was told that i can have another categorical variable based on regression value.
For example, is it in range of low, medium, or high?
Then, it becomes the classification problem too and classification models can be used.
How can i do that, really confused.
You can use a dataset for any kind of problem, it maybe classification, regression, or clustering, you just need to prepare your data for that problem.