predict.dasvm: Predict Method for Discriminant Adaptive Support Vector...

Description Usage Arguments Value Note References See Also Examples

View source: R/dasvm.R

Description

This function predicts values based upon a model trained by dasvm.

Usage

1
predict.dasvm(object, newdata, ...)

Arguments

object

Object of class "dasvm", created by dasvm.

newdata

An object containing the new input data: either a matrix or a sparse matrix (object of class Matrix provided by the Matrix package, or of class matrix.csr provided by the SparseM package, or of class simple_triplet_matrix provided by the slam package). A vector will be transformed to a n x 1 matrix.

...

Further arguments to wsvm, e.g. decision.values, probability, na.action.

Value

A vector of predicted values (for classification: a vector of labels, for density estimation: a logical vector). If decision.value is TRUE, the vector gets a "decision.values" attribute containing a n * c matrix (n number of predicted values, c number of classifiers) of all c binary classifiers' decision values. There are k * (k - 1) / 2 classifiers (k number of classes). The colnames of the matrix indicate the labels of the two classes. If probability is TRUE, the vector gets a "probabilities" attribute containing a n * k matrix of the class probabilities.

Note

If the training set was scaled by dasvm (done by default), the new data is scaled accordingly using scale and center of the training data.

References

Hand, D. J., Vinciotti, V. (2003), Local versus global models for classification problems: Fitting models where it matters, The American Statistician, 57(2) 124–130.

See Also

dasvm, wsvm, svm.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
fit1 <- wsvm(Species ~ Sepal.Length + Sepal.Width, data = iris, kernel = "linear", 
	  probability = TRUE)
pred <- predict(fit1)
mean(pred != iris$Species)

fit2 <- dasvm(Species ~ Sepal.Length + Sepal.Width, data = iris, kernel = "linear",
    wf = "gaussian", bw = 0.5, method = "prob", probability = TRUE)
pred <- predict(fit2)
mean(pred != iris$Species)

fit3 <- dasvm(Species ~ Sepal.Length + Sepal.Width, data = iris, kernel = "linear",
    wf = "gaussian", bw = 0.8, method = "decision", probability = TRUE)
pred <- predict(fit3)
mean(pred != iris$Species)

## plot of decision boundary (maximum posterior probabilities):
grid <- expand.grid(Sepal.Length = seq(4,8,0.1), Sepal.Width = seq(2,5,0.1)) 

probgrid1 <- attr(predict(fit1, newdata = grid, probability = TRUE), "probabilities")
decgrid1 <- attr(predict(fit1, newdata = grid, decision.values = TRUE), "decision.values")
probgrid2 <- attr(predict(fit2, newdata = grid, probability = TRUE), "probabilities")
decgrid3 <- attr(predict(fit3, newdata = grid, decision.values = TRUE), "decision.values")

par(mfrow = c(1,2))
contour(seq(4,8,0.1), seq(2,5,0.1), 
    matrix(as.numeric(apply(probgrid1, 1, max)), nrow = length(seq(4,8,0.1))))
contour(seq(4,8,0.1), seq(2,5,0.1), 
    matrix(as.numeric(apply(probgrid2, 1, max)), nrow = length(seq(4,8,0.1))))
points(iris$Sepal.Length, iris$Sepal.Width, pch = 19, 
    cex = fit2$case.weights[[3]]*2, col = as.numeric(iris$Species))

par(mfrow = c(1,2))
contour(seq(4,8,0.1), seq(2,5,0.1), 
    matrix(as.numeric(decgrid1[,1]), nrow = length(seq(4,8,0.1))))
contour(seq(4,8,0.1), seq(2,5,0.1), 
    matrix(as.numeric(decgrid3[,1]), nrow = length(seq(4,8,0.1))))
points(iris$Sepal.Length, iris$Sepal.Width, pch = 19, 
    cex = fit3$case.weights[[3]]*2, col = as.numeric(iris$Species))

contour(seq(4,8,0.1), seq(2,5,0.1), 
    matrix(as.numeric(decgrid1[,2]), nrow = length(seq(4,8,0.1))))
contour(seq(4,8,0.1), seq(2,5,0.1), 
    matrix(as.numeric(decgrid3[,2]), nrow = length(seq(4,8,0.1))))
points(iris$Sepal.Length, iris$Sepal.Width, pch = 19, 
    cex = fit3$case.weights[[3]]*2, col = as.numeric(iris$Species))

contour(seq(4,8,0.1), seq(2,5,0.1), 
    matrix(as.numeric(decgrid1[,3]), nrow = length(seq(4,8,0.1))))
contour(seq(4,8,0.1), seq(2,5,0.1), 
    matrix(as.numeric(decgrid3[,3]), nrow = length(seq(4,8,0.1))))
points(iris$Sepal.Length, iris$Sepal.Width, pch = 19, 
    cex = fit3$case.weights[[3]]*2, col = as.numeric(iris$Species))

schiffner/locClass documentation built on May 29, 2019, 3:39 p.m.