Data Products Project 4

Arind

August 8, 2018

Introduction

This presentation is one half of the assignemnt of week 4, Developing Data Products course from Coursera. In this presentation we will pitch for the shiny application we have developped, which can be found here.

In this shiny application we are going to predict the Miles/Gallon from the mtcars dataset taking the values from other features in the dataset interactively.

Analysis

In the shiny app we have considered the mtcars dataset for our analysis.

The variable “am” in mtcars represents the transmission mode of the vehicle i.e “1” for Manual and “0” for automatic transmission.

Let’s convert the “am” variable to a factor variable replacing the binary 1 & 0 with “Auto” and “Manual” respectively.

mtcars$am <- factor(ifelse(mtcars$am == 1, "Manual", "Auto"))

We have shown the relationship of all the features against Miles/Gallon

Regression

In the app we have shown linear regression between the variables . A sample code is given below.

model <- lm(formula = mpg ~ cyl + hp + wt + am, data = mtcars)
with(mtcars, {
      plot(model)
      abline(model, col=2)
      }
     )

## Warning in abline(model, col = 2): only using the first two of 5 regression
## coefficients

Forecast

We have trained model now we predict the Miles/Gallon according to inputs. In shiny app this has been done interactively.

An example shown below.

library(caret)
## Loading required package: lattice
## Loading required package: ggplot2
customTrainControl <- trainControl(method = "cv", number = 10)
trModel <- train(mpg ~ cyl + hp + wt + am, data = mtcars, method = "lm", trControl = customTrainControl)
predict(trModel, newdata = mtcars[1:10,])
##         Mazda RX4     Mazda RX4 Wag        Datsun 710    Hornet 4 Drive 
##          23.58005          22.91539          26.27647          20.55114 
## Hornet Sportabout           Valiant        Duster 360         Merc 240D 
##          16.85255          20.03731          14.76713          23.30427 
##          Merc 230          Merc 280 
##          22.58514          19.64032