From 69b68ad6912f09787bd4ce12e03f4bcb4f6f2e75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Monlla=C3=B3?= Date: Thu, 11 Apr 2019 17:57:25 +0200 Subject: [PATCH] MDL-65175 mlbackend_php: Add missing checking for number of targets --- lib/mlbackend/php/classes/processor.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/mlbackend/php/classes/processor.php b/lib/mlbackend/php/classes/processor.php index 016e86c96bb..063c44db96d 100644 --- a/lib/mlbackend/php/classes/processor.php +++ b/lib/mlbackend/php/classes/processor.php @@ -291,11 +291,15 @@ class processor implements \core_analytics\classifier, \core_analytics\regressor // We need at least 2 samples belonging to each target. $counts = array_count_values($targets); + $ntargets = count(explode(',', $metadata['targetclasses'])); foreach ($counts as $count) { if ($count < 2) { $notenoughdata = true; } } + if ($ntargets > count($counts)) { + $notenoughdata = true; + } if (!empty($notenoughdata)) { $resultobj = new \stdClass(); $resultobj->status = \core_analytics\model::NOT_ENOUGH_DATA;