Case 2: Estimating object relevance

Implementation in RubixML

Below is a runnable RubixML example: train Ridge on a small dataset and predict relevance for a new object.

 
<?php

use Rubix\ML\Datasets\Labeled;
use 
Rubix\ML\Datasets\Unlabeled;
use 
Rubix\ML\Regressors\Ridge;

$samples = [
    [
10, 5, 2],
    [
4, 1, 0],
    [
20, 8, 5],
];

$labels = [8, 2, 15];

$dataset = new Labeled($samples, $labels);

$model = new Ridge(1.0);
$model->train($dataset);

$newSample = [[9, 6, 4]];

$prediction = $model->predict(new Unlabeled($newSample));
print_r($prediction);
Result: Memory: 1.074 Mb Time running: 0.011 sec.
Array
(
    [0] => 8.1755577109603
)

Takeaway: RubixML lets you replace a manual formula with a model that learns from data and adapts feature contributions.