forecasting_utils 模块
用于 AML 预测包的通用实用工具函数。
类
| ForecastingUtilConstants |
用于预测 utils 模块的常量。 |
函数
array_equal_with_nans
当 np.nan 存在时,测试 numpy 数组是否相等。
标准行为是 np.nan != np.nan,这是正确的。 但它增加了单元测试的难度,因此有了这个函数。 :param x:
一个 numpy 数组。
array_equal_with_nans(x, y)
参数
- y
返回
一个指示输入数组是否相等的布尔值。
flatten_list
平展(可能嵌套的)列表。
flatten_list(input_list)
参数
- input_list
一个可包含任何类型的项的列表。
返回
可从中获取平展列表的生成器类的实例。
get_period_offsets_from_dates
确定输入和引用时间索引之间的时间段差。
时间段根据时序频率来定义。
示例:
time_index = pd.date_range(start='2017-04', periods=6, freq='MS') time_index DatetimeIndex(['2017-04-01', '2017-05-01', '2017-06-01', '2017-07-01',
'2017-08-01', '2017-09-01'], dtype='datetime64[ns]', freq='MS')
>>> get_period_offsets_from_dates(pd.Timestamp('2017-03'),
... time_index, freq='MS')
array([1, 2, 3, 4, 5, 6], dtype=int64)
get_period_offsets_from_dates(reference_index, time_index, freq, misalignment_action='warn')
参数
- reference_index
- <xref:pandas.core.indexes.datetimes.DatetimeIndex>, <xref:pd._libs.tslibs.timestamps.Timestamp>
用于计算偏移的基线
- time_index
- <xref:pandas.core.indexes.datetimes.DatetimeIndex>
timedate 值
返回
整数偏移的 numpy 数组,其长度与 time_index 相同
返回类型
get_pipeline_step
get_pipeline_step(pipeline, name)
参数
- pipeline
- name
grain_level_to_dict
将粒度级别转换为字典。
dict 键由 grain_colnames 提供。 grain_level 参数通常派生自 pd.DataFrame.GroupBy 的“name”属性。 即对于 name,X.groupby(level=X.grain_colnames) 中的组:
print('grain_level is {}'.name)
grain_level_to_dict(grain_colnames, grain_level)
参数
- grain_colnames
- grain_level
invert_dict_of_lists
倒排列表字典。
根据字符串键和列表值的字典构造一个反向字典,其中列表的元素是键,初始键将放入值中的列表中。
>>> input = {'a': [1, 2], 'b': 1, 'c': [0, 2]}
>>> output = invert_dict_of_lists(input)
>>> output
>>> {0: ['c'], 1: ['b', 'a'], 2: ['c', 'a']}
invert_dict_of_lists(dictionary)
参数
返回
倒排字典。
make_groupby_map
为数据帧创建 groupby 映射。
定义组的项可能在索引、常规列集中,或同时在两者中。
此函数返回索引与 df 相同的 pandas 序列对象,而值是组标识符(作为标量或元组)。 返回的序列可以直接传递给 pd.DataFrame.groupby 作为“by”参数;pandas 将序列解释为从索引值到组的映射。
截至 Pandas 0.20.3,pd.DataFrame.groupby 对于按索引、列或两者中的项目进行分组的用例没有统一的接口。 只有在需要此常规功能时,才应使用此函数。 如果确定 groupby 项肯定在列或索引中,则分别使用常规的 pandas groupby (by=) 或 groupby (level=)。 在这种情况下,与直接分组相比,此实用工具性能要低得多。
make_groupby_map(df, groupby_cols_or_indices)
参数
- df
- groupby_cols_or_indices
subtract_list_from_list
反馈
提交和查看相关反馈