Connection to specific algorithms
Linear model with feature vector
Many machine learning algorithms use the same core idea: prediction is a weighted sum of input features plus bias.
This is exactly why vectors and dimensions matter in practice: each feature has its own weight and contributes to the final result.
Example of code:
<?php
function linearModel(array $x, array $w, float $b): float {
$n = count($x);
if ($n !== count($w)) {
throw new InvalidArgumentException('Arguments x and w must have the same length');
}
$sum = $b;
for ($i = 0; $i < $n; $i++) {
$sum += $x[$i] * $w[$i];
}
return $sum;
}