TransWikia.com

How does the randomColumn() function in Google Earth Engine work

Geographic Information Systems Asked by Floriana Spatola on January 29, 2021

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);

2 Answers

As far as I know, it depends on the NDVI values and the structure of your feature collection (I think the hash of the table header). However, the generated random numbers are not generated from the NDVI values. Also, there is no known relationship between the NDVI values and Random Numbers.

Actually, "randomColumn" creates pseudorandom numbers in a deterministic way. This makes it possible to generate reproducible pseudorandom sequence by defining "seed" parameter. In other words, given a starting value (i.e. the seed) they will always provide the same sequence of pseudo random numbers. Accordingly, same data and same seed always returns the same sequence of random numbers.

Hope it helps.

Answered by HamiEbra on January 29, 2021

The random values generated by randomColumn() have no association with the input collection - they are simply random values. According to the docs:

[randomColum] Adds a column of deterministic pseudorandom numbers to a collection. The numbers are double-precision floating point numbers in the range 0.0 (inclusive) to 1.0 (exclusive).

In the context of your analysis, the random values are used to divide your sample into training and validation sets. For instance, use all features with random values less than 0.75 for training, and those with values greater than or equal to 0.75 for validation.

Answered by Justin Braaten on January 29, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP