Created
January 24, 2017 23:00
-
-
Save mrecos/354eb832b0efdd876b7bab344ba5fd63 to your computer and use it in GitHub Desktop.
Function for predicting Logistic Kernel Ridge Regression. Arguments: test_data = testing data set, train_data = data used to train model, alphas_pred = alpha parameters resulting from KRR_logit_optim() or KRR_logit(), sigma = sigma parameter of Gaussian RBF kernel, dist_method = distance method from `proxy` package, progress = T/F progress bar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
KRR_logit_predict <- function(test_data, train_data, alphas_pred, sigma, dist_method = "Euclidean", progress = TRUE){ | |
# example: KRR_logit_predict(test_dat, train_dat, theSol, sigma) | |
pred_yhat <- matrix(nrow = length(test_data), ncol = length(train_data)) | |
if(isTRUE(progress)){ | |
total_iter <- length(test_data) * length(train_data) | |
pb <- txtProgressBar(min = 0, max = total_iter, style = 3) | |
} | |
iter <- 0 | |
for(j in 1:length(test_data)){ | |
for(i in 1:length(train_data)){ | |
g_i <- get_k(train_data[[i]], | |
test_data[[j]], sigma, dist_method = dist_method) | |
k_i <- round(mean(g_i),3) | |
pred_yhat[j,i] <- k_i | |
if(isTRUE(progress)){setTxtProgressBar(pb, iter)} | |
iter <- iter + 1 | |
} | |
} | |
if(isTRUE(progress)){close(pb)} | |
pred <- 1 / (1 + exp(-as.vector(pred_yhat %*% alphas_pred))) | |
return(pred) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment