Microsoft Stock Price Prediction with Machine Learning

In this project, I have used a machine-learning algorithm to predict the stock price of one of the largest tech companies named Microsoft using Python.

Dataset Link: MSFT.csv

Step-1: Import necessary libraries and data exploration on given data.

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

data = pd.read_csv("MSFT.csv")

Microsoft Stock Price Prediction with Machine Learning

Step-2: Data Visualization

plt.figure(figsize=(10, 4))
plt.title("Microsoft Stock Prices")

Data Visualization

Step-3: Finding Co-relation between data


Finding Co-relation between data

Finding Co-relation between data

Step-4: Splitting Data into train and test data

x = data[["Open", "High", "Low"]]
y = data["Close"]
x = x.to_numpy()
y = y.to_numpy()
y = y.reshape(-1, 1)

from sklearn.model_selection import train_test_split
xtrain, xtest, ytrain, ytest = train_test_split(x, y, test_size=0.2, random_state=42)

Step-5: Applying machine learning model

from sklearn.tree import DecisionTreeRegressor
model = DecisionTreeRegressor(), ytrain)
ypred = model.predict(xtest)
data = pd.DataFrame(data={"Predicted Rate": ypred})

Splitting Data into train and test data

Leave a Reply

Your email address will not be published. Required fields are marked *