Verified Commit 078643ed authored by Nat Okpe's avatar Nat Okpe
Browse files

Fixed issues preventing ML model from getting probability

parent d17935c3
......@@ -583,6 +583,9 @@ class Services_ML_Controller
}
} else {
$results = $this->mllib->probaSample($model, $processedFields);
if (empty($results)) {
throw new Exception("Failed to get probability. Not supported by model.");
}
foreach ($results as $itemId => $proba) {
$results[$itemId] = ['proba' => number_format($proba * 100, 2), 'fields' => []];
}
......
......@@ -191,16 +191,16 @@ class MachineLearningLib extends TikiDb_Bridge
public function probaSample($model, $processedFields)
{
$estimator = $this->getTrainedModel($model);
if (! method_exists($estimator, 'probaSample')) {
return [];
}
$sample = [];
foreach ($processedFields as $field) {
$value = TikiLib::lib('trk')->field_render_value([
'field' => $field,
]);
$sample[] = $value;
$sample[] = $field['type'] === "n" ? floatval($field['value']) : $field['value'];
}
$estimator = $this->getTrainedModel($model);
$result = $estimator->probaSample($sample);
$result = array_filter($result);
arsort($result);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment