e1071 - Support Vector Machine
This guide is designed as a quick-stop reference of how to use some
of the more popular machine learning R packages with vivid
.
In the following examples, we use the air quality data for regression
and the iris data for classification.
library('vivid')
library("e1071")
e1071 - SUpport Vector Machine
The e1071
package in R provides functions for various
machine learning algorithms including support vector machines
(SVMs).
Regression
#load data
aq <- na.omit(airquality)
# build SVM model
sv <- svm(Ozone ~ ., data = aq, kernel = "radial")
# vivid
vi <- vivi(data = aq, fit = sv, response = 'Ozone')
Heatmap
Figure 1: Heatmap of a SVM regression fit
displaying 2-way interaction strength on the off diagonal and individual
variable importance on the diagonal.
PDP
pdpPairs(data = aq,
fit = sv,
response = "Ozone",
nmax = 500,
gridSize = 20,
nIce = 100)
Figure 2: Generalized pairs partial
dependence plot for a SVM regression fit.
Classification
# Load the iris dataset
data(iris)
# Train
sv <- svm(Species ~ ., data = iris, probability = T)
vi <- vivi(data = iris, fit = sv, response = 'Species', class = 'setosa')
Heatmap
Figure 3: Heatmap of a SVM classification
fit displaying 2-way interaction strength on the off diagonal and
individual variable importance on the diagonal.
PDP
pdpPairs(data = iris,
fit = sv,
response = "Species",
nmax = 50,
gridSize = 4,
nIce = 10,
class = 'setosa')
Figure 4: Generalized pairs partial
dependence plot for a SVM classification fit.