Auto MPG — Tuned Random Forest Regressor
This model is trained on the Auto MPG dataset.
It predicts fuel efficiency (mpg) from car features such as cylinders, horsepower, weight, and more.
Best Test R² : 0.9178 — Tuned using RandomizedSearchCV with 5-Fold Cross-Validation.
Model Details
| Property | Value |
|---|---|
| Algorithm | Random Forest Regressor |
| Library | scikit-learn |
| Tuning Method | RandomizedSearchCV (50 iterations) |
| Cross-Validation | 5-Fold KFold |
| Target Variable | Miles Per Gallon (mpg) |
| Train / Test Split | 80% / 20% |
| Random State | 42 |
Performance Metrics
Tuned Model — Test Set Results
| Metric | Untuned RF | Tuned RF | Improvement |
|---|---|---|---|
| R² | 0.8923 | 0.9178 | ▲ +0.0255 |
| RMSE | 2.3443 | 2.0521 | ▼ −0.2922 |
| MAE | 1.6481 | 1.4237 | ▼ −0.2244 |
Cross-Validation (Training Set)
| Metric | Mean | Std |
|---|---|---|
| CV R² | 0.9041 | ±0.0198 |
| CV RMSE | 2.1834 | — |
All Models Comparison
| Model | Test R² | Test RMSE | Test MAE |
|---|---|---|---|
| Tuned Random Forest | 0.9178 | 2.0521 | 1.4237 |
| Random Forest (Untuned) | 0.8923 | 2.3443 | 1.6481 |
| Gradient Boosting | 0.8743 | 2.5324 | 1.7661 |
| Polynomial Regression | 0.8473 | 2.7917 | 2.0755 |
| Ridge Regression | 0.7903 | 3.2715 | 2.4190 |
| Linear Regression | 0.7902 | 3.2727 | 2.4198 |
| Lasso Regression | 0.7901 | 3.2730 | 2.4193 |
Best Hyperparameters (Found via RandomizedSearchCV)
| Parameter | Value |
|---|---|
n_estimators |
300 |
max_depth |
None |
min_samples_split |
2 |
min_samples_leaf |
1 |
max_features |
sqrt |
Features Used
| Feature | Description |
|---|---|
cylinders |
Number of engine cylinders |
displacement |
Engine displacement (cubic inches) |
horsepower |
Engine horsepower |
weight |
Vehicle weight (lbs) |
acceleration |
0–60 mph acceleration time (seconds) |
model year |
Year of manufacture (70–82) |
origin |
Region of manufacture (1=USA, 2=Europe, 3=Japan) |
How to Use
import joblib
import numpy as np
from huggingface_hub import hf_hub_download
# Download the model
model_path = hf_hub_download(
repo_id="rohansuyal/auto-mpg-random-forest",
filename="tuned_random_forest.pkl"
)
# Load the model
model = joblib.load(model_path)
# Make a prediction
# [cylinders, displacement, horsepower, weight, acceleration, model_year, origin]
sample = np.array([[4, 120.0, 79.0, 2625, 18.6, 82, 1]])
predicted_mpg = model.predict(sample)
print(f"Predicted MPG: {predicted_mpg[0]:.2f}")
# Output: Predicted MPG: 32.47
Files
| File | Description |
|---|---|
tuned_random_forest.pkl |
Trained & tuned model (joblib format) |
tune.py |
Full hyperparameter tuning script |
random_forest_tuning_results.csv |
All 50 tuning trial results |
cleaned_data.csv |
Preprocessed Auto MPG dataset (392 rows) |
Dataset
- Source: UCI Auto MPG Dataset
- Samples: 392 (after cleaning — removed missing horsepower values)
- Train samples: 313
- Test samples: 79
Installation
pip install scikit-learn joblib huggingface_hub numpy
Citation
@misc{auto-mpg-rf-2024,
author = {rohansuyal},
title = {Auto MPG — Tuned Random Forest Regressor},
year = {2024},
url = {https://huggingface.co/rohansuyal/auto-mpg-random-forest}
}