GitHunt
AB

abdulrahimzulfiqar/Stock-Price-Prediction-Using-Scikit-Learn-Linear-Regression

This project predicts the next day's stock closing price using Lag Features + Linear Regression (with scikit-learn). Built with public financial data from Yahoo Finance and visualized with cost convergence and prediction analysis.

πŸ“ˆ Stock Price Prediction Using Scikit-Learn Linear Regression

This project demonstrates how to predict the next day's stock closing price using supervised learning with Linear Regression from scikit-learn. We use public stock data from Yahoo Finance, engineer lag-based features, and evaluate the model's performance with error metrics and visualizations.


🧠 Overview

  • βœ… Downloaded historical stock data (Apple Inc.) using yfinance
  • βœ… Created lag features from past 5 days to use as inputs
  • βœ… Applied feature scaling using StandardScaler
  • βœ… Trained a Linear Regression model using sklearn
  • βœ… Evaluated the model using MSE and RΒ²
  • βœ… Visualized actual vs predicted prices
  • βœ… Built entirely in Google Colab using free tools

πŸ—‚οΈ Project Structure

File Description
stock_prediction_sklearn.ipynb Full notebook with training, evaluation, and plots
README.md Project documentation (this file)
images/ Screenshot 2025-06-21 at 3 40 43β€―pm

πŸ“Š Data Source

  • Ticker: AAPL (Apple Inc.)
  • Timeframe: Jan 2020 to Jan 2024
  • Source: Yahoo Finance

βš™οΈ Technologies Used

  • Python
  • Google Colab
  • Pandas, NumPy
  • Matplotlib
  • scikit-learn
  • yfinance

πŸ“‰ Model Details

  • Input features: Closing prices of the last 5 days
  • Target: Next day's closing price
  • Model: sklearn.linear_model.LinearRegression
  • Metrics:
    • Mean Squared Error (MSE)
    • RΒ² Score

πŸ“ˆ Results

  • Prediction error is relatively low, and the model captures general trends.
  • Perfect accuracy is not expected as stock markets are affected by external, unmodeled factors.

πŸ–ΌοΈ Visualizations

Screenshot 2025-06-21 at 3 40 43β€―pm
abdulrahimzulfiqar/Stock-Price-Prediction-Using-Scikit-Learn-Linear-Regression | GitHunt