ee.FeatureCollection.randomColumn
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เพิ่มคอลัมน์ของตัวเลขแบบสุ่มจำลองที่แน่นอนลงในคอลเล็กชัน ผลลัพธ์คือจำนวนจุดลอยตัวแบบละเอียด เมื่อใช้การแจกแจงแบบ "สม่ำเสมอ" (ค่าเริ่มต้น) เอาต์พุตจะอยู่ในช่วง [0, 1) เมื่อใช้การแจกแจงแบบ "ปกติ" เอาต์พุตจะมีค่า μ=0, σ=1 แต่ไม่มีขีดจำกัดที่ชัดเจน
การใช้งาน | การคืนสินค้า |
---|
FeatureCollection.randomColumn(columnName, seed, distribution, rowKeys) | FeatureCollection |
อาร์กิวเมนต์ | ประเภท | รายละเอียด |
---|
this: collection | FeatureCollection | คอลเล็กชันอินพุตที่จะเพิ่มคอลัมน์แบบสุ่ม |
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())
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-25 UTC
[null,null,["อัปเดตล่าสุด 2025-07-25 UTC"],[],["This tool adds a column of pseudorandom numbers to a FeatureCollection. Users can specify the `columnName`, `seed`, and `distribution`. The default distribution, 'uniform', generates numbers between 0 and 1; 'normal' produces numbers with a mean of 0 and a standard deviation of 1. The `randomColumn` method returns the modified FeatureCollection. This is exemplified by creating random splits into subsets. The outputs are double-precision floating point numbers.\n"],null,[]]