GithubHelp home page GithubHelp logo

Comments (1)

sjevelazco avatar sjevelazco commented on June 24, 2024

Hi

This is an interesting feature to be added to p_pdp function. However, I need to think carefully about implementing it to this function based on different ensemble approaches. I will add this implementation to my "todo" list ;)
Meanwhile, you can try to use the data_pdp, which returns a tibble object you can use to plot the curves.

Follow an example

library(terra)
library(dplyr)
library(tidyr)
library(ggplot2)
library(flexsdm)


somevar <- system.file("external/somevar.tif", package = "flexsdm")
somevar <- terra::rast(somevar) # environmental data
names(somevar) <- c("aet", "cwd", "tmx", "tmn")
data(abies)

abies2 <- abies %>%
  select(x, y, pr_ab)

abies2 <- sdm_extract(abies2,
  x = "x",
  y = "y",
  env_layer = somevar
)
abies2 <- part_random(abies2,
  pr_ab = "pr_ab",
  method = c(method = "kfold", folds = 5)
)

svm_t1 <- fit_svm(
  data = abies2,
  response = "pr_ab",
  predictors = c("aet", "cwd", "tmx", "tmn"),
  partition = ".part",
  thr = c("max_sens_spec")
)

gam_t1 <- fit_gam(
  data = abies2,
  response = "pr_ab",
  predictors = c("aet", "cwd", "tmx", "tmn"),
  partition = ".part",
  thr = c("max_sens_spec"), k = -1
)

raf_t1 <- fit_raf(
  data = abies2,
  response = "pr_ab",
  predictors = c("aet", "cwd", "tmx", "tmn"),
  partition = ".part",
  thr = c("max_sens_spec")
)

df_svm <- data_pdp(
  model = svm_t1$model,
  predictors = c("aet"),
  resolution = 100,
  resid = TRUE,
  projection_data = somevar,
  training_data = abies2,
  clamping = FALSE
)

df_gam <- data_pdp(
  model = gam_t1$model,
  predictors = c("aet"),
  resolution = 100,
  resid = TRUE,
  projection_data = somevar,
  training_data = abies2,
  clamping = FALSE
)
df_raf <- data_pdp(
  model = raf_t1$model,
  predictors = c("aet"),
  resolution = 100,
  resid = TRUE,
  projection_data = somevar,
  training_data = abies2,
  clamping = FALSE
)

db_list <- list(SVM = df_svm$pdpdata, 
                GAM = df_gam$pdpdata, 
                RAF = df_raf$pdpdata)
db_list <- bind_rows(db_list, .id = "Algorithm")
db_list <- db_list %>% tidyr::spread(Algorithm, Suitability)
# Calculate ensemble
db_list <- db_list %>%
  dplyr::rowwise() %>%
  mutate(Ensemble = mean(c(GAM, SVM, RAF)))

db_list <- db_list %>% 
  tidyr::gather("Algorithm", "Suitability", GAM, SVM, RAF, Ensemble)
db_list$`-aet` <- NULL

ggplot(db_list, aes(aet, Suitability)) +
  geom_line(aes(color = Algorithm))

ggplot(
  db_list %>% dplyr::filter(Algorithm == "Ensemble"),
  aes(aet, Suitability)
) +
  geom_line(aes(color = Algorithm))

from flexsdm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.