filipematias23 / FIELDimageR.Extra

Package with new tools to support FIELDimageR software on evaluating GIS images from agriculture field trials.
GNU General Public License v3.0
18 stars 12 forks source link

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

Open IbrahimUWA opened 9 months ago

IbrahimUWA commented 9 months ago

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 commented 9 months ago

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