original_string: public function train_classification($uniqueid, \stored_file $dataset, $outputdir) {
  
          $modelfilepath = $this->get_model_filepath($outputdir);
  
          $modelmanager = new ModelManager();
  
          if (file_exists($modelfilepath)) {
              $classifier = $modelmanager->restoreFromFile($modelfilepath);
          } else {
              $classifier = new \Phpml\Classification\Linear\LogisticRegression(self::TRAIN_ITERATIONS, Normalizer::NORM_L2);
          }
  
          $fh = $dataset->get_content_file_handle();
  
          // The first lines are var names and the second one values.
          $metadata = $this->extract_metadata($fh);
  
          // Skip headers.
          fgets($fh);
  
          $samples = array();
          $targets = array();
          while (($data = fgetcsv($fh)) !== false) {
              $sampledata = array_map('floatval', $data);
              $samples[] = array_slice($sampledata, 0, $metadata['nfeatures']);
              $targets[] = intval($data[$metadata['nfeatures']]);
  
              $nsamples = count($samples);
              if ($nsamples === self::BATCH_SIZE) {
                  // Training it batches to avoid running out of memory.
  
                  $classifier->partialTrain($samples, $targets, array(0, 1));
                  $samples = array();
                  $targets = array();
              }
              if (empty($morethan1sample) && $nsamples > 1) {
                  $morethan1sample = true;
              }
          }
          fclose($fh);
  
          if (empty($morethan1sample)) {
              $resultobj = new \stdClass();
              $resultobj->status = \core_analytics\model::NO_DATASET;
              $resultobj->info = array();
              return $resultobj;
          }
  
          // Train the remaining samples.
          if ($samples) {
              $classifier->partialTrain($samples, $targets, array(0, 1));
          }
  
          $resultobj = new \stdClass();
          $resultobj->status = \core_analytics\model::OK;
          $resultobj->info = array();
  
          // Store the trained model.
          $modelmanager->saveToFile($classifier, $modelfilepath);
  
          return $resultobj;
      }
code: public function train_classification($uniqueid, \stored_file $dataset, $outputdir) {
  
          $modelfilepath = $this->get_model_filepath($outputdir);
  
          $modelmanager = new ModelManager();
  
          if (file_exists($modelfilepath)) {
              $classifier = $modelmanager->restoreFromFile($modelfilepath);
          } else {
              $classifier = new \Phpml\Classification\Linear\LogisticRegression(self::TRAIN_ITERATIONS, Normalizer::NORM_L2);
          }
  
          $fh = $dataset->get_content_file_handle();
  
          // The first lines are var names and the second one values.
          $metadata = $this->extract_metadata($fh);
  
          // Skip headers.
          fgets($fh);
  
          $samples = array();
          $targets = array();
          while (($data = fgetcsv($fh)) !== false) {
              $sampledata = array_map('floatval', $data);
              $samples[] = array_slice($sampledata, 0, $metadata['nfeatures']);
              $targets[] = intval($data[$metadata['nfeatures']]);
  
              $nsamples = count($samples);
              if ($nsamples === self::BATCH_SIZE) {
                  // Training it batches to avoid running out of memory.
  
                  $classifier->partialTrain($samples, $targets, array(0, 1));
                  $samples = array();
                  $targets = array();
              }
              if (empty($morethan1sample) && $nsamples > 1) {
                  $morethan1sample = true;
              }
          }
          fclose($fh);
  
          if (empty($morethan1sample)) {
              $resultobj = new \stdClass();
              $resultobj->status = \core_analytics\model::NO_DATASET;
              $resultobj->info = array();
              return $resultobj;
          }
  
          // Train the remaining samples.
          if ($samples) {
              $classifier->partialTrain($samples, $targets, array(0, 1));
          }
  
          $resultobj = new \stdClass();
          $resultobj->status = \core_analytics\model::OK;
          $resultobj->info = array();
  
          // Store the trained model.
          $modelmanager->saveToFile($classifier, $modelfilepath);
  
          return $resultobj;
      }
code_tokens: public function train_classification ( $ uniqueid , \ stored_file $ dataset , $ outputdir ) { $ modelfilepath = $ this -> get_model_filepath ( $ outputdir ) ; $ modelmanager = new ModelManager ( ) ; if ( file_exists ( $ modelfilepath ) ) { $ classifier = $ modelmanager -> restoreFromFile ( $ modelfilepath ) ; } else { $ classifier = new \ Phpml \ Classification \ Linear \ LogisticRegression ( self :: TRAIN_ITERATIONS , Normalizer :: NORM_L2 ) ; } $ fh = $ dataset -> get_content_file_handle ( ) ; // The first lines are var names and the second one values. $ metadata = $ this -> extract_metadata ( $ fh ) ; // Skip headers. fgets ( $ fh ) ; $ samples = array ( ) ; $ targets = array ( ) ; while ( ( $ data = fgetcsv ( $ fh ) ) !== false ) { $ sampledata = array_map ( 'floatval' , $ data ) ; $ samples [ ] = array_slice ( $ sampledata , 0 , $ metadata [ 'nfeatures' ] ) ; $ targets [ ] = intval ( $ data [ $ metadata [ 'nfeatures' ] ] ) ; $ nsamples = count ( $ samples ) ; if ( $ nsamples === self :: BATCH_SIZE ) { // Training it batches to avoid running out of memory. $ classifier -> partialTrain ( $ samples , $ targets , array ( 0 , 1 ) ) ; $ samples = array ( ) ; $ targets = array ( ) ; } if ( empty ( $ morethan1sample ) && $ nsamples > 1 ) { $ morethan1sample = true ; } } fclose ( $ fh ) ; if ( empty ( $ morethan1sample ) ) { $ resultobj = new \ stdClass ( ) ; $ resultobj -> status = \ core_analytics \ model :: NO_DATASET ; $ resultobj -> info = array ( ) ; return $ resultobj ; } // Train the remaining samples. if ( $ samples ) { $ classifier -> partialTrain ( $ samples , $ targets , array ( 0 , 1 ) ) ; } $ resultobj = new \ stdClass ( ) ; $ resultobj -> status = \ core_analytics \ model :: OK ; $ resultobj -> info = array ( ) ; // Store the trained model. $ modelmanager -> saveToFile ( $ classifier , $ modelfilepath ) ; return $ resultobj ; }
docstring: Train this processor classification model using the provided supervised learning dataset.
  
  @param string $uniqueid
  @param \stored_file $dataset
  @param string $outputdir
  @return \stdClass
docstring_tokens: Train this processor classification model using the provided supervised learning dataset .