I have an array from postgresql array with structure like this ,laravel dd($samples):
array:4 [▼
0 => array:1 [▼
0 => "8"
]
1 => array:1 [▼
0 => "10"
]
2 => array:1 [▼
0 => "17"
]
3 => array:3 [▼
0 => "11"
1 => "10"
2 => "27"
]
]
and i try to test data ,input that array to php-ml library here the link https://php-ml.readthedocs.io/en/latest/machine-learning/association/apriori/
why it getting error "Undefined offset: 1" ?
this is error detail :
protected function compileForeach($expression)
{
preg_match('/\( *(.*) +as *(.*)\)$/is', $expression, $matches);
$iteratee = trim($matches[1]);
$iteration = trim($matches[2]);
$initLoop = "\$__currentLoopData = {$iteratee}; \$__env->addLoop(\$__currentLoopData);";
$iterateLoop = '$__env->incrementLoopIndices(); $loop = $__env->getLastLoop();';
return "<?php {$initLoop} foreach(\$__currentLoopData as {$iteration}): {$iterateLoop} ?>";
}
and this my controller :
<?php
namespace App\Http\Controllers;
use App\Product;
use App\Order;
use App\OrderProduct;
use App\OrderItemset;
use Phpml\Association\Apriori;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class AprioriController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$data = OrderItemset::get('order_itemset');
$obj = json_decode($data,true);
$samples = array_column($obj, 'order_itemset');
$samples = array_map(function ($v) {
preg_match("/^\{(.+)\}$/", $v, $matches);
if ($matches[1]) {
return explode(',', $matches[1]);
}
return null;
}, $samples);
// dd($samples);
$labels = [];
$associator = new Apriori($support = 0.2, $confidence = 0.7);
$associator->train($samples, $labels);
$associator->predict(['3']);
$associator->apriori();
$associator->apriori();
//dd($associator);
]);
im newb, and and very grateful if someone helps me. sorry for my broken english. Thanks
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3cCv6Hi
via IFTTT
Aucun commentaire:
Enregistrer un commentaire