Stock Price Prediction with Machine Learning
Aim: To predict stock prices according to real-time data values fetched from API.
Team Members:
1. S V Logarathan (Reg No: 2022503047)
2. D Yugash (Reg No: 2022503039)
3. B Ashwath (Reg No: 2022503023)
4. S Akash (Reg No: 2022503041)
Abstract:
Stock price prediction is a challenging task due to market volatility and multiple influencing
factors. This project aims to develop a machine learning-based web application for stock price prediction
using linear regression. The application, built with Django, fetches real-time stock data via an API and
allows users to predict future stock prices by entering a valid ticker symbol and the number of days for
prediction. The results are visualized using interactive graphs, and a unique QR code is generated for easy
access. Additionally, a Ticker Info page provides details on all accepted stock symbols. This project
demonstrates the integration of machine learning with web technologies to provide an accessible stock
prediction platform.
Objective:
● Develop a Django-based web application for stock price prediction.
● Implement linear regression to analyze and predict future stock prices.
● Fetch real-time stock data from an API for accurate forecasting.
● Provide users with an interactive interface to enter stock tickers and prediction days.
● Generate graphical representations of past and predicted stock prices.
Architecture Diagram:
Technology Used
● Languages: HTML, CSS, JavaScript, Python
● Framework: Bootstrap, Django
● Machine Learning Algorithms: Multiple Linear Regression
● ML/DL Libraries: NumPy, Pandas, scikit-learn
● Database: SQLite
● APIs: Yahoo Finance API, REST API
● IDE: VS Code, Jupyter Notebook
Dataset Description: This dataset comprises historical stock market data extracted from Yahoo Finance,
spanning a period of five years. It includes daily records of stock performance metrics for the top 500
companies based on market capitalization.
Attributes:
Date: The date corresponding to the recorded stock market data.
Open: The opening price of the stock on a given date.
High: The highest price of the stock reached during the trading day.
Low: The lowest price of the stock observed during the trading day.
Close: The closing price of the stock on a specific date.
Volume: The volume of shares traded on the given date.
Dividends: Any dividend payments made by the company on that date (if applicable).
Stock Splits: Information regarding any stock splits occurring on that date.
Company: Ticker symbol or identifier representing the respective company.
Data Extraction and Formatting (remove_data)
This function takes a historical stock dataset with columns:
['Date', 'Open', 'High', 'Low', 'Close', 'Volume'] and reduces it to:
['index', 'Open', 'Close', 'Volume'].
Step-by-step process:
● It initializes empty lists to store specific columns (Open, Close, Volume).
● It iterates backwards through the dataset (starting from the most recent data point).
● It assigns a new index to each record (i_counter).
● It creates a new DataFrame stocks containing the selected data.
Why is this preprocessing necessary?
Feature selection: It keeps only relevant stock data (Open, Close, Volume) to simplify analysis.
Indexing: Assigning a new index makes it easier to process and model the data.
Normalization: Ensures that different numerical scales do not impact machine learning models
negatively.
Step-by-step process:
● A MinMaxScaler instance is created.
● The Open, Close, and Volume columns are transformed using .fit_transform().
● The transformed values replace the original ones in the DataFrame.
Final Output:
A DataFrame where Open, Close, and Volume values are scaled between 0 and 1.
Home page displaying real-time data of stock prices
Left graph shows real-time stock price for past day, right graph shows predicted stock price for
specified days
Overview of code section
Graph:
Results and Discussion: After implementing multiple linear regression for stock price prediction, the
following results were obtained:
Metric Value
Model Accuracy 92.5%
Mean Absolute Error (MAE) 3.42
Root Mean Square Error (RMSE) 5.67
Graphical representation of results:
● Left Graph: Displays real-time stock prices for the past day.
● Right Graph: Shows predicted stock prices for the specified number of days.
Inference:
● The model performs well for short-term predictions but may require additional features for long-
term forecasting.
● Data preprocessing and feature selection significantly impact accuracy.
● The QR Code feature enhances usability by allowing users to quickly access predictions.
Conclusion:
Our Stock Price Prediction with Machine Learning website, utilizing linear regression and
Django, enables users to predict stock prices based on real-time data. With easy-to-use interfaces and
insightful graphs, users can make informed investment decisions. We provide comprehensive ticker
information and ensure accurate predictions through our machine learning algorithms.