理解gluonts的AddObservedValuesIndicator的用法

# class AddObservedValuesIndicator(SimpleTransformation):
#     """
#     Replaces missing values in a numpy array (NaNs) with a dummy value and adds
#     an "observed"-indicator that is ``1`` when values are observed and ``0``
#     when values are missing.
#
#
#     Parameters
#     ----------
#     target_field
#         Field for which missing values will be replaced
#     output_field
#         Field name to use for the indicator
#     dummy_value
#         Value to use for replacing missing values.
#     convert_nans
#         If set to true (default) missing values will be replaced. Otherwise
#         they will not be replaced. In any case the indicator is included in the
#         result.
#     """
#
#     @validated()
#     def __init__(
#         self,
#         target_field: str,
#         output_field: str,
#         dummy_value: int = 0,
#         convert_nans: bool = True,
#         dtype: DType = np.float32,
#     ) -> None:
#         self.dummy_value = dummy_value
#         self.target_field = target_field
#         self.output_field = output_field
#         self.convert_nans = convert_nans
#         self.dtype = dtype
#
#     def transform(self, data: DataEntry) -> DataEntry:
#         value = data[self.target_field]
#         nan_indices = np.where(np.isnan(value))
#         nan_entries = np.isnan(value)
#
#         if self.convert_nans:
#             value[nan_indices] = self.dummy_value
#
#         data[self.target_field] = value
#         # Invert bool array so that missing values are zeros and store as float
#         data[self.output_field] = np.invert(nan_entries).astype(self.dtype)
#         return data

#知识点:
#1.AddObservedValuesIndicator功能:检查观测值是否缺失,若用一个变量记录是否缺失;
#2.掌握np.isnan,np.where,np.invert的用法;
#3.DataEntry提示数据类型,无实际具体消耗。

from gluonts.transform import AddObservedValuesIndicator
import numpy as np
if __name__ == '__main__':
    data={'target':np.array([1,2,3,np.nan])}
    aovi=AddObservedValuesIndicator('target','output'
    print(aovi.transform(data))
    #{'target': array([1., 2., 3., 0.]), 'output': array([1., 1., 1., 0.], dtype=float32)}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值