July 23, 2026

Car MPG Predictor

Predicting vehicle fuel efficiency using the mtcars dataset.

This Shiny application allows users to estimate MPG based on vehicle characteristics.

Features - Interactive user inputs - Regression-based prediction - Visualization of predicted fuel efficiency

Motivation

Fuel efficiency depends on several vehicle characteristics.

This application explores the relationship between:

  • Horsepower
  • Vehicle weight
  • Number of cylinders
  • Transmission type

The goal is to provide a simple tool for predicting MPG.

Data and Prediction Model

The application uses the built-in mtcars dataset.

Variables included:

  • mpg = Miles per gallon
  • hp = Horsepower
  • wt = Weight
  • cyl = Cylinders
  • am = Transmission
data(mtcars)

model <- lm(
  mpg ~ hp + wt + cyl + am,
  data = mtcars
)

summary(model)
## 
## Call:
## lm(formula = mpg ~ hp + wt + cyl + am, data = mtcars)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.4765 -1.8471 -0.5544  1.2758  5.6608 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 36.14654    3.10478  11.642 4.94e-12 ***
## hp          -0.02495    0.01365  -1.828   0.0786 .  
## wt          -2.60648    0.91984  -2.834   0.0086 ** 
## cyl         -0.74516    0.58279  -1.279   0.2119    
## am           1.47805    1.44115   1.026   0.3142    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.509 on 27 degrees of freedom
## Multiple R-squared:  0.849,  Adjusted R-squared:  0.8267 
## F-statistic: 37.96 on 4 and 27 DF,  p-value: 1.025e-10

How the Shiny Application Works

Users enter vehicle information:

  1. Horsepower
  2. Weight
  3. Number of cylinders
  4. Transmission type

The server uses a regression model to calculate predicted MPG.

The prediction is displayed instantly with a visualization.

Conclusion

The Car MPG Predictor provides an interactive way to explore vehicle fuel efficiency.

Benefits - Easy-to-use interface - Real-time predictions - Data-driven results

Future Improvements - Add more vehicle features - Compare additional models - Use larger datasets