install.packages("AppliedPredictiveModeling",repos = "http://cran.us.r-project.org")
##
## The downloaded binary packages are in
## /var/folders/4z/9kr7k7jd1q7gc792xjkrwf040000gn/T//RtmpnbRBjm/downloaded_packages
library(AppliedPredictiveModeling)
install.packages("caret",repos = "http://cran.us.r-project.org")
##
## The downloaded binary packages are in
## /var/folders/4z/9kr7k7jd1q7gc792xjkrwf040000gn/T//RtmpnbRBjm/downloaded_packages
library(caret)
## Warning: package 'caret' was built under R version 3.3.2
## Loading required package: lattice
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.3.2
transparentTheme(trans = .4)
featurePlot(x = iris[, 1:4],
y = iris$Species,
plot = "pairs",
## Add a key at the top
auto.key = list(columns = 3))
transparentTheme(trans = .9)
featurePlot(x = iris[, 1:4],
y = iris$Species,
plot = "density",
## Pass in options to xyplot() to
## make it prettier
scales = list(x = list(relation="free"),
y = list(relation="free")),
adjust = 1.5,
pch = "|",
layout = c(4, 1),
auto.key = list(columns = 3))
transparentTheme(trans = .9)
featurePlot(x = iris[, 1:4],
y = iris$Species,
plot = "box",
## Pass in options to bwplot()
scales = list(y = list(relation="free"),
x = list(rot = 90)),
layout = c(4,1 ),
auto.key = list(columns = 2))
When the predictors are continuous, featurePlot can be used to create scatter plots of each of the predictors with the outcome. For example:
install.packages("mlbench",repos = "http://cran.us.r-project.org")
##
## The downloaded binary packages are in
## /var/folders/4z/9kr7k7jd1q7gc792xjkrwf040000gn/T//RtmpnbRBjm/downloaded_packages
library(mlbench)
data(BostonHousing)
regVar <- c("age", "lstat", "tax")
str(BostonHousing[, regVar])
## 'data.frame': 506 obs. of 3 variables:
## $ age : num 65.2 78.9 61.1 45.8 54.2 58.7 66.6 96.1 100 85.9 ...
## $ lstat: num 4.98 9.14 4.03 2.94 5.33 ...
## $ tax : num 296 242 242 222 222 222 311 311 311 311 ...
theme1 <- trellis.par.get()
theme1$plot.symbol$col = rgb(.2, .2, .2, .4)
theme1$plot.symbol$pch = 16
theme1$plot.line$col = rgb(1, 0, 0, .7)
theme1$plot.line$lwd <- 2
trellis.par.set(theme1)
featurePlot(x = BostonHousing[, regVar],
y = BostonHousing$medv,
plot = "scatter",
layout = c(3, 1))
featurePlot(x = BostonHousing[, regVar],
y = BostonHousing$medv,
plot = "scatter",
type = c("p", "smooth"),
span = .5,
layout = c(3, 1))