简体   繁体   中英

Can PHP ML have multiple label values?

According to the example given here:

https://php-ml.readthedocs.io/en/latest/machine-learning/datasets/array-dataset/

One dataset can have one label. I am brand new to ML and am trying to classify articles that have multiple categories per article so is it possible to do something like the following? In effect teach the model that articles can have multiple labels or does this defeat the object.

use Phpml\Dataset\ArrayDataset;

$dataset = new ArrayDataset([[1, 1], [2, 1], [3, 2], [4, 1]], [['a','b'],['a','c'],['b','d'],['b','e']]);

It would appear I'm not the only one who is experiencing this - https://github.com/php-ai/php-ml/issues/423

Looking through the project code I see the use of one label.

$this->labels = array_map('strval', array_flip(array_flip($this->targets)));
    foreach ($this->labels as $label) {
        $samples = $this->getSamplesByLabel($label);
        $this->p[$label] = count($samples) / $this->sampleCount;
        $this->calculateStatistics($label, $samples);

There were other functions, though I did not see any that would take and array instead of a string.

Github: https://github.com/php-ai/php-ml

Regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM