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.
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.
├── ev_data.csv
├── ev_range_predictor.ipynb
├── random_forest_model.pkl
├── columns.pkl
├── target_encoder.pkl
└── app.py
- Inspected feature distributions and value counts for categorical columns (brand, segment, body type, drivetrain)
- Identified and handled missing values:
number_of_cellsfilled with the column mean; remaining rows with nulls dropped cargo_volume_lcoerced to numeric, nulls filled with the median
- Dropped:
source_url,model,battery_type,fast_charge_port - One-hot encoding:
car_body_type,segment,drivetrain - Target encoding:
brand— encoded usingcategory_encoders.TargetEncoderwith smoothing=10 to avoid overfitting on rare brands
Two regressors were trained and compared on an 80/20 split:
| Model | MAE (km) | R² |
|---|---|---|
| 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.
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)
| 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 |
EV dataset downloaded from kaggle with multiple features. Also it is available to see in the repository.