Hi João!
I write you back again since we are retaking the land cover classfication of our project but with the rasters masked, they are RGB orthoimages from aerial flights. I spent some days studying what is wrong and I wonder if you could have a quick look at the code to see what is failing. I always get this error:
Error in evalPerformanceClassifier(classifObj) : The input in obj must be an object of class SOptim.Classifier generated by calibrateClassifier with option runFullCalibration = TRUE!Before that there is a warning message:
In calibrateClassifier(calData = calData, classificationMethod = "RF", ... : The number of train cases by class is below minCasesByClassTest! Unable to do performance evaluation.The train data is a integer raster with the same extent as the segmented raster. I have minimum 16 train areas for each class and the error is always the same, no matter what I change:
This is our last step, so I hope we could fix the bug easily, please find the code attached.
Thank you very much in advance!
Álvaro.
Hi Álvaro,
Thanks for your feedback. Just to put things into context, here
goes a short explanation on what is happening:
SegOptim uses cross-validation to evaluate classifier performance
which can be performed in different ways such as 10- or 5-fold CV.
This procedure partitions data into train and test sets with 10 or
5 partitions (respectively).
It is also important to note that if you have 16 train areas that
does not mean you have that many objects in training. That will
depend much on the way segmentation is parametrized to produce
large or small segments. It depends also on the spectral and
spatial characteristics of each class (which will have different
average sizes).
In your case, you have many objects but when 10-fold CV is used (with 90% for training and 10% for testing) some testing partitions have a number of objects below the minCasesByClassTest parameter (which was set to 5). See the test partition example below for your data which has only 4 objects for class 3:
## --- TRAINING ROUND 2 --- ##
.. Frequency table by class for train data:
1 2 3
106 207 39
.. Frequency table by class for test data:
1 2 3
10 24 4
This issue will produce a warning but let you finish the training step. One quick-fix for solving this issue is doing 5-fold CV which will increment the test set from 10% to 20%. This can be done by replacing the following lines of code:
classifObj <-
calibrateClassifier(calData = calData,
classificationMethod =
"RF",
balanceTrainData =
FALSE,
balanceMethod =
"ubOver",
evalMethod = "5FCV", # <<<----
Changed from 10-fold CV to 5-fold CV
evalMetric = "Kappa",
minTrainCases
= 30,
minCasesByClassTrain = 10,
minCasesByClassTest = 5,
runFullCalibration
= TRUE)
By fixing this, the evalPerformanceClassifier() function will run correctly. To calculate overall statistics across all five partitions the following lines have also to be changed:
# Calculate the average and standard
deviation of performance measures:
print(apply(evalMatrix[-6,],2,mean))
print(apply(evalMatrix[-6,],2,sd))
This will remove the sixth line in the evaluation matrix which
holds performance stats for the full training round (this round
uses the entire dataset for training without partitioning it).
Check out the modified script in attachment (don't forget to change the file paths..).
Hope it helps! 🙂 Let me know if this works for you.
Cheers
João
- - -
--
You received this message because you are subscribed to the Google Groups "SegOptim user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to segoptim-user-g...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/segoptim-user-group/f95e8363-dda2-48ca-a6b8-2afcfddeb271n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/segoptim-user-group/ebf8a563-1e30-4211-a5df-34e23a93c233n%40googlegroups.com.
Hi Álvaro,
Seems like you have too few training segments, in this case smaller than the minimum number which is defined in the minTrainCases value (set to 30).
If increasing the number of samples in the training dataset is
not enough, you may try to decrease the minimum number to: minTrainCases
= 20 (note: less than 20 is too small to train the
classifier )
Modifying segmentation parameters may help also to create smaller
segments and have a higher number of training cases for the
classification step.
Try it out and give some feedback
Cheers
- - -
--
You received this message because you are subscribed to a topic in the Google Groups "SegOptim user group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/segoptim-user-group/RYrHDLLbwvY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to segoptim-user-g...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/segoptim-user-group/20aa24f5-7c88-be36-7bc4-f2139414c727%40gmail.com.