Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error to run Supervised way of classification using RandomForest for multispectral data (Mavic-3 Pro) #5

Open
IbrahimUWA opened this issue Feb 14, 2024 · 1 comment

Comments

@IbrahimUWA
Copy link

IbrahimUWA commented Feb 14, 2024

Hello,
Previously, I tried all the classification methods as mentioned on your Github and that worked. However, I am trying the supervised method using Random forest and I get the following error consistantly. Please help me out regarding this issue. It will be highly appreciated. Thank you.

Error:
classification<-fieldSegment(mosaic = Test, trainDataset = training_sam)
[1] "Starting supervised classification ..."
Error in predict.randomForest(modelFit, newdata) :
variables in the training data missing in newdata

Code:

soil<-fieldView(mosaic = Test, editor = TRUE)
soil<-st_as_sf(st_sample(soil, 200))
soil$class<-'soil'

plants<-fieldView(mosaic = Test, editor = TRUE)
plants<-st_as_sf(st_sample(plants, 200))
plants$class<-'plants'

training_sam<-rbind(soil,plants)

classification<-fieldSegment(mosaic = raster(Test), trainDataset = training_sam)

@pspawar71
Copy link
Collaborator

Hi.. @IbrahimUWA,
Try this. It will work.

classification<-fieldSegment(mosaic = Test, trainDataset = training_sam)

FIELDimageR.Extra utilizes terra library for raster operations. For more information about the functionalities of FIELDimageR.Extra and its dependencies, please refer to this publication: https://acsess.onlinelibrary.wiley.com/doi/full/10.1002/ppj2.20083

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants