2025-12-17

Introduction

Fuel consumption Prediction

This presentation introduces a Shiny application to predict a vehicle’s fuel consumption (MPG). * Data: ‘mtcars’ (Dataset of 32 automobiles). * Model: Linear Regression.

The porpuse

What does it predict?

The application allows a user to predict a vehicle’s MPG based on two key, easily obtainable factors:

  1. Vehicle Weight (wt): A Slider to select the weight.
  2. Number of Cylinders (cyl): Radio Buttons (4, 6, or 8 cylinders).

Model and R Code.

The Linear Regression Model

We use a simple linear regression model where MPG is a function of weight (wt) and cylinders (cyl).

The following code was evaluated during the generation of this slide:

# Requirement: R code that is executed and displayed 
data(mtcars)
mpg_model <- lm(mpg ~ wt + factor(cyl), data = mtcars)
coef(mpg_model)
##  (Intercept)           wt factor(cyl)6 factor(cyl)8 
##    33.990794    -3.205613    -4.255582    -6.070860

Application functionality

Interactive Features

  • Weight Slider: Adjust vehicle weight between 1,500 and 5,500 lbs.
  • Cylinder Selection: Choose between 4, 6, or 8 cylinder engines.
  • Instant Result: The app updates the MPG prediction immediately using a reactive server function.

Sample Calculation (Reproducible R Code)

If a user selects a weight of 3,000 lbs (3.0) and 6 cylinders, the server runs:

##        1 
## 20.11837

Conclusions and resources

Why Use This App?

  • Speed: No need to perform manual regression calculations.
  • Accuracy: Based on the verified mtcars industry dataset.
  • Accessibility: Available on any web browser via Shinyapps.io.

Project Links

Thank you for evaluating this project!