GlobWetlandAfrica / GWA_scripts

Collection of QGIS Processing scripts developed for GWAIII
0 stars 7 forks source link

Error in randomForest.default(data[, 1:(ncol(data) - 1)], as.factor(data$LUC), : NA not permitted in predictors #40

Open 01zeng opened 3 years ago

01zeng commented 3 years ago

Hi, I want to do a classification following the workflow steps and I have created the training sample with ArcGis Pro. Bu I cannot really undestand this error occuring :

# run random forest classifier
RandomForestModel 
Error in randomForest.default(data[, 1:(ncol(data) - 1)], as.factor(data$LUC), :
NA not permitted in predictors
Calls: randomForest -> randomForest.default
Execution halted
Converting outputs
Loading resulting layers

Log message : 
Error in randomForest.default(data[, 1:(ncol(data) - 1)], as.factor(data$LUC),  :
            NA not permitted in predictors
            Calls: randomForest -> randomForest.default
            Execution halted
2021-05-29T19:55:15 2   Error loading result layer:
            Traceback (most recent call last):
              File "C:/Users/senghor/.qgis2/python/plugins\processing\gui\Postprocessing.py", line 79, in handleAlgorithmResults
                isRaster)
              File "C:/Users/senghor/.qgis2/python/plugins\processing\tools\dataobjects.py", line 186, in load
                + '\nCheck the processing framework log to look for errors')
            RuntimeError: Could not load layer: C:/Users/senghor/OneDrive - unige.ch/Bureau/Classification/02_RFC_Delta5.tif
            Check the processing framework log to look for errors

Someone could help ?

j08lue commented 3 years ago

The final error message just tells you that the output file was not produced. But the real source of the error was this:

NA not permitted in predictors

Which means that your input data contained some nodata values (NaN or so), it seems. Maybe @kegro can confirm?

kegro commented 3 years ago

Yes the imagery you are using seems to have NA values in areas used for training the model. I think it is ok is the to have NA values in the .tif in general, but not in the training areas. Try to remove NA value from your training polygons/points.

01zeng commented 3 years ago

Hi thanks for your feedback.

However, I had a look on the attribute table but did not find any missing value. I thought then, it could be on a another location that I ignore. May you please recommend one or two ways of removing NA value ? If there is any useful option for removing those NA value from the training polygons, that would be really helpful, I am working with different images and this error occurred several times.

Thanks in advance for your recommendation. Best.

PS: I use either ArcgisPro or SCP plugin from QGIS to create the samples

kegro commented 3 years ago

There may be some confusion here. I'm not suggesting that you training labels have NA values, but that it looks like your imagery has NA values somewhere that overlap with you training polygons. Check do you have NA values in you image (for example along image edges), and look to see if your training polygons overlap with these.