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
model_path = hf_hub_download(
repo_id="rohansuyal/auto-mpg-random-forest",
filename="tuned_random_forest.pkl"
)
model = joblib.load(model_path)
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}")
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}
}