protected function to_features($calculatedvalues) {

        $classes = static::get_classes();

        foreach ($calculatedvalues as $sampleid => $calculatedvalue) {

            // Using intval as it may come as a float from the db.
            $classindex = array_search(intval($calculatedvalue), $classes, true);

            if ($classindex === false && !is_null($calculatedvalue)) {
                throw new \coding_exception(get_class($this) . ' calculated value "' . $calculatedvalue .
                    '" is not one of its defined classes (' . json_encode($classes) . ')');
            }

            // We transform the calculated value into multiple features, one for each of the possible classes.
            $features = array_fill(0, count($classes), 0);

            // 1 to the selected value.
            if (!is_null($calculatedvalue)) {
                $features[$classindex] = 1;
            }

            $calculatedvalues[$sampleid] = $features;
        }

        return $calculatedvalues;
    }
protected function to_features($calculatedvalues) {

        $classes = static::get_classes();

        foreach ($calculatedvalues as $sampleid => $calculatedvalue) {

            // Using intval as it may come as a float from the db.
            $classindex = array_search(intval($calculatedvalue), $classes, true);

            if ($classindex === false && !is_null($calculatedvalue)) {
                throw new \coding_exception(get_class($this) . ' calculated value "' . $calculatedvalue .
                    '" is not one of its defined classes (' . json_encode($classes) . ')');
            }

            // We transform the calculated value into multiple features, one for each of the possible classes.
            $features = array_fill(0, count($classes), 0);

            // 1 to the selected value.
            if (!is_null($calculatedvalue)) {
                $features[$classindex] = 1;
            }

            $calculatedvalues[$sampleid] = $features;
        }

        return $calculatedvalues;
    }
protected function to_features ( $ calculatedvalues ) { $ classes = static :: get_classes ( ) ; foreach ( $ calculatedvalues as $ sampleid => $ calculatedvalue ) { // Using intval as it may come as a float from the db. $ classindex = array_search ( intval ( $ calculatedvalue ) , $ classes , true ) ; if ( $ classindex === false && ! is_null ( $ calculatedvalue ) ) { throw new \ coding_exception ( get_class ( $ this ) . ' calculated value "' . $ calculatedvalue . '" is not one of its defined classes (' . json_encode ( $ classes ) . ')' ) ; } // We transform the calculated value into multiple features, one for each of the possible classes. $ features = array_fill ( 0 , count ( $ classes ) , 0 ) ; // 1 to the selected value. if ( ! is_null ( $ calculatedvalue ) ) { $ features [ $ classindex ] = 1 ; } $ calculatedvalues [ $ sampleid ] = $ features ; } return $ calculatedvalues ; }
From calculated values to dataset features.

One column for each class.

@param float[] $calculatedvalues
@return float[]
From calculated values to dataset features .