Skip to content

poojithaganta/LinearRegressionFromScratch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Salary Prediction using Linear Regression from Scratch

This project demonstrates how to implement Linear Regression manually using Python and deploy it as an interactive web app using Streamlit.

The model predicts a person's salary based on their years of experience.

Objective

Build a salary prediction model from scratch using gradient descent and deploy it using Streamlit to make real-time predictions based on user input.

Project Structure

  • LinearRegressionFromScratch.ipynb # Jupyter notebook for training the model
  • app.py # Streamlit app for interactive predictions
  • Salary_Data.csv # Dataset
  • README.md # Project documentation

Dataset

The dataset includes:

  • YearsExperience: Number of years in the workforce
  • Salary: Annual salary in USD

It's a dataset used to illustrate linear regression.

Implementation Details

Linear Regression Model (from scratch)

  • Equation used: y = m * x + b
  • Parameters m (slope) and b (intercept) are learned using Gradient Descent
  • Mean Squared Error (MSE) is used as the loss function
  • Outputs a trained model with optimized weights

Streamlit Web App

  • Users enter Years of Experience
  • Model predicts and displays the Estimated Salary
  • Uses the trained values of m and b directly

How to Run

Option A: Run Locally

  1. Install dependencies:

    pip install streamlit numpy pandas matplotlib
  2. Start the app:

    streamlit run app.py

Option B: Run in Google Colab with Ngrok

  1. Install packages:

    !pip install streamlit pyngrok
  2. Run and expose Streamlit app:

    from pyngrok import ngrok
    
    # Kill existing sessions
    !pkill streamlit
    
    # Start app
    get_ipython().system_raw('streamlit run app.py &')
    
    # Create public URL
    public_url = ngrok.connect("http://localhost:8501")
    public_url

Click the Predict Salaries to access your deployed app online.

Screenshot 2025-07-25 at 2 17 51 AM

Example Predictions

Years of Experience Predicted Salary
1.5 $39,967.14
5.0 $73,041.00
7.3 $95,868.00

Possible Extensions

  • Display evaluation metrics (RMSE, R²)
  • Support multiple predictions from a CSV

Requirements

streamlit
numpy
pandas
matplotlib
pyngrok

Install with:

pip install -r requirements.txt

Made with ❤️ by Poojitha Ganta

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published