# format the data
data("bradypus", package = "maxnet")
bradypus_tb <- tibble::as_tibble(bradypus) %>%
dplyr::mutate(presence = relevel(
factor(
dplyr::case_match(presence, 1 ~ "presence", 0 ~ "absence")
),
ref = "presence"
)) %>%
select(-ecoreg)
# fit the model, and make some predictions
maxent_spec <- maxent(feature_classes = "lq")
maxent_fitted <- maxent_spec %>%
fit(presence ~ ., data = bradypus_tb)
pred_prob <- predict(maxent_fitted,
new_data = bradypus[, -1],
type = "prob"
)
pred_class <- predict(maxent_fitted,
new_data = bradypus[, -1],
type = "class"
)
# Now with tuning
maxent_spec <- maxent(
regularization_multiplier = tune::tune(),
feature_classes = tune::tune()
)
set.seed(452)
cv <- vfold_cv(bradypus_tb, v = 2)
maxent_tune_res <- maxent_spec %>%
tune_grid(presence ~ ., cv, grid = 3)
show_best(maxent_tune_res, metric = "roc_auc")
Run the code above in your browser using DataLab