Vector dimension

Vector dimension validation (predict)

Below is a minimal example: the predict function expects an array of 10 numbers and throws an exception if the dimension does not match.

 
<?php

function vectorPredict(array $features): float {
    if (
count($features) !== 10) {
        throw new 
InvalidArgumentException('Expecting a vector of dimension 10');
    }

    
// Further calculations
    
return 0.75;
}

try {
    
$features = [0.120.850.330.670.910.440.580.760.290.50];

    
$result vectorPredict($features);
    echo 
'Model score: ' round($result3) . PHP_EOL;

    
// Result interpretation
    
if ($result 0.7) {
        echo 
'High probability of a positive outcome';
    } elseif (
$result 0.4) {
        echo 
'Medium probability';
    } else {
        echo 
'Low probability';
    }
} catch (
Exception $e) {
    echo 
'Error: ' $e->getMessage();
}
Result: Memory: 0.001 Mb Time running: < 0.001 sec.
Model score: 0.75
High probability of a positive outcome

The idea is straightforward: dimension is a contract between the data pipeline and the model. In production, such checks help you detect feature-generation bugs early.