Description Usage Arguments Value Note References See Also Examples
This function predicts values based upon a model trained by dasvm
.
1 | predict.dasvm(object, newdata, ...)
|
object |
Object of class |
newdata |
An object containing the new input data: either a
matrix or a sparse matrix (object of class
|
... |
Further arguments to |
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.
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.
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.
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))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.