Running examples in ‘e1071-Ex.R’ failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: svm
> ### Title: Support Vector Machines
> ### Aliases: svm svm.default svm.formula summary.svm print.summary.svm
> ###   coef.svm print.svm
> ### Keywords: neural nonlinear classif
> 
> ### ** Examples
> 
> data(iris)
> attach(iris)
> 
> ## classification mode
> # default with factor response:
> model <- svm(Species ~ ., data = iris)
> 
> # alternatively the traditional interface:
> x <- subset(iris, select = -Species)
> y <- Species
> model <- svm(x, y) 
> 
> print(model)

Call:
svm.default(x = x, y = y)


Parameters:
   SVM-Type:  C-classification 
 SVM-Kernel:  radial 
       cost:  1 

Number of Support Vectors:  51

> summary(model)

Call:
svm.default(x = x, y = y)


Parameters:
   SVM-Type:  C-classification 
 SVM-Kernel:  radial 
       cost:  1 

Number of Support Vectors:  51

 ( 8 22 21 )


Number of Classes:  3 

Levels: 
 setosa versicolor virginica



> 
> # test with train data
> pred <- predict(model, x)
> # (same as:)
> pred <- fitted(model)
> 
> # Check accuracy:
> table(pred, y)
            y
pred         setosa versicolor virginica
  setosa         50          0         0
  versicolor      0         48         2
  virginica       0          2        48
> 
> # compute decision values and probabilities:
> pred <- predict(model, x, decision.values = TRUE)
> attr(pred, "decision.values")[1:4,]
  setosa/versicolor setosa/virginica versicolor/virginica
1          1.196152         1.091757            0.6708810
2          1.064621         1.056185            0.8483518
3          1.180842         1.074542            0.6439798
4          1.110699         1.053012            0.6782041
> 
> # visualize (classes by color, SV by crosses):
> plot(cmdscale(dist(iris[,-5])),
+      col = as.integer(iris[,5]),
+      pch = c("o","+")[1:150 %in% model$index + 1])
> 
> ## try regression mode on two dimensions
> 
> # create data
> x <- seq(0.1, 5, by = 0.05)
> y <- log(x) + rnorm(x, sd = 0.2)
> 
> # estimate model and predict input values
> m   <- svm(x, y)
> new <- predict(m, x)
> 
> # visualize
> plot(x, y)
> points(x, log(x), col = 2)
> points(x, new, col = 4)
> 
> ## density-estimation
> 
> # create 2-dim. normal with rho=0:
> X <- data.frame(a = rnorm(1000), b = rnorm(1000))
> attach(X)
> 
> # traditional way:
> m <- svm(X, gamma = 0.1)
> 
> # formula interface:
> m <- svm(~., data = X, gamma = 0.1)
> # or:
> m <- svm(~ a + b, gamma = 0.1)
> 
> # test:
> newdata <- data.frame(a = c(0, 4), b = c(0, 4))
> predict (m, newdata)
    1     2 
 TRUE FALSE 
> 
> # visualize:
> plot(X, col = 1:1000 %in% m$index + 1, xlim = c(-5,5), ylim=c(-5,5))
> points(newdata, pch = "+", col = 2, cex = 5)
> 
> ## weights: (example not particularly sensible)
> i2 <- iris
> levels(i2$Species)[3] <- "versicolor"
> summary(i2$Species)
    setosa versicolor 
        50        100 
> wts <- 100 / table(i2$Species)
> wts

    setosa versicolor 
         2          1 
> m <- svm(Species ~ ., data = i2, class.weights = wts)
> 
> ## extract coefficients for linear kernel
> 
> # a. regression
> x <- 1:100
> y <- x + rnorm(100)
> m <- svm(y ~ x, scale = FALSE, kernel = "linear")
> coef(m)
(Intercept)           x 
 -0.3756197   1.0052570 
> plot(y ~ x)
> abline(m, col = "red")
> 
> # b. classification
> # transform iris data to binary problem, and scale data
> setosa <- as.factor(iris$Species == "setosa")
> iris2 = scale(iris[,-5])
> 
> # fit binary C-classification model
> m <- svm(setosa ~ Petal.Width + Petal.Length,
+         data = iris2, kernel = "linear")
Error in model.frame.default(formula = setosa ~ Petal.Width + Petal.Length,  : 
  'data' must be a data.frame, not a matrix or an array
Calls: svm ... svm.formula -> eval -> eval -> <Anonymous> -> model.frame.default
Execution halted