I get pixel values from it using reference polygons. Extracted pixel values are in data frame, but one row represent extracted values for single pixel. In the classification I need to split the dataset into test (50%) and training (50%) by class (tree, meadow e.t.c)
I know how to split a set according to classes. However, I want values extracted for one polygon to be assigned to one of the sets (training OR test ) and they were not mixed
For this purpose I want to use the polygon ID (Object Identification). I would like to do this using the createDataPartition function. These are just two sample classes (there are many more)
Here is part of table with extracted values:
"band_1" "band_2" "band_3" "CLASS" "Id"
110 134 119 "tree" 1
112 133 118 "tree" 1
105 125 110 "tree" 2
112 132 117 "tree" 2
109 125 115 "meadow" 6
93 110 101 "meadow" 6
86 106 95 "meadow" 7
105 136 116 "meadow" 7
102 128 111 "meadow" 8
108 129 115 "meadow" 8
113 134 119 "meadow" 8
Here is code:
trainIndeks <- caret::createDataPartition(EXTRACTED$CLASS, p = 0.5, list=FALSE, times = 1)
dataTrain <- EXTRACTED[trainIndeks,]
dataTest <- EXTRACTED[-trainIndeks,]
However, I do not want to split fields with the same ID (I want a class with the same ID to be in training or test set and not not be splited)
- that's exactly what train/test splitting does. Could you please be more specific? What doesID
mean in your data set? $\endgroup$