forked from cfia-data-science/PHAEDE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
svm.R
69 lines (60 loc) · 2.56 KB
/
svm.R
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# data partition
title_description_features_training <- title_description_features[training_index, ]
title_description_features_testing <- title_description_features[-training_index, ]
# linear svm model
set.seed(1)
start_time <- Sys.time()
model_lsvm <- train(Risk ~ .,
data = title_description_features_training,
method = "svmLinear",
metric = "ROC",
tuneLength = 10,
trControl = trainControl(method = "cv",
number = 10,
classProbs = TRUE,
summaryFunction = twoClassSummary))
end_time <- Sys.time()
# linear svm running time
time_lsvm <- end_time - start_time
# linear svm predictions
predictions_lsvm <- predict(model_lsvm, title_description_features_testing)
cm_lsvm <- confusionMatrix(predictions_lsvm, title_description_features_testing$Risk)
cm_lsvm
# polynomial svm model
set.seed(2)
start_time <- Sys.time()
model_psvm <- train(Risk ~ .,
data = title_description_features_training,
method = "svmPoly",
metric = "ROC",
tuneLength = 10,
trControl = trainControl(method = "cv",
number = 10,
classProbs = TRUE,
summaryFunction = twoClassSummary))
end_time <- Sys.time()
# polynomial svm running time
time_psvm <- end_time - start_time
# polynomial svm predictions
predictions_psvm <- predict(model_psvm, title_description_features_testing)
cm_psvm <- confusionMatrix(predictions_psvm, title_description_features_testing$Risk)
cm_psvm
# radial svm model
set.seed(3)
start_time <- Sys.time()
model_rsvm <- train(Risk ~ .,
data = title_description_features_training,
method = "svmRadial",
metric = "ROC",
tuneLength = 10,
trControl = trainControl(method = "cv",
number = 10,
classProbs = TRUE,
summaryFunction = twoClassSummary))
end_time <- Sys.time()
# radial svm running time
time_rsvm <- end_time - start_time
# radial svm predictions
predictions_rsvm <- predict(model_rsvm, title_description_features_testing)
cm_rsvm <- confusionMatrix(predictions_rsvm, title_description_features_testing$Risk)
cm_rsvm