0% found this document useful (0 votes)
12 views33 pages

Stock Price Prediction Report

Uploaded by

Anurag Karmakar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views33 pages

Stock Price Prediction Report

Uploaded by

Anurag Karmakar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PCS110 – Data Science Foundations Lab

REPORT – STOCK PRICE PREDICTION

End-Semester Evaluation

Submitted by:

(8024320023) – Ayush Susheel

(8024320018) – Anurag Karmakar

(8024320006) – Abhinav Kumar

(8024320021) – Atul Garg

ME(CSE) First Year Course Work

Submitted to:

“Divisha Garg”

Doctoral Researcher

Computer Science and Engineering Department

TIET, Patiala

November, 2024
PCS110 – Data Science Foundations Lab

In the project majorly 4 Steps has to be followed in a sequence

• Data Visualization
• Data Pre-Processing
• Model Implementation
• Model Evaluation

So hereby,
This report consists of the 1st two steps as mentioned below :-

Step1) Data Visualization


• The very 1st step is to import the necessary libraries.

• Here we have used the matplotlib, seaborn and plotly libraries for data

visualization.
PCS110 – Data Science Foundations Lab

• Understanding the Dataset

• We have considered “Google Stock Price” dataset from the years

30th August,2019 - 30th August,2024.

• In the dataset we have features like “Date”, Opening Price as “Open”, Closing

Price as “Close” , Highest Price on the specific date as “High” , Lowest Price on

the specific date as “Low” , Adjusted Closing Price after all the dividend and split

factor as “Adj Close” and the amount of stock bought on specific date as

“Volume”.

• Now after understanding the dataset it’s time to visualize the numeric data so that
it can understood more clearly and precisely.
PCS110 – Data Science Foundations Lab

• This we did using the matplotlib library (plotted in graph,histogram) form.


• We also used the Plotly library which helps in visualizing data more clearly.

• Visualizing Data for the Feature “OPEN” in a Graph

• Visualizing Data for the Feature “OPEN” in Histogram Form


PCS110 – Data Science Foundations Lab

• Visualizing Data for the Feature “OPEN” using Plotly

• Visualizing Data for the Feature “LOW” using Plotly


PCS110 – Data Science Foundations Lab

• Visualizing Data for the Feature “VOLUME” using Plotly


PCS110 – Data Science Foundations Lab

• Like these the visualizations are performed for all the features mentioned below :-

• Open

• High

• Low

• Close

• AdjClose

• Volume

Now after visualization comes the second step,

Step2) Data Preprocessing


• In Data preprocssing various steps are involved which are very important to

perform because this data is going to be used further in the model implementation.

• These Steps are :-

✓ Handle the missing values

✓ Data Transformation

✓ Data Normalization

✓ Outlier Removal

✓ Feature Selection

• In our Project we have used Data Normalization, Outlier Removal method

because we found the no missing values were present in the dataset, there is no
PCS110 – Data Science Foundations Lab

need to transform the data as our data is already in numeric form if it was in

categorical form then we need to use transformation.

• Data Normalization

✓ We found that the 2 features “Adj Close” and “Close” have similar values
therefore we are dropping the feature as we should not provide the duplicate
value to the model

✓ As we are going to predict the “CLOSE” feature values therefore we are


scaling it in the range 0-1 using the MinMaxScaler.

• Removing the duplicate values :-

✓ Using the drop function we are dropping the feature “Adj Close”

✓ Also providing the axis value as 1 means dropping the column value and if
we provide 0 it means drop the row value.
PCS110 – Data Science Foundations Lab

• Scale down the values (MinMaxScaler):-

✓ 1st we are creating a new dataframe which consists only “CLOSE” column
values.

✓ Then converting it into a numpy array.


PCS110 – Data Science Foundations Lab

✓ Using the MinMaxScaler we are scaling down the values in the range 0 - 1
PCS110 – Data Science Foundations Lab

• Removing the Outliers from the Dataset

✓ 1st finding the outliers by visualizing the values of all features


PCS110 – Data Science Foundations Lab

✓ We found that the data is not normally distributed in the feature “VOLUME”

(1)

(2) Using Plotly and Seaborn visualizing the feature “VOLUME”


PCS110 – Data Science Foundations Lab

(3) Using Box Plot to visualize the outliers

✓ After finding the outliers remove them from the dataset using the quantile method
PCS110 – Data Science Foundations Lab

✓ After successfully removing the outliers we are visualizing the dataset to make sure the
outliers are removed perfectly.

✓ Successfully removed the outliers.


PCS110 – Data Science Foundations Lab

Step 3) Model Implementation


• Now, as we started with the implementation part 1st we calculate the moving average for 250
days, 100 days and will compare both of them via graph (as this concept helps us to see the
stock closing price will go down or up)

Here, google_data is our data frame via which we are selecting the Close Feature
PCS110 – Data Science Foundations Lab

• Plotting the Graph for Moving Average of 250 days

• Comparing Moving average for 250 days with Original Stock


closing price
PCS110 – Data Science Foundations Lab

• Calculating Moving Avg for 100 days and Comparing it with


Original Stock closing price

• Comparing both MA’s


PCS110 – Data Science Foundations Lab

• Now, creating our x and y data via which we will calculate the
values of our Moving Average
PCS110 – Data Science Foundations Lab

• Now comes the train and test split part where we used 70% of data
for training and 30% of data for testing
PCS110 – Data Science Foundations Lab

• We used Sequential Model and “LSTM” (Long Short- Term


Memory) layers in order to find the predicted values.

Here in the LSTM model,

• We added 2 LSTM layers and 2 Dense layers with the neurons as mentioned above.
As it is used to control the output shape of the LSTM layer and whether it returns the entire
sequence of outputs or just the last output

• When this parameter is set to True, the LSTM layer will return the full sequence of outputs
at each time step for each input in the sequence.
PCS110 – Data Science Foundations Lab

• When this parameter is set to False, the LSTM layer only returns the output at the final time
step of the sequence.

• Here is the model summary

• Layer Type basically tells the type

• Output Shape tells that how the data transforms when it passes during the network

• And Param means the no. of parameters trained in each layer


PCS110 – Data Science Foundations Lab

• Predicting the Values using predict() method and passing x_test as


a parameter to it.

• After predicting the values we are now doing inverse transform so that it comes to its
proper decimal values as all the data before inverse transform is in range 0-1.
PCS110 – Data Science Foundations Lab

• Also doing the inverse transform in the y test data


PCS110 – Data Science Foundations Lab

Step 4) Model Evaluation

• Now Calculating the Evaluation Metrics one by one as :-

• MAE = 2.08

• MSE = 7.5

• RMSE = 2.75

• MAPE = 1.37

• R2 = 0.97
PCS110 – Data Science Foundations Lab

• Comparing the original values along with the predicted values


PCS110 – Data Science Foundations Lab

• Plotting the graph of Actual vs Predicted Values


PCS110 – Data Science Foundations Lab

• Predicting the next 30 days values

• Now for predicting the next 30 days values we are using the y_test values
PCS110 – Data Science Foundations Lab

• Here basically we are reshaping the data again and again when we are adding the
predicted values in the final output list, we are starting with 1 index ahead each time
therefore we are taking values from [1 : ] till end.

• The previous values are being given as an input and the new value as output is then
added each time to the output list.
PCS110 – Data Science Foundations Lab

• Inverse Transforming the values as they are in the range 0 – 1


PCS110 – Data Science Foundations Lab

• As the last value of our dataset was 4th November 2024, so after that date we will predict
the values

• We can either use this method also in which we are passing the last 60 days values in
order to predict next 30 days values.
PCS110 – Data Science Foundations Lab

• These are the next 30 days predicted values


PCS110 – Data Science Foundations Lab

• From the datetime library we are now setting the date values along with their predicted
prices.
PCS110 – Data Science Foundations Lab

• After predicting the value’s we are then plotting a graph to visualize the data more
clearly.

You might also like