MPG Predictor

Shoaib Haroon
July 2026

The Problem

Fuel efficiency matters - but what drives it?

  • Heavier cars burn more fuel
  • Higher horsepower engines consume more
  • More cylinders generally reduce MPG

Yet most people have no quick way to estimate MPG from these specs without running R themselves.

This app solves that for any user, no R required.

How the App Works

The app takes three inputs from the user:

Input Widget Range
Weight (1,000 lbs) Slider 1.5 - 5.5
Horsepower Slider 52 - 335
Cylinders Radio buttons 4 / 6 / 8

A linear regression model trained on R's built-in mtcars dataset produces an instant MPG prediction.

The result updates reactively - no submit button needed.

The Model (runs live)

model <- lm(mpg ~ wt + hp + cyl, data = mtcars)
round(summary(model)$coefficients, 3)
            Estimate Std. Error t value Pr(>|t|)
(Intercept)   38.752      1.787  21.687    0.000
wt            -3.167      0.741  -4.276    0.000
hp            -0.018      0.012  -1.519    0.140
cyl           -0.942      0.551  -1.709    0.098

R-squared: 0.843 - the three predictors explain over 84% of MPG variance.

Each extra 1,000 lbs of weight costs roughly 3.17 MPG.

Try the App!

Live app: https://s8tlsi-shoaib-haroon.shinyapps.io/mpg-predictor/

Source code (GitHub): https://github.com/shoby0/mpg-predictor

Features at a glance:

  • Instant reactive predictions
  • Scatter plot showing your car vs the full dataset
  • Trend line for your selected cylinder group
  • Plain-English documentation built into the sidebar
  • No R knowledge required to use it