HannaMeyer / CAST

Developer Version of the R package CAST: Caret Applications for Spatio-Temporal models
https://hannameyer.github.io/CAST/
108 stars 30 forks source link

knndm function #71

Closed emmeb2021 closed 11 months ago

emmeb2021 commented 11 months ago

Hi! Thank you for creating this package it has been a pleasure using it so far. I am using the knndm function to see if I can better mange spatial auto correlation in my RF model, but I am having some issues at the global_validation step. I get an error: "Error in global_validation(model4) : Global performance could not be estimated because predictions were not saved. Train model with savePredictions='final'."

I figured this was to do with how the data is feeding into the knndm function, now as a classification model I don't have any reference. The parameters used in the 'trainControl' function should be okay (including the line savePredictions='final'). But I'm confused

Any assistance would be greatly appreciated I'm still a beginner! Thank you Emme

knndm_folds4 <- knndm(pts4, modeldomain=studyArea, k = 5) knndm_folds4 plot(knndm_folds4)

ctrl4 <- trainControl(method="cv", index=knndm_folds4$indx_train, savePredictions='final')

model4 <- train(abpres~., data = Train4[,-c(2:3)], method="rf", trcontrol = ctrl4) model4 lengths(model4$pred) global_validation(model4)

global_validation(model4) Error in global_validation(model4) : Global performance could not be estimated because predictions were not saved. Train model with savePredictions='final'

(Coordinate data is projected) head(pts4) abpres BtmSalinity_fall_max BtmStress_fall_max BtmStress_fall_min BtmTemp_fall_max BtmTemp_fall_min 1 abs 35.04016 0.084448554 0.0318813547 5.066860 4.3416319 3 pres 31.07378 0.003851054 0.0003281421 11.879930 4.8315330 5 pres 32.51310 0.005012250 0.0002675029 5.575860 0.2846721 6 abs 34.97558 0.047943920 0.0008219921 5.541814 3.9962437 7 pres 34.75494 0.058296647 0.0227264166 4.417707 2.7072399 8 pres 33.39942 0.019661102 0.0067749284 2.136045 -0.4165318 MLD_fall_max MLD_fall_min SurfaceTemp_fall_max geometry 1 195.44728 12.422209 9.134846 POINT (926113.1 1210112) 3 39.75787 8.601914 18.005045 POINT (-144911.3 -436612) 5 33.26155 4.898076 13.206921 POINT (491246.7 -249519.5) 6 29.63660 4.868274 22.026590 POINT (-128115.7 -818321.2) 7 33.98904 5.724236 11.875775 POINT (841782.8 -177986.8) 8 31.39414 7.639641 16.741175 POINT (483544 -490805.2)

HannaMeyer commented 11 months ago

I guess ctrl4 is currently ignored. The argument in caret::train is "trControl" not "trcontrol". Does it work when you change that ?

emmeb2021 commented 11 months ago

yup thats it! thank you!!