You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to run your example code provided in your tidysdm overview vignette but I am getting an issue when I call the collect_metric() on the lacerta_ensemble object. Could you please take a look?
Reprex
library(tidysdm)
#> Loading required package: tidymodels#> Loading required package: spatialsample
library(sf)
#> Linking to GEOS 3.12.0, GDAL 3.7.1, PROJ 9.2.1; sf_use_s2() is TRUE
library(pastclim)
#> Loading required package: terra#> terra 1.7.55#> #> Attaching package: 'terra'#> The following object is masked from 'package:tidyr':#> #> extract#> The following object is masked from 'package:scales':#> #> rescale#> #> Attaching package: 'pastclim'#> The following objects are masked from 'package:tidysdm':#> #> date2ybp, ybp2date
library(tidyterra)
#> #> Attaching package: 'tidyterra'#> The following object is masked from 'package:stats':#> #> filter
library(ggplot2)
data(lacerta)
lacerta#> # A tibble: 1,297 × 3#> ID latitude longitude#> <dbl> <dbl> <dbl>#> 1 858029749 42.6 -7.09#> 2 858029738 42.6 -7.09#> 3 614631090 41.4 -7.90#> 4 614631085 41.3 -7.81#> 5 614631083 41.3 -7.81#> 6 614631080 41.4 -7.83#> 7 614631072 41.4 -7.81#> 8 614559731 40.3 -7.70#> 9 614559728 40.4 -7.70#> 10 614559657 40.4 -7.56#> # ℹ 1,287 more rowslacerta<- st_as_sf(lacerta, coords= c("longitude", "latitude"))
st_crs(lacerta) <-4326# Iberia peninsula extensioniberia_poly<-terra::vect("POLYGON((-9.8 43.3,-7.8 44.1,-2.0 43.7,3.6 42.5,3.8 41.5,1.3 40.8,0.3 39.5,0.9 38.6,-0.4 37.5,-1.6 36.7,-2.3 36.3,-4.1 36.4,-4.5 36.4,-5.0 36.1,-5.6 36.0,-6.3 36.0,-7.1 36.9,-9.5 36.6,-9.4 38.0,-10.6 38.9,-9.5 40.8,-9.8 43.3))")
crs(iberia_poly) <-"lonlat"
gdal(warn=3)
land_mask<- rast(system.file("extdata/lacerta_land_mask.nc",
package="tidysdm"))
ggplot() +
geom_spatraster(data=land_mask, aes(fill=land_mask_1985)) +
geom_sf(data=lacerta)
climate_present<-climate_present[[suggested_vars]]
vars_uncor<- filter_high_cor(climate_present, cutoff=0.7)
vars_uncor#> [1] "bio15" "bio05" "bio13" "bio06"#> attr(,"to_remove")#> [1] "bio14"lacerta_thin<-lacerta_thin %>% select(all_of(c(vars_uncor, "class")))
climate_present<-climate_present[[vars_uncor]]
lacerta_rec<- recipe(lacerta_thin, formula=class~.)
lacerta_rec#> #> ── Recipe ──────────────────────────────────────────────────────────────────────#> #> ── Inputs#> Number of variables by role#> outcome: 1#> predictor: 4#> coords: 2lacerta_thin %>% check_sdm_presence(class)
#> [1] TRUElacerta_models<-# create the workflow_set
workflow_set(
preproc=list(default=lacerta_rec),
models=list(
# the standard glm specsglm= sdm_spec_glm(),
# rf specs with tuningrf= sdm_spec_rf(),
# boosted tree model (gbm) specs with tuninggbm= sdm_spec_boost_tree(),
# maxent specs with tuningmaxent= sdm_spec_maxent()
),
# make all combinations of preproc and models,cross=TRUE
) %>%
# tweak controls to store information needed later to create the ensemble
option_add(control= control_ensemble_grid())
set.seed(100)
lacerta_cv<- spatial_block_cv(lacerta_thin, v=5)
autoplot(lacerta_cv)
set.seed(1234567)
lacerta_models<-lacerta_models %>%
workflow_map("tune_grid",
resamples=lacerta_cv, grid=3,
metrics= sdm_metric_set(), verbose=TRUE
)
#> i No tuning parameters. `fit_resamples()` will be attempted#> i 1 of 4 resampling: default_glm#> ✔ 1 of 4 resampling: default_glm (188ms)#> i 2 of 4 tuning: default_rf#> i Creating pre-processing data to finalize unknown parameter: mtry#> ✔ 2 of 4 tuning: default_rf (763ms)#> i 3 of 4 tuning: default_gbm#> i Creating pre-processing data to finalize unknown parameter: mtry#> ✔ 3 of 4 tuning: default_gbm (4s)#> i 4 of 4 tuning: default_maxent#> ✔ 4 of 4 tuning: default_maxent (1.4s)
autoplot(lacerta_models)
lacerta_ensemble<- simple_ensemble() %>%
add_member(lacerta_models, metric="boyce_cont")
lacerta_ensemble#> A simple_ensemble of models#> #> Members:#> • default_glm#> • default_rf#> • default_gbm#> • default_maxent#> #> Available metrics:#> • boyce_cont#> • roc_auc#> • tss_max#> #> Metric used to tune workflows:#> • boyce_cont
autoplot(lacerta_ensemble)
lacerta_ensemble %>% collect_metrics()
#> Error in `collect_metrics()`:#> ! No `collect_metric()` exists for this type of object.#> Backtrace:#> ▆#> 1. ├─lacerta_ensemble %>% collect_metrics()#> 2. ├─tune::collect_metrics(.)#> 3. └─tune:::collect_metrics.default(.)#> 4. └─rlang::abort("No `collect_metric()` exists for this type of object.")
Hello,
Thank you for developing this amazing package!
I am trying to run your example code provided in your tidysdm overview vignette but I am getting an issue when I call the
collect_metric()
on thelacerta_ensemble
object. Could you please take a look?Reprex
Session info
The text was updated successfully, but these errors were encountered: