OpenGeoHub / spatial-sampling-ml

Rmarkdown tutorial on how to generate spatial sampling and how to use resampling methods for ML
https://opengeohub.github.io/spatial-sampling-ml/
Other
13 stars 6 forks source link

Resampling using Ensemble ML (classification) #1

Open oliviafraserusda opened 2 years ago

oliviafraserusda commented 2 years ago

Do you have an example of resampling using ensemble ml (section 2.4) with classification (instead of regression)?

thengl commented 2 years ago

Yes, example is at: https://opengeohub.github.io/spatial-prediction-eml/spatial-interpolation-using-ensemble-ml.html#spatial-prediction-of-soil-types-factor-variable It works the same way - you just have to prepare the spatial grid for spatial blocking or use the landmap::train.spLearner function.

oliviafraserusda commented 2 years ago

Is it possible to predict landmap::train.spLearner across an independent geographic area SpatialPixelsDataFrame for model validation?

thengl commented 2 years ago

Yes just use argument predictionLocations. See: https://rdrr.io/cran/landmap/man/predict.spLearner.html

jpgannon commented 7 months ago

I’m having trouble using the predict() function for the purpose above (applying the model to a new geographic area). I’m hoping you can provide some guidance.

The line to create the model I’m using: mC <- train.spLearner(plots["hpu"], covariates = spdf_all_layers[,c('tpi20', 'tpi100', 'tpi200m', 'mrvbf', 'hbuaab', 'EDb', 'twid')], SL.library = SL.library, super.learner = "classif.glmnet", parallel = FALSE, oblique.coords = TRUE)

Then I am trying to use predict() to apply the model to a new geographic location. Both of the following syntax options return the same error (spdf_all_layers2 is an spdf of the new area):

BPhpu <- predict(mC, predictionLocations = spdf_all_layers2[,c('tpi20', 'tpi100', 'tpi200m', 'mrvbf', 'hbuaab', 'EDb', 'twid')])

Or

BPhpu <- predict(mC, predictionLocations = spdf_all_layers2)

Error in [.data.frame(predictionLocations@data, , object@spModel$features) : undefined columns selected

I’m using the same code to create spfd_all_layers2 as to create the initial one. All columns are named the same, the spdf has the same dimensions, projection, etc.

Are there any known frequent issues with this that I could use to help me troubleshoot? Thank you!

jpgannon commented 7 months ago

One more thing: I tried to run predict() with the exact spatial points dataframe used to build the model "spdf_all_layers" above, and it threw the same error.

oliviafraserusda commented 7 months ago

OH!!! Are your Cone/Black Pond rasters all exactly the same footprint? I've gotten a similar error when my rasters weren't all the same exact geographic extent.

For example, a topo metric stacked with NDVI derived from NAIP.

@. Olivia Fraser (she/her) National Reforestation and Nursery System Analyst Forest Service WO Forest, Range Management, & Vegetation Ecology National Forest System Cell: 603-290-3882 @*.**@*.***> www.fs.fed.ushttp://www.fs.fed.us/ [USDA Logo]https://usda.gov/[Forest Service Twitter]https://twitter.com/forestservice[USDA Facebook]https://www.facebook.com/pages/US-Forest-Service/1431984283714112 Caring for the land and serving people

From: JP Gannon @.> Sent: Friday, March 22, 2024 7:23 AM To: OpenGeoHub/spatial-sampling-ml @.> Cc: Fraser, Olivia - FS, NH @.>; Author @.> Subject: Re: [OpenGeoHub/spatial-sampling-ml] Resampling using Ensemble ML (classification) (Issue #1)

One more thing: I tried to run predict() with the exact spatial points dataframe used to build the model "spdf_all_layers" above, and it threw the same error.

- Reply to this email directly, view it on GitHubhttps://github.com/OpenGeoHub/spatial-sampling-ml/issues/1#issuecomment-2014876565, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AXO4ERLJVSGPLM26BFOKRELYZQH7XAVCNFSM5MY7L35KU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMBRGQ4DONRVGY2Q. You are receiving this because you authored the thread.Message ID: @.***>

This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately.

jpgannon commented 7 months ago

Yeah they are all derived from the same DEM. They are built in the exact same way as the input for the model.