1

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);
5
  • Could you please share the pertinent code as formatted text? – Aaron Jun 8 '20 at 15:14
  • 1
  • I mean add the pertinent code as formatted text in your post as well as a link to the GE code. – Aaron Jun 8 '20 at 17:39
  • The question is unclear to me. You want to know how the "randomcolumn" function generates random number? Please give more detail. – HamiEbra Jun 9 '20 at 14:51
  • yes i want to know how the random cololumn generates random number. In this case the random number is generates from NDVI value? – Floriana Spatola Jun 9 '20 at 15:21
0

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.

0

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.

2
  • I think that in my case, the "seed parameter" are NDVI value? If i understood. – Floriana Spatola Jun 9 '20 at 18:54
  • No, it is not. You did not define any "seed" value. The randomColumn function take two argument; (columnName, seed), in the code you only provided the first one. Therefore, it uses the default value (0) for seed. – HamiEbra Jun 10 '20 at 6:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.