diff --git a/lab3/assignment3.R b/lab3/assignment3.R index 5ebddf8d8d372d201e214df8c95261c7769a8b6e..fe91786a70f7dde06f7d69a8775d80a15297d52d 100644 --- a/lab3/assignment3.R +++ b/lab3/assignment3.R @@ -89,8 +89,8 @@ err3 # 3. Implementation of SVM predictions. -gaussian_kernel <- function(x, sigma = 0.05) { - exp(-(x ^ 2) / (2 * sigma ^ 2)) +rbf_kernel <- function(x1, x2, lambda = 0.05) { + exp(-(dist(rbind(x1,x2)) ^ 2) * lambda) } sv <- alphaindex(filter3)[[1]] @@ -103,7 +103,7 @@ for (i in 1:10) { data_point <- spam[i, -58] for (j in 1:length(sv)) { support_vector <- spam[sv[j], -58] - kernel_value <- gaussian_kernel(sum((support_vector - data_point)^2), sigma = 0.05) + kernel_value <- rbf_kernel(support_vector, data_point) k2 <- k2 + co[j] * kernel_value } print(k2)