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