GEE 教程:如何实现对指定矢量集合的归一化操作(以北京市各区县面积和边长为例)

简介

数据归一化处理是指将数据按照一定的规则进行变换,使数据落入一个特定的区间范围内。数据归一化处理的目的是消除数据之间的量纲差异,同时保留数据的分布特征,以便更好地进行数据分析和建模。

常见的数据归一化方法有如下几种:

1. 线性归一化(Min-Max Scaling):将数据线性映射到[0,1]区间内,公式如下:
   X_normalized = (X - X_min) / (X_max - X_min)

   其中,X为原始数据,X_normalized为归一化后的数据,X_min和X_max分别为数据的最小和最大值。

2. Z-score标准化(Standardization):将数据转化为均值为0,标准差为1的分布,公式如下:
   X_standardized = (X - X_mean) / X_std

   其中,X为原始数据,X_standardized为标准化后的数据,X_mean为数据的平均值,X_std为数据的标准差。

3. 小数定标标准化(Decimal Scaling):将数据移到小数点后一位,并除以移动的位数,使数据落入[-1,1]区间内,公式如下:
   X_scaled = X / 10^k

   其中,X为原始数据,X_scaled为定标标准化后的数据,k为使数据落入[-1,1]区间所移动的位数。

数据归一化处理可以消除数据之间的量纲差异,使得不同量纲的数据具有可比性;同时,归一化后的数据也更适合进行某些机器学习算法的训练,如K-means聚类算法。

函数

reduceColumns(reducer, selectors, weightSelectors)

Apply a reducer to each element of a collection, using the given selectors to determine the inputs.

Returns a dictionary of results, keyed with the output names.

使用给定的选择器确定输入,对集合的每个元素应用一个减法器。

返回以输出名称为关键字的结果字典。

Arguments:

this:collection (FeatureCollection):

The collection to aggregate over.

reducer (Reducer):

The reducer to apply.

selectors (List):

A selector for each input of the reducer.

weightSelectors (List, default: null):

A selector for each weighted input of the reducer.

Returns: Dictionary

repeat(count)

Creates a Reducer by combining the specified number of copies of the given reducer. Output names are the same as the given reducer, but each is a list of the corresponding output from each of the reducers.

通过合并指定数量的还原器副本创建还原器。输出名称与给定的还原器相同,但每个还原器的输出都是一个列表。

Arguments:

this:reducer (Reducer)

count (Integer):

The number of copies of the reducer to combine.

Returns: Reducer

ee.Dictionary.fromLists(keys, values)

Construct a dictionary from two parallel lists of keys and values.

Arguments:

keys (List):

A list of keys.

values (List):

A list of values.

Returns: Dictionary

toDictionary(properties)

Extract properties from a feature as a dictionary.

Arguments:

this:element (Element):

The feature to extract the property from.

properties (List, default: null):

The list of properties to extract. Defaults to all non-system properties.

Returns: Dictionary

代码

//加载矢量集合或者属性表
var lucas = ee.FeatureCollection("JRC/LUCAS_HARMO/THLOC/V1");

//我们设定限制200
var exampleFC = lucas.limit(200);

// 我们分别获取你想要获取的属性名称
var listOfProps =  ['year','id'];
var minMax = exampleFC.reduceColumns(ee.Reducer.minMax().repeat(2), listOfProps);
var minDict = ee.Dictionary.fromLists(listOfProps, minMax.get('min'));
var maxDict = ee.Dictionary.fromLists(listOfProps, minMax.get('max'));

//打印查看一下结果
print('minMax',minMax)
print('minDict',minDict)
print('maxDict',maxDict)

// 进行归一化处理,这里注意需要县蒋每一个矢量进行子电话处理
var exampleFC_norm = exampleFC.map(function(f){
  var f_dict = f.toDictionary(listOfProps);
  var f_dict_norm = f_dict.map(function(property, value){
    return ee.Number(value).subtract(minDict.get(property)).divide(
            ee.Number(maxDict.get(property)).subtract(minDict.get(property)))
    });
  return f.set(f_dict_norm)
});

//查看归一化后的结果
print(exampleFC_norm.first())

结果

北京市案例1

var  table = ee.FeatureCollection("users/bqt2000204051/Beijing");

var exampleFC = table;


var listOfProps =  ['Shape_Area','Shape_Leng'];
var minMax = exampleFC.reduceColumns(ee.Reducer.minMax().repeat(2), listOfProps);
var minDict = ee.Dictionary.fromLists(listOfProps, minMax.get('min'));
var maxDict = ee.Dictionary.fromLists(listOfProps, minMax.get('max'));

print('minMax',minMax)
print('minDict',minDict)
print('maxDict',maxDict)


var exampleFC_norm = exampleFC.map(function(f){
  var f_dict = f.toDictionary(listOfProps);
  var f_dict_norm = f_dict.map(function(property, value){
    return ee.Number(value).subtract(minDict.get(property)).divide(
            ee.Number(maxDict.get(property)).subtract(minDict.get(property)))
    });
  return f.set(f_dict_norm)
});

print(exampleFC_norm.first())

矢量表 

 

结果

  • 31
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

此星光明

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值