Car Fuel Efficiency (MPG) Predictor

Sujal
October 2026

A Shiny app that predicts a car's mileage from its weight, horsepower and transmission.

Developing Data Products — Course Project

The Problem

  • Fuel cost is one of the biggest running costs of owning a car.
  • Before buying, people want a quick answer to: “How many miles per gallon will this car give?”
  • Spec sheets list weight, horsepower and gearbox — but not always real-world mileage.

Our idea: turn those three easy-to-find numbers into an instant mileage estimate, with no statistics knowledge needed.

How It Works

The app fits a linear regression on R's built-in mtcars dataset (32 cars):

fit <- lm(mpg ~ wt + hp + am, data = mtcars)
round(coef(fit), 3)
(Intercept)          wt          hp          am 
     34.003      -2.879      -0.037       2.084 
  • Every 1000 lbs of extra weight costs about 2.9 MPG.
  • The model explains 84% of the variation in MPG.

A Live Example

A 3000 lb, 120 hp car with a manual gearbox:

car <- data.frame(wt = 3.0, hp = 120, am = 1)
round(predict(fit, car, interval = "prediction"), 1)
  fit  lwr  upr
1  23 17.4 28.5

plot of chunk unnamed-chunk-3

Try It Yourself

Using the app takes three steps: 1. Move the weight and horsepower sliders. 2. Choose Automatic or Manual transmission. 3. Read the predicted MPG, km/l and 95% range — updated instantly, with a plot.

A built-in “How to use” tab explains everything for first-time users.