top of page

Stock Market Prediction using LSTM

📈 Predicting Tesla’s Stock Price: A Machine Learning and Deep Learning Approach

Tesla Inc., the electric vehicle and renewable energy giant, continues to dominate headlines not just for its cutting-edge tech, but also for its dynamic stock market performance. For investors and analysts alike, predicting Tesla’s stock trends is both a challenge and an opportunity.

In this project, we combined data analysis, feature engineering, and predictive modeling to forecast Tesla's stock price movements using both traditional machine learning models and advanced deep learning architectures like LSTM (Long Short- Term Memory) networks.

🔍 Objective

The goal was to:

  • Clean and analyze Tesla's historical stock market data

  • Extract meaningful insights through exploratory data analysis (EDA)

  • Engineer features to enhance model performance

  • Train and evaluate different models for stock price prediction

  • Compare traditional ML techniques with deep learning models for forecasting


🧾 Tesla Dataset Overview

Our dataset included:

  • Date

  • Open, High, Low, Close prices

  • Volume (number of shares traded)

  • Adjusted Close (reflecting dividends, splits, etc.)

We added a 'Month' column to observe monthly trends.


❓ Research Questions

  1. How well do machine learning methods forecast stock prices?

  2. How can time-series analysis be used to predict future stock prices?

  3. Are non-linear models better than linear regression for this task?

  4. What patterns exist between open/close prices and other market variables?


📊 Data Analysis & Visualization

Exploratory Insights

  • No null values or missing data

  • No outliers disrupting trends

  • Dataset was fully numeric, suitable for modeling


Visualizations

  • Line charts to show trends in Open, High, Low, Close, and Volume over time

  • Heatmap to show correlation between features

  • Bar and line plots for monthly and yearly averages

  • AUC-ROC plots to compare model performance

  • An interactive dashboard was built to help users explore stock trends in real-time


🤖 Models Applied

We trained and tested the following models:

  1. Logistic Regression

  2. Support Vector Classifier (SVC)

  3. XGBoost Classifier

  4. LSTM (Long Short-Term Memory) – for time-series forecasting


📌 Key Observations

  • XGBoost showed overfitting — high training accuracy but lower test performance.

  • Logistic Regression and Linear Regression produced RMSE values of 53.57 and 77.2 respectively.

  • LSTM outperformed all with the lowest RMSE values and better generalization, making it the best model for stock trend prediction.


🧠 Why LSTM?

LSTM networks are designed for sequential data, making them perfect for stock trend forecasting. They:

  • Capture long-term dependencies

  • Learn from historical price patterns

  • Efficiently handle non-linearities in financial data

We used 70% of the data for training and 30% for testing. Among the features, 'Low' price delivered the best results in terms of RMSE.


📉 RMSE Values of LSTM Model

Feature

Training RMSE

Testing RMSE

All Features

168.76

314.11

Open

5.75

11.69

Close

5.80

12.26

High

5.44

12.23

Low

5.29

11.01

🔹 The 'Low' feature had the smallest gap between training and testing RMSE values, making it the most stable and generalizable predictor.

📌 Final Verdict

LSTM emerged as the most efficient and reliable model, outperforming traditional models like Logistic Regression and XGBoost. It handled complex time-based relationships and delivered accurate stock trend forecasts.


📚 References

  1. Gandhmal, D.P., & Kumar, K. (2019). Systematic analysis and review of stock market prediction techniques. Computer Science Review, 34:100190.

  2. Li, Z., Yu, H., Xu, J., Liu, J., & Mo, Y. (2023). Stock market analysis and prediction using LSTM: A case study on technology stocks. Innovations in Applied Engineering and Technology.


🚀 Conclusion

Whether you’re a data enthusiast, financial analyst, or just curious about the power of machine learning in finance, this project shows how AI can offer deep insights into market behavior. With Tesla’s stock being highly volatile, using LSTM models opens up new possibilities for smarter investment strategies.

 
 
 

Comments


Feel free to reach out if you have any questions, project inquiries, or want to connect. I'm always open to discussing new projects, creative ideas, or opportunities to be part of your vision.

Connect With Me:

  • GitHub
  • LinkedIn

(906) 767-1906

bottom of page