Vector dimension
Vector dimension validation (predict)
In machine learning, vector dimension usually means the number of features in a single sample. In PHP this is most often just an array of numbers with a fixed length.
If a model expects 10 features and you pass 9 or 11, this is a different input and the calculation is no longer meaningful. In practice, validating the expected vector size before computing is a simple and useful guardrail.
Example of code:
<?php
function vectorPredict(array $features): float {
if (count($features) !== 10) {
throw new InvalidArgumentException('Expecting a vector of dimension 10');
}
// Further calculations
return 0.75;
}