Does the randomColumn()
function assign an arbitrary random value as a collection element property or is it based on some aspect of the collection element?
For instance, I have a script that calls randomColumn()
on an NDVI image - does the random value added as an element property have anything to do with NDVI values?
The following is my analysis/script for context.
I made Random Forest Classifier in Google Earth Engine, and I get this:
properties: Object (4 properties)
NDVI: 0.6263543963432312
PRIM_LIV: 101
classification: 101
random: 0.489545211200769
This is code:
var fire_2007= ee.FeatureCollection('users/spatola/FIRE_2007');
//mask_cloud
function fmask(img) {
var cloudShadowBitMask = 1 << 3;
var cloudsBitMask = 1 << 5;
var qa = img.select('pixel_qa');
var mask = qa.bitwiseAnd(cloudShadowBitMask)
.eq(0)
.and(qa.bitwiseAnd(cloudsBitMask).eq(0));
return img.updateMask(mask);
}
function calcNDVI(img) {
return img.normalizedDifference(['B5', 'B4']).rename('NDVI');
}
// Define function to prepare OLI images.
function prepOli(img) {
var orig = img;
img = fmask(img);
img = calcNDVI(img);
return ee.Image(img.copyProperties(orig, orig.propertyNames()));
}
//post_2008_2017
var OLI_L8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filter(ee.Filter.eq('WRS_PATH', 188))
.filter(ee.Filter.eq('WRS_ROW', 32))
.filterBounds(fire_2007)
.filterDate('2013-04-01', '2017-12-31')
.map(prepOli)
.set('system:time_start',2017);
//convert ImageCollection to Image as Bands
var mergeBands = function(image, previous) {
return ee.Image(previous).addBands(image, ["NDVI"]);
};
var merged= ee.Image(OLI_L8.iterate(mergeBands, ee.Image([])));
//Random forest
//BUILD TRAINING
var bands= ["NDVI"];
var classProperty= 'PRIM_LIV';
var training= merged.select(bands).sampleRegions({
collection: fire_2007,
properties: [classProperty],
scale:30,
tileScale: 16,
});
print(training.first())
//Train
var random= training.randomColumn('random');
var split_train= 0.7;
var split_test= 0.4;
var trainPartition= random.filter(ee.Filter.lt('random',split_train));
var testPartition= random.filter(ee.Filter.gte('random',split_test));
//apply_randomForest
var trainedClassifier = ee.Classifier.smileRandomForest(10).train({
features: trainPartition,
classProperty: classProperty,
inputProperties: bands
});
print(trainedClassifier);
var test = testPartition.classify(trainedClassifier);
print(test.first());
var confusionMatrix = test.errorMatrix(classProperty, 'classification');
print('Confusion Matrix', confusionMatrix);