Объявление : Все некоммерческие проекты, зарегистрированные для использования Earth Engine до
15 апреля 2025 года, должны
подтвердить некоммерческое право на сохранение доступа к Earth Engine.
ee.FeatureCollection.randomColumn
Оптимизируйте свои подборки
Сохраняйте и классифицируйте контент в соответствии со своими настройками.
Добавляет в коллекцию столбец детерминированных псевдослучайных чисел. Выходные данные представляют собой числа двойной точности с плавающей запятой. При использовании «равномерного» распределения (по умолчанию) выходные данные находятся в диапазоне [0, 1). При использовании «нормального» распределения выходные данные имеют µ=0, σ=1, но не имеют явных ограничений.
Использование | Возврат | FeatureCollection. randomColumn ( columnName , seed , distribution , rowKeys ) | FeatureCollection |
Аргумент | Тип | Подробности | это: collection | FeatureCollection | Входная коллекция, в которую нужно добавить случайный столбец. |
columnName | Строка, по умолчанию: «случайная». | Имя добавляемого столбца. |
seed | Длинный, по умолчанию: 0 | Начальное число, используемое при генерации случайных чисел. |
distribution | Строка, по умолчанию: "uniform" | Тип распределения создаваемых случайных чисел; один из «равномерных» или «нормальных». |
rowKeys | Список, необязательно | Список свойств, которые должны однозначно и повторяемо идентифицировать элемент коллекции, используемый для генерации случайного числа. По умолчанию — [система:индекс]. |
Примеры
Редактор кода (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 Python и использовании geemap
для интерактивной разработки.
import ee
import geemap.core as geemap
Колаб (Питон)
# 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())
Если не указано иное, контент на этой странице предоставляется по лицензии Creative Commons "С указанием авторства 4.0", а примеры кода – по лицензии Apache 2.0. Подробнее об этом написано в правилах сайта. Java – это зарегистрированный товарный знак корпорации Oracle и ее аффилированных лиц.
Последнее обновление: 2025-07-24 UTC.
[null,null,["Последнее обновление: 2025-07-24 UTC."],[[["\u003cp\u003e\u003ccode\u003erandomColumn()\u003c/code\u003e adds a new column of pseudorandom numbers to a FeatureCollection, with the default column name being "random".\u003c/p\u003e\n"],["\u003cp\u003eThe generated random numbers can follow either a uniform distribution ([0, 1)) or a normal distribution (μ=0, σ=1) specified using the \u003ccode\u003edistribution\u003c/code\u003e parameter.\u003c/p\u003e\n"],["\u003cp\u003eUsers can provide a seed value for reproducibility using the \u003ccode\u003eseed\u003c/code\u003e parameter, ensuring the same sequence of random numbers is generated for a given seed.\u003c/p\u003e\n"],["\u003cp\u003eThis function is commonly used for tasks like randomly splitting a FeatureCollection into subsets for training and testing machine learning models, as demonstrated in the examples.\u003c/p\u003e\n"]]],["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,["# ee.FeatureCollection.randomColumn\n\nAdds a column of deterministic pseudorandom numbers to a collection. The outputs are double-precision floating point numbers. When using the 'uniform' distribution (default), outputs are in the range of \\[0, 1). Using the 'normal' distribution, outputs have μ=0, σ=1, but have no explicit limits.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|----------------------------------------------------------------------------------------------|-------------------|\n| FeatureCollection.randomColumn`(`*columnName* `, `*seed* `, `*distribution* `, `*rowKeys*`)` | FeatureCollection |\n\n| Argument | Type | Details |\n|--------------------|----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| this: `collection` | FeatureCollection | The input collection to which to add a random column. |\n| `columnName` | String, default: \"random\" | The name of the column to add. |\n| `seed` | Long, default: 0 | A seed used when generating the random numbers. |\n| `distribution` | String, default: \"uniform\" | The distribution type of random numbers to produce; one of 'uniform' or 'normal'. |\n| `rowKeys` | List, optional | A list of properties that should uniquely and repeatably identify an element of the collection, used to generate the random number. Defaults to \\[system:index\\]. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// FeatureCollection of power plants in Belgium.\nvar fc = ee.FeatureCollection('WRI/GPPD/power_plants')\n .filter('country_lg == \"Belgium\"');\nprint('N features in collection', fc.size());\n\n// Add a uniform distribution random value column to the FeatureCollection.\nfc = fc.randomColumn();\n\n// Randomly split the collection into two sets, 30% and 70% of the total.\nvar randomSample30 = fc.filter('random \u003c 0.3');\nprint('N features in 30% sample', randomSample30.size());\n\nvar randomSample70 = fc.filter('random \u003e= 0.3');\nprint('N features in 70% sample', randomSample70.size());\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\n# FeatureCollection of power plants in Belgium.\nfc = ee.FeatureCollection('WRI/GPPD/power_plants').filter(\n 'country_lg == \"Belgium\"')\nprint('N features in collection:', fc.size().getInfo())\n\n# Add a uniform distribution random value column to the FeatureCollection.\nfc = fc.randomColumn()\n\n# Randomly split the collection into two sets, 30% and 70% of the total.\nrandom_sample_30 = fc.filter('random \u003c 0.3')\nprint('N features in 30% sample:', random_sample_30.size().getInfo())\n\nrandom_sample_70 = fc.filter('random \u003e= 0.3')\nprint('N features in 70% sample:', random_sample_70.size().getInfo())\n```"]]