ee.FeatureCollection.randomColumn

הוספת עמודה של מספרים פסאודו-אקראיים דטרמיניסטיים לאוסף. הפלט הוא מספרים של נקודה צפה (floating-point) ברמת דיוק כפולה. כשמשתמשים בהתפלגות 'uniform' (ברירת המחדל), הפלט נמצא בטווח [0, 1). כשמשתמשים בהתפלגות 'נורמלית', הערכים של הפלט הם μ=0, σ=1, אבל אין להם מגבלות מפורשות.

שימושהחזרות
FeatureCollection.randomColumn(columnName, seed, distribution, rowKeys)FeatureCollection
ארגומנטסוגפרטים
זה: collectionFeatureCollectionאוסף הקלט שאליו רוצים להוסיף עמודה אקראית.
columnNameמחרוזת, ברירת המחדל: 'random'השם של העמודה שרוצים להוסיף.
seedארוך, ברירת המחדל: 0זרע שמשמש ליצירת המספרים האקראיים.
distributionמחרוזת, ברירת המחדל: uniformסוג ההתפלגות של המספרים האקראיים שייווצרו. אפשר לבחור באפשרויות 'עקבי' או 'נורמלי'.
rowKeysרשימה, אופציונלירשימה של מאפיינים שצריכים לזהות באופן ייחודי וחזרתי אלמנט בקולקציה, המשמשת ליצירת המספר האקראי. ברירת המחדל היא [system:index].

דוגמאות

Code Editor‏ (JavaScript)

// FeatureCollection of power plants in Belgium.
var fc = ee.FeatureCollection('WRI/GPPD/power_plants')
            .filter('country_lg == "Belgium"');
print('N features in collection', fc.size());

// Add a uniform distribution random value column to the FeatureCollection.
fc = fc.randomColumn();

// Randomly split the collection into two sets, 30% and 70% of the total.
var randomSample30 = fc.filter('random < 0.3');
print('N features in 30% sample', randomSample30.size());

var randomSample70 = fc.filter('random >= 0.3');
print('N features in 70% sample', randomSample70.size());

הגדרת Python

בדף סביבת Python מפורט מידע על Python API ועל השימוש ב-geemap לפיתוח אינטראקטיבי.

import ee
import geemap.core as geemap

Colab (Python)

# FeatureCollection of power plants in Belgium.
fc = ee.FeatureCollection('WRI/GPPD/power_plants').filter(
    'country_lg == "Belgium"')
print('N features in collection:', fc.size().getInfo())

# Add a uniform distribution random value column to the FeatureCollection.
fc = fc.randomColumn()

# Randomly split the collection into two sets, 30% and 70% of the total.
random_sample_30 = fc.filter('random < 0.3')
print('N features in 30% sample:', random_sample_30.size().getInfo())

random_sample_70 = fc.filter('random >= 0.3')
print('N features in 70% sample:', random_sample_70.size().getInfo())