-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.r
29 lines (19 loc) · 805 Bytes
/
test.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
library('e1071')
# matrix with n rows (observations) and p columns (features)
x = as.matrix(read.table("data/train_data.txt"))
#x = read.matrix.csr("data/train_data.csr", fac = FALSE)
# vector of size n and values +1 or -1 only
y = as.factor(as.vector(read.table("data/train_labels.txt"),
mode = "numeric"))
# check number of rows
stopifnot(nrow(x) == length(y))
# RBF kernel parameters
cost = 1
gamma = 1 / ncol(x)
model <- svm(x, y, type = 'C-classification', scale = FALSE,
kernel = "radial", cost, gamma)
save(model, file="r_svm_model.bin")
load("r_svm_model.bin")
values = attributes(predict(model, newdata = x, decision.values = TRUE))$decision.values
write.table(values, file = "data/predictions.txt", sep = "\n", row.names = F, col.names = F)
quit()