PHPackages                             ourenergy/imputer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ourenergy/imputer

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ourenergy/imputer
=================

A library for filling in missing data

0.2.0(7y ago)07MITPHP

Since Feb 25Pushed 7y agoCompare

[ Source](https://github.com/our-energy/imputer)[ Packagist](https://packagist.org/packages/ourenergy/imputer)[ RSS](/packages/ourenergy-imputer/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

[![Build Status](https://camo.githubusercontent.com/6252603ac89e6b09f33ae4db2388a571b53fabcb9c0d4cfa439f65596193bbf7/68747470733a2f2f7472617669732d63692e6f72672f6f75722d656e657267792f696d70757465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/our-energy/imputer)[![Latest Stable Version](https://camo.githubusercontent.com/e0f2c67006b7b0f4a92097241e9c84a1e5d31fb33026d5ff72c2327d8f81b282/68747470733a2f2f706f7365722e707567782e6f72672f6f7572656e657267792f696d70757465722f762f737461626c653f666f726d61743d666c6174)](https://packagist.org/packages/ourenergy/imputer)

Imputer
=======

[](#imputer)

A library for filling in missing data by applying strategies. Inspired by [php-ai/php-ml](https://github.com/php-ai/php-ml).

Installation
------------

[](#installation)

```
composer require ourenergy/imputer

```

Usage
-----

[](#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
----------

[](#strategies)

Out of the box Imputer provides a few basic strategies. You can write your own by implementing the `Imputer\Strategy`interface.

### Linear Interpolation

[](#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

[](#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

[](#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
)

```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

2636d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/02b7e52b569aef810afb40f3601ee78b7607362f77b7a8701dad159b9a9de926?d=identicon)[andrewjoll](/maintainers/andrewjoll)

---

Top Contributors

[![andrewjoll](https://avatars.githubusercontent.com/u/118745?v=4)](https://github.com/andrewjoll "andrewjoll (7 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ourenergy-imputer/health.svg)

```
[![Health](https://phpackages.com/badges/ourenergy-imputer/health.svg)](https://phpackages.com/packages/ourenergy-imputer)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
