Phpml\SupportVectorMachine\DataTransformer::trainingSet PHP Method

trainingSet() public static method

public static trainingSet ( array $samples, array $labels, boolean $targets = false ) : string
$samples array
$labels array
$targets boolean
return string
    public static function trainingSet(array $samples, array $labels, bool $targets = false) : string
    {
        $set = '';
        if (!$targets) {
            $numericLabels = self::numericLabels($labels);
        }
        foreach ($labels as $index => $label) {
            $set .= sprintf('%s %s %s', $targets ? $label : $numericLabels[$label], self::sampleRow($samples[$index]), PHP_EOL);
        }
        return $set;
    }

Usage Example

Example #1
0
 public function testTransformDatasetToTrainingSet()
 {
     $samples = [[1, 1], [2, 1], [3, 2], [4, 5]];
     $labels = ['a', 'a', 'b', 'b'];
     $trainingSet = '0 1:1 2:1 ' . PHP_EOL . '0 1:2 2:1 ' . PHP_EOL . '1 1:3 2:2 ' . PHP_EOL . '1 1:4 2:5 ' . PHP_EOL;
     $this->assertEquals($trainingSet, DataTransformer::trainingSet($samples, $labels));
 }