30e9a2b08485ca1c1a3a7182538de15c2606ea93
[aggexp.git] / pkg / R / m_SVMclassif.R
1 #' @include b_Algorithm.R
2
3 #' @title SVM Algorithm
4 #'
5 #' @description SVM classifier.
6 #' Inherits \code{\link{Algorithm}}
7 #'
8 #' @field kernel TODO
9 #' @field someParam TODO
10 #'
11 SVMclassif = setRefClass(
12 Class = "SVMclassif",
13
14 fields = c(
15 kernel = "numeric",
16 someParam = "logical"
17 ),
18
19 contains = "Algorithm",
20
21 methods = list(
22 initialize = function(...)
23 {
24 callSuper(...)
25 #TODO
26 },
27 predict_noNA = function(XY, x)
28 {
29 if (nrow(XY) <= 5)
30 return (10) #TODO
31
32 require(kernlab, quietly=TRUE)
33 XY[,"alert"] = XY[,"Measure"] > 30
34 alertsIndices = XY[,"alert"]
35 XY[alertsIndices,"alert"] = "alert"
36 XY[!alertsIndices,"alert"] = "noalert"
37 XY[,"alert"] = as.factor(XY[,"alert"])
38 XY[,"Measure"] = NULL
39
40 ks = ksvm(alert ~ ., data=XY)
41 pred = as.character(predict(ks, as.data.frame(x)))
42 pred[pred == "alert"] = 70
43 pred[pred == "noalert"] = 10
44 return (as.numeric(pred))
45 }
46 )
47 )