Car MPG Predictor App

Your Name
2026-09-06

Overview

The Car MPG Predictor is a Shiny application that allows users to predict the fuel efficiency (Miles Per Gallon) of a car based on specific characteristics.

This application is built for the Coursera “Developing Data Products” course project. It features:

  • An easy-to-use interactive interface
  • Real-time prediction updates
  • Built-in documentation for novice users
  • A robust linear model based on the classic mtcars dataset

The Dataset

The application uses the mtcars dataset, which was extracted from the 1974 Motor Trend US magazine, and comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles.

# Display the first few rows of the dataset features used in the app
head(mtcars[, c("mpg", "hp", "wt", "am")])
                   mpg  hp    wt am
Mazda RX4         21.0 110 2.620  1
Mazda RX4 Wag     21.0 110 2.875  1
Datsun 710        22.8  93 2.320  1
Hornet 4 Drive    21.4 110 3.215  0
Hornet Sportabout 18.7 175 3.440  0
Valiant           18.1 105 3.460  0

The Prediction Model

A linear regression model is fitted to predict mpg using Horsepower (hp), Weight (wt), and Transmission Type (am).

# Fit the model
model <- lm(mpg ~ hp + wt + am, data = mtcars)
# Display the coefficients
summary(model)$coefficients
               Estimate  Std. Error   t value     Pr(>|t|)
(Intercept) 34.00287512 2.642659337 12.866916 2.824030e-13
hp          -0.03747873 0.009605422 -3.901830 5.464023e-04
wt          -2.87857541 0.904970538 -3.180850 3.574031e-03
am           2.08371013 1.376420152  1.513862 1.412682e-01

How to Use the App

  1. Select Horsepower: Use the first slider to set the car's horsepower.
  2. Select Weight: Use the second slider to set the car's weight in 1000 lbs.
  3. Select Transmission: Choose between Automatic (0) and Manual (1) transmission using the radio buttons.
  4. View Results: The predicted MPG is displayed immediately on the right side of the screen along with the R model summary.

Check out the source code on GitHub and try the app on shinyapps.io!