docstr: Choose hyperparameters, then use them to test and save a Classifier.
docstr_tok: ["Choose","hyperparameters",",","then","use","them","to","test","and","save","a","Classifier","."]
code: def run_classifier(self, hyperpartition_id=None):
      """
      Choose hyperparameters, then use them to test and save a Classifier.
      """
      # check to see if our work is done
      if self.is_datarun_finished():
          # marked the run as done successfully
          self.db.mark_datarun_complete(self.datarun.id)
          LOGGER.warning("Datarun %d has ended." % self.datarun.id)
          return
  
      try:
          LOGGER.debug("Choosing hyperparameters...")
          if hyperpartition_id is not None:
              hyperpartition = self.db.get_hyperpartition(
                  hyperpartition_id
              )
              if hyperpartition.datarun_id != self.datarun.id:
                  LOGGER.error(
                      "Hyperpartition %d is not a part of datarun %d"
                      % (hyperpartition_id, self.datarun.id)
                  )
                  return
          else:
              # use the multi-arm bandit to choose which hyperpartition to use next
              hyperpartition = self.select_hyperpartition()
  
          # use tuner to choose a set of parameters for the hyperpartition
          params = self.tune_hyperparameters(hyperpartition)
  
      except Exception:
          LOGGER.error(
              "Error choosing hyperparameters: datarun=%s"
              % str(self.datarun)
          )
          LOGGER.error(traceback.format_exc())
          raise ClassifierError()
  
      if params is None:
          LOGGER.warning(
              "No parameters chosen: hyperpartition %d is finished."
              % hyperpartition.id
          )
          return
  
      param_info = (
          'Chose parameters for method "%s":' % hyperpartition.method
      )
      for k in sorted(params.keys()):
          param_info += "\n\t%s = %s" % (k, params[k])
  
      LOGGER.info(param_info)
  
      LOGGER.debug("Creating classifier...")
      classifier = self.db.start_classifier(
          hyperpartition_id=hyperpartition.id,
          datarun_id=self.datarun.id,
          host=HOSTNAME,
          hyperparameter_values=params,
      )
  
      try:
          LOGGER.debug("Testing classifier...")
          model, metrics = self.test_classifier(
              hyperpartition.method, params
          )
          LOGGER.debug("Saving classifier...")
          self.save_classifier(classifier.id, model, metrics)
  
      except Exception:
          msg = traceback.format_exc()
          LOGGER.error(
              "Error testing classifier: datarun=%s" % str(self.datarun)
          )
          LOGGER.error(msg)
          self.db.mark_classifier_errored(
              classifier.id, error_message=msg
          )
          raise ClassifierError()
  
imports: from __future__ import absolute_import, unicode_literals
  import datetime
  import imp
  import logging
  import os
  import re
  import socket
  import traceback
  import warnings
  from builtins import object, str
  from collections import defaultdict
  import boto3
  import numpy
  from atm.classifier import Model
  from atm.constants import CUSTOM_CLASS_REGEX, SELECTORS, TUNERS
  from atm.database import ClassifierStatus, DBSession
  from atm.utilities import ensure_directory, get_instance, save_metrics, save_model, update_params
label_desc: Use image node_id 10 for calling the Worker obj's underlying member method code with example usage: obj.run_classifier(hyperpartition_id) without return types