Skip to content

A FastAPI-based machine learning project that predicts vehicle fuel consumption using a regression model trained on the Kaggle FuelConsumption dataset. It covers data processing, model training, and API deployment for real-time predictions.

Notifications You must be signed in to change notification settings

sameer-at-git/Fuel-Consumption-Prediction-API-using-Linear-Regression-and-FastAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fuel Consumption Prediction API

A FastAPI-based Machine Learning project that predicts vehicle fuel consumption using a regression model trained on the FuelConsumption dataset.

This project demonstrates the full pipeline — data preprocessing, model training, serialization with Joblib, and API deployment using FastAPI.


Project Overview

This API allows users to input numeric vehicle parameters (like engine size, cylinders, or CO2 emissions) and get predicted fuel consumption values instantly.

FastAPI Docs View

docs

Example Prediction

result


Tech Stack

  • FastAPI – Backend framework
  • Scikit-learn – Model training
  • Joblib – Model serialization
  • Pydantic – Data validation
  • Uvicorn – ASGI server for deployment

Project Structure

├── api.py             # FastAPI app
├── model/
│   └── model.pkl          # Trained model
├── notebook.ipynb
├── data/
│   └── FuelConsumption.csv
├── requirements.txt
└── README.md

API Endpoints

POST /predict/

Request Body

{
  "feature1": 5.3,
  "feature2": 120.5
}

Response

{
  "prediction": 7.84
}

How to Run Locally

1️⃣ Clone the repo

git clone https://github.com/sameer-at-git/Fuel-Consumption-Prediction-API-using-Linear-Regression-and-FastAPI.git
cd Fuel-Consumption-Prediction-API-using-Linear-Regression-and-FastAPI

2️⃣ Create a virtual environment

python -m venv venv
source venv/bin/activate     # (Linux/Mac)
venv\Scripts\activate        # (Windows)

3️⃣ Install dependencies

pip install -r requirements.txt

4️⃣ Run the FastAPI app

uvicorn app.api:app --reload

Access the docs:
👉 http://127.0.0.1:8000/docs


Model Training (Notebook)

The notebook notebook.ipynb covers:

  • Dataset exploration
  • Feature engineering
  • Model training & evaluation
  • Saving model using Joblib

Deployment Ideas


Author

Md. Sameer Sayed
📧 mdsameersayed0@gmail.com
🌐 GitHub


License

This project is released under the MIT License.

About

A FastAPI-based machine learning project that predicts vehicle fuel consumption using a regression model trained on the Kaggle FuelConsumption dataset. It covers data processing, model training, and API deployment for real-time predictions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published