ourenergy/imputer
Composer 安装命令:
composer require ourenergy/imputer
包简介
A library for filling in missing data
README 文档
README
Imputer
A library for filling in missing data by applying strategies. Inspired by php-ai/php-ml.
Installation
composer require ourenergy/imputer
Usage
Imputer works by taking a list of array keys, and a partial set of values, then filling in the gaps. A gap is any key which exists in the key list, which doesn't have a corresponding value.
Say we had a set of incomplete data;
$knownData = [ 0 => 0.5, // 1 => ??? 2 => 1.0, 3 => 1.2, // 4 => ??? 5 => 3.0 ];
We can apply a linear interpolation to guess at what the values in between might be;
$keys = [ 0, 1, 2, 3, 4, 5 ]; $knownData = [ 0 => 0.5, 2 => 1.0, 3 => 1.2, 5 => 3.0 ]; $imputer = new Imputer($keys, $knownData, new LinearInterpolation()); $result = $imputer->generate();
The result will be a completed set of data;
Array
(
[0] => 0.5
[1] => 0.75
[2] => 1
[3] => 1.2
[4] => 2.1
[5] => 3
)
Strategies
Out of the box Imputer provides a few basic strategies. You can write your own by implementing the Imputer\Strategy
interface.
Linear Interpolation
As described above, the LinearInterpolation strategy will generate a number of steps between the previous and next
known values.
e.g. 3 steps between 1.0 and 3.0 will create [1.5, 2.0, 2.5]
Weighted Interpolation
Similar to the LinearInterpolation strategy, it will interpolate missing values, but with the added capability of
applying a weight to each result. This can be useful for applying historical trends to computed data or when you don't
want a straight line between points on your graph.
$keys = range(0, 5); $knownData = [ 0 => 10, 2 => 30, 5 => 60 ]; $weights = [ 1 => 1, 3 => 0.7, 4 => 0.5 ]; $strategy = new WeightedInterpolation($weights); $imputer = new Imputer($keys, $knownData, $strategy); $result = $imputer->generate();
Will result in the following;
Array
(
[0] => 10
[1] => 20
[2] => 30
[3] => 28
[4] => 25
[5] => 60
)
Substitution
The Substitution strategy will take an existing set of values and use them to fill in any gaps.
$keys = range(0, 5); $knownData = [ 0 => 10, 2 => 30, 5 => 60 ]; $substitutes = [ 1 => 'a', 3 => 'b' ]; $strategy = new Substitution($substitutes, 'x'); $imputer = new Imputer($keys, $knownData, $strategy); $result = $imputer->generate();
Will result in the following;
Array
(
[0] => 10
[1] => a
[2] => 30
[3] => b
[4] => x
[5] => 60
)
ourenergy/imputer 适用场景与选型建议
ourenergy/imputer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 02 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ourenergy/imputer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ourenergy/imputer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-02-25