ee.FeatureCollection.randomColumn

เพิ่มคอลัมน์ของตัวเลขแบบสุ่มจำลองที่แน่นอนลงในคอลเล็กชัน ผลลัพธ์คือจำนวนจุดลอยตัวแบบละเอียด เมื่อใช้การแจกแจงแบบ "สม่ำเสมอ" (ค่าเริ่มต้น) เอาต์พุตจะอยู่ในช่วง [0, 1) เมื่อใช้การแจกแจงแบบ "ปกติ" เอาต์พุตจะมีค่า μ=0, σ=1 แต่ไม่มีขีดจำกัดที่ชัดเจน

การใช้งานการคืนสินค้า
FeatureCollection.randomColumn(columnName, seed, distribution, rowKeys)FeatureCollection
อาร์กิวเมนต์ประเภทรายละเอียด
this: collectionFeatureCollectionคอลเล็กชันอินพุตที่จะเพิ่มคอลัมน์แบบสุ่ม
columnNameสตริง โดยค่าเริ่มต้นคือ "random"ชื่อของคอลัมน์ที่จะเพิ่ม
seedตัวเลขยาว ค่าเริ่มต้น: 0เมล็ดที่ใช้เมื่อสร้างตัวเลขสุ่ม
distributionสตริง โดยค่าเริ่มต้นคือ "uniform"ประเภทการแจกแจงของตัวเลขสุ่มที่จะสร้าง ซึ่งอาจเป็น "แบบสม่ำเสมอ" หรือ "แบบปกติ"
rowKeysรายการ (ไม่บังคับ)รายการพร็อพเพอร์ตี้ที่ควรระบุองค์ประกอบของคอลเล็กชันโดยไม่ซ้ำกันและใช้ซ้ำได้ ซึ่งจะใช้สร้างเลขสุ่ม ค่าเริ่มต้นคือ [system:index]

ตัวอย่าง

เครื่องมือแก้ไขโค้ด (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 API และการใช้ geemap สําหรับการพัฒนาแบบอินเทอร์แอกทีฟได้ที่หน้า สภาพแวดล้อม Python

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