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
Is there a preferred save and load procedure and class type for SDMmodel files? I am running numerous SDMtune models and saving them to file before loading them later on to then extract various metrics like auc() and predict() to output raster surfaces. But, I am having issues with being able to use the reloaded model objects and intermittently getting errors from them. It seems to be a class issue with the error commonly being:
"Error in UseMethod("predict") : no applicable method for 'predict' applied to an object of class "randomForest""
But, this goes for maxent, maxnet and BRT methods also. I am using saveRDS() and readRDS() to save and load SDMmodelCV class models. When I read in these objects in they look identical to when they were originally created and are of class SDMmodel or SDMmodelCV, but they are not working (sometimes) with code they have done previously when not saved and reloaded. I have written some example code below, which frustratingly worked when I ran it, but is indicative of my workflow.
For reference, these model files are based on training data and have 4 k-folds as below. I am also applying an optimisation process such that:
methods <- c('Maxnet', 'BRT', 'RF')
m1 <- SDMtune::train(method = methods[j],data = train, sampsize = RF_wts, replace =T, weights = BRT_wts, folds = folds)
m2 <- varSel(m1, metric = "auc", test = TRUE, bg4cor = d_env, method = "spearman", cor_th = 0.9, permut = 1, interactive = F)m3 m3 <- reduceVar(m2, th = 5, metric = "auc", test = TRUE, permut = 1, use_jk = T, interactive = F)
m4 <- optimizeModel(m3, hypers = paramsL[[j]], metric = "auc", interactive = F)
m5 <- combineCV(m4@models[[1]])
Any feedback on this process (which is taking alot of computing time) more broadly would also be appreciated.
This error is happening intermittently but I cannot determine the root cause. I have tried running SDMtune::auc(), SDMtune::predict, raster::predict(), terra::predict() to attempt to overcome any package issues, but with no success. The error also persists no matter if I use SDMmodelCV class object, or if I subset it such as model@models[[1]] etc
Reproducible example
I have done my best to provide the steps to reproduce the bug
The text was updated successfully, but these errors were encountered:
Describe the bug
Is there a preferred save and load procedure and class type for SDMmodel files? I am running numerous SDMtune models and saving them to file before loading them later on to then extract various metrics like auc() and predict() to output raster surfaces. But, I am having issues with being able to use the reloaded model objects and intermittently getting errors from them. It seems to be a class issue with the error commonly being:
"Error in UseMethod("predict") : no applicable method for 'predict' applied to an object of class "randomForest""
But, this goes for maxent, maxnet and BRT methods also. I am using saveRDS() and readRDS() to save and load SDMmodelCV class models. When I read in these objects in they look identical to when they were originally created and are of class SDMmodel or SDMmodelCV, but they are not working (sometimes) with code they have done previously when not saved and reloaded. I have written some example code below, which frustratingly worked when I ran it, but is indicative of my workflow.
For reference, these model files are based on training data and have 4 k-folds as below. I am also applying an optimisation process such that:
methods <- c('Maxnet', 'BRT', 'RF')
m1 <- SDMtune::train(method = methods[j],data = train, sampsize = RF_wts, replace =T, weights = BRT_wts, folds = folds)
m2 <- varSel(m1, metric = "auc", test = TRUE, bg4cor = d_env, method = "spearman", cor_th = 0.9, permut = 1, interactive = F)m3 m3 <- reduceVar(m2, th = 5, metric = "auc", test = TRUE, permut = 1, use_jk = T, interactive = F)
m4 <- optimizeModel(m3, hypers = paramsL[[j]], metric = "auc", interactive = F)
m5 <- combineCV(m4@models[[1]])
Any feedback on this process (which is taking alot of computing time) more broadly would also be appreciated.
Steps to reproduce the bug
Session information
Additional information
This error is happening intermittently but I cannot determine the root cause. I have tried running SDMtune::auc(), SDMtune::predict, raster::predict(), terra::predict() to attempt to overcome any package issues, but with no success. The error also persists no matter if I use SDMmodelCV class object, or if I subset it such as model@models[[1]] etc
Reproducible example
The text was updated successfully, but these errors were encountered: