CoolFace
Modelpublic

adityasuyal/auto-mpg-random-forest

sourceHugging Facemitupdated 3d agoView on Hugging Face
1likes
Model Card

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

PropertyValue
AlgorithmRandom Forest Regressor
Libraryscikit-learn
Tuning MethodRandomizedSearchCV (50 iterations)
Cross-Validation5-Fold KFold
Target VariableMiles Per Gallon (mpg)
Train / Test Split80% / 20%
Random State42

Performance Metrics

Tuned Model — Test Set Results

MetricUntuned RF**Tuned RF**Improvement
0.89230.9178▲ +0.0255
RMSE2.34432.0521▼ −0.2922
MAE1.64811.4237▼ −0.2244

Cross-Validation (Training Set)

MetricMeanStd
CV R²0.9041±0.0198
CV RMSE2.1834

All Models Comparison

ModelTest R²Test RMSETest MAE
Tuned Random Forest0.91782.05211.4237
Random Forest (Untuned)0.89232.34431.6481
Gradient Boosting0.87432.53241.7661
Polynomial Regression0.84732.79172.0755
Ridge Regression0.79033.27152.4190
Linear Regression0.79023.27272.4198
Lasso Regression0.79013.27302.4193

Best Hyperparameters (Found via RandomizedSearchCV)

ParameterValue
n_estimators300
max_depthNone
min_samples_split2
min_samples_leaf1
max_featuressqrt

Features Used

FeatureDescription
cylindersNumber of engine cylinders
displacementEngine displacement (cubic inches)
horsepowerEngine horsepower
weightVehicle weight (lbs)
acceleration0–60 mph acceleration time (seconds)
model yearYear of manufacture (70–82)
originRegion of manufacture (1=USA, 2=Europe, 3=Japan)

How to Use

python
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

FileDescription
tuned_random_forest.pklTrained & tuned model (joblib format)
tune.pyFull hyperparameter tuning script
random_forest_tuning_results.csvAll 50 tuning trial results
cleaned_data.csvPreprocessed 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

bash
pip install scikit-learn joblib huggingface_hub numpy

Citation

bibtex
@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}
}