Skip to content

Jayraj-Dhaigude/EV-Range-Prediction

Repository files navigation

EV Range Predictor

A machine learning model that predicts the estimated driving range (in km) of an electric vehicle based on its technical specifications. Built with a Random Forest regressor and served via an interactive Streamlit UI.


Overview

Range anxiety is one of the biggest barriers to EV adoption. This project trains a regression model on a dataset of ~478 real-world EVs from the EV Database, covering 59 brands and a wide variety of vehicle segments, body types, and drivetrains. Given a vehicle's specs, the app instantly predicts its range and classifies it as short, mid, or long range.


Project Structure

├── ev_data.csv              
├── ev_range_predictor.ipynb   
├── random_forest_model.pkl    
├── columns.pkl               
├── target_encoder.pkl         
└── app.py                     

Notebook Walkthrough

1. Exploratory Data Analysis

  • Inspected feature distributions and value counts for categorical columns (brand, segment, body type, drivetrain)
  • Identified and handled missing values: number_of_cells filled with the column mean; remaining rows with nulls dropped
  • cargo_volume_l coerced to numeric, nulls filled with the median

2. Feature Engineering

  • Dropped: source_url, model, battery_type, fast_charge_port
  • One-hot encoding: car_body_type, segment, drivetrain
  • Target encoding: brand — encoded using category_encoders.TargetEncoder with smoothing=10 to avoid overfitting on rare brands

3. Modelling

Two regressors were trained and compared on an 80/20 split:

Model MAE (km)
Random Forest 11.90 0.9733
XGBoost 12.31 0.9750

Random Forest was selected as the final model and saved as random_forest_model.pkl.


Streamlit App

The app provides a form-based interface grouped into three sections:

Vehicle Identity

  • Brand (59 options), Body Type, Drivetrain, Segment

Battery & Performance

  • Battery Capacity (kWh), Fast Charging Power (kW DC), Top Speed, 0–100 km/h acceleration, Torque, Efficiency (Wh/km)

Dimensions & Capacity

  • Length, Width, Height, Seats, Cargo Volume, Towing Capacity, Number of Cells

On submission, the app returns:

  • Predicted range in km and miles
  • A contextual label: Short range (< 300 km) / Mid range (300–500 km) / Long range (> 500 km)

Tech Stack

Layer Library
Data manipulation pandas, numpy
Visualization matplotlib, seaborn
Encoding category_encoders (TargetEncoder)
Machine learning scikit-learn (Random Forest), xgboost
Model serialization joblib
Web UI streamlit

Dataset

EV dataset downloaded from kaggle with multiple features. Also it is available to see in the repository.


About

Range anxiety is one of the biggest barriers to EV adoption. This project trains a regression model on a dataset of real-world EVs from the EV Database. Given a vehicle's specs, the app instantly predicts its range.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors