# Comparison
models <- list(PLS = pls_model, Ridge = ridge_fit, `Elastic net` = enet_fit)
best_cv <- function(fit) {
r <- merge(fit$bestTune, fit$results)
c(CV_RMSE = r$RMSE, CV_Rsq = r$Rsquared)
}
test_perf <- function(fit) {
p <- postResample(predict(fit, fingerprints_test), permeability_test)
c(Test_RMSE = unname(p["RMSE"]), Test_Rsq = unname(p["Rsquared"]))
}
comparison <- do.call(rbind, lapply(models, function(m) c(best_cv(m), test_perf(m))))
comparison <- data.frame(
Model = names(models),
Tuning = c(paste("ncomp =", pls_model$bestTune$ncomp),
paste("lambda =", round(ridge_fit$bestTune$lambda, 3)),
paste0("lambda = ", enet_fit$bestTune$lambda,
", fraction = ", round(enet_fit$bestTune$fraction, 2))),
round(comparison, 3), row.names = NULL)
comparison