original_string: public function train() {
  
          \core_analytics\manager::check_can_manage_models();
  
          if ($this->is_static()) {
              $this->get_analyser()->add_log(get_string('notrainingbasedassumptions', 'analytics'));
              $result = new \stdClass();
              $result->status = self::OK;
              return $result;
          }
  
          if (!$this->is_enabled() || empty($this->model->timesplitting)) {
              throw new \moodle_exception('invalidtimesplitting', 'analytics', '', $this->model->id);
          }
  
          if (empty($this->get_indicators())) {
              throw new \moodle_exception('errornoindicators', 'analytics');
          }
  
          $this->heavy_duty_mode();
  
          // Before get_labelled_data call so we get an early exception if it is not writable.
          $outputdir = $this->get_output_dir(array('execution'));
  
          // Before get_labelled_data call so we get an early exception if it is not ready.
          $predictor = $this->get_predictions_processor();
  
          $datasets = $this->get_analyser()->get_labelled_data();
  
          // No training if no files have been provided.
          if (empty($datasets) || empty($datasets[$this->model->timesplitting])) {
  
              $result = new \stdClass();
              $result->status = self::NO_DATASET;
              $result->info = $this->get_analyser()->get_logs();
              return $result;
          }
          $samplesfile = $datasets[$this->model->timesplitting];
  
          // Train using the dataset.
          if ($this->get_target()->is_linear()) {
              $predictorresult = $predictor->train_regression($this->get_unique_id(), $samplesfile, $outputdir);
          } else {
              $predictorresult = $predictor->train_classification($this->get_unique_id(), $samplesfile, $outputdir);
          }
  
          $result = new \stdClass();
          $result->status = $predictorresult->status;
          $result->info = $predictorresult->info;
  
          if ($result->status !== self::OK) {
              return $result;
          }
  
          $this->flag_file_as_used($samplesfile, 'trained');
  
          // Mark the model as trained if it wasn't.
          if ($this->model->trained == false) {
              $this->mark_as_trained();
          }
  
          return $result;
      }
code: public function train() {
  
          \core_analytics\manager::check_can_manage_models();
  
          if ($this->is_static()) {
              $this->get_analyser()->add_log(get_string('notrainingbasedassumptions', 'analytics'));
              $result = new \stdClass();
              $result->status = self::OK;
              return $result;
          }
  
          if (!$this->is_enabled() || empty($this->model->timesplitting)) {
              throw new \moodle_exception('invalidtimesplitting', 'analytics', '', $this->model->id);
          }
  
          if (empty($this->get_indicators())) {
              throw new \moodle_exception('errornoindicators', 'analytics');
          }
  
          $this->heavy_duty_mode();
  
          // Before get_labelled_data call so we get an early exception if it is not writable.
          $outputdir = $this->get_output_dir(array('execution'));
  
          // Before get_labelled_data call so we get an early exception if it is not ready.
          $predictor = $this->get_predictions_processor();
  
          $datasets = $this->get_analyser()->get_labelled_data();
  
          // No training if no files have been provided.
          if (empty($datasets) || empty($datasets[$this->model->timesplitting])) {
  
              $result = new \stdClass();
              $result->status = self::NO_DATASET;
              $result->info = $this->get_analyser()->get_logs();
              return $result;
          }
          $samplesfile = $datasets[$this->model->timesplitting];
  
          // Train using the dataset.
          if ($this->get_target()->is_linear()) {
              $predictorresult = $predictor->train_regression($this->get_unique_id(), $samplesfile, $outputdir);
          } else {
              $predictorresult = $predictor->train_classification($this->get_unique_id(), $samplesfile, $outputdir);
          }
  
          $result = new \stdClass();
          $result->status = $predictorresult->status;
          $result->info = $predictorresult->info;
  
          if ($result->status !== self::OK) {
              return $result;
          }
  
          $this->flag_file_as_used($samplesfile, 'trained');
  
          // Mark the model as trained if it wasn't.
          if ($this->model->trained == false) {
              $this->mark_as_trained();
          }
  
          return $result;
      }
code_tokens: public function train ( ) { \ core_analytics \ manager :: check_can_manage_models ( ) ; if ( $ this -> is_static ( ) ) { $ this -> get_analyser ( ) -> add_log ( get_string ( 'notrainingbasedassumptions' , 'analytics' ) ) ; $ result = new \ stdClass ( ) ; $ result -> status = self :: OK ; return $ result ; } if ( ! $ this -> is_enabled ( ) || empty ( $ this -> model -> timesplitting ) ) { throw new \ moodle_exception ( 'invalidtimesplitting' , 'analytics' , '' , $ this -> model -> id ) ; } if ( empty ( $ this -> get_indicators ( ) ) ) { throw new \ moodle_exception ( 'errornoindicators' , 'analytics' ) ; } $ this -> heavy_duty_mode ( ) ; // Before get_labelled_data call so we get an early exception if it is not writable. $ outputdir = $ this -> get_output_dir ( array ( 'execution' ) ) ; // Before get_labelled_data call so we get an early exception if it is not ready. $ predictor = $ this -> get_predictions_processor ( ) ; $ datasets = $ this -> get_analyser ( ) -> get_labelled_data ( ) ; // No training if no files have been provided. if ( empty ( $ datasets ) || empty ( $ datasets [ $ this -> model -> timesplitting ] ) ) { $ result = new \ stdClass ( ) ; $ result -> status = self :: NO_DATASET ; $ result -> info = $ this -> get_analyser ( ) -> get_logs ( ) ; return $ result ; } $ samplesfile = $ datasets [ $ this -> model -> timesplitting ] ; // Train using the dataset. if ( $ this -> get_target ( ) -> is_linear ( ) ) { $ predictorresult = $ predictor -> train_regression ( $ this -> get_unique_id ( ) , $ samplesfile , $ outputdir ) ; } else { $ predictorresult = $ predictor -> train_classification ( $ this -> get_unique_id ( ) , $ samplesfile , $ outputdir ) ; } $ result = new \ stdClass ( ) ; $ result -> status = $ predictorresult -> status ; $ result -> info = $ predictorresult -> info ; if ( $ result -> status !== self :: OK ) { return $ result ; } $ this -> flag_file_as_used ( $ samplesfile , 'trained' ) ; // Mark the model as trained if it wasn't. if ( $ this -> model -> trained == false ) { $ this -> mark_as_trained ( ) ; } return $ result ; }
docstring: Trains the model using the site contents.
  
  This method prepares a dataset from the site contents (through the analyser)
  and passes it to the machine learning backends. Static models are skipped as
  they do not require training.
  
  @return \stdClass
docstring_tokens: Trains the model using the site contents .