PHP code example of ourenergy / imputer

1. Go to this page and download the library: Download ourenergy/imputer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ourenergy / imputer example snippets


$knownData = [
    0 => 0.5,
 // 1 => ???
    2 => 1.0,
    3 => 1.2,
 // 4 => ???
    5 => 3.0
];

$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();

$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();

$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();