docstr: Get best model of a given family/algorithm for a given criterion from an AutoML object.
  
  :param algorithm: One of "basemodel", "deeplearning", "drf", "gbm", "glm", "stackedensemble", "xgboost".
                    If None, pick the best model regardless of the algorithm.
  :param criterion: Criterion can be one of the metrics reported in leaderboard. If set to None, the same ordering
                    as in the leaderboard will be used.
                    Avaliable criteria:
                      - Regression metrics: deviance, rmse, mse, mae, rmsle
                      - Binomial metrics: auc, logloss, aucpr, mean_per_class_error, rmse, mse
                      - Multinomial metrics: mean_per_class_error, logloss, rmse, mse
                    The following additional leaderboard information can be also used as a criterion:
                      - 'training_time_ms': column providing the training time of each model in milliseconds (doesn't include the training of cross validation models).
                      - 'predict_time_per_row_ms`: column providing the average prediction time by the model for a single row.
  :return: An H2OModel or None if no model of a given family is present
  
  :examples:
  
  >>> # Set up an H2OAutoML object
  >>> aml = H2OAutoML(max_runtime_secs=30)
  >>> # Launch an AutoML run
  >>> aml.train(y=y, training_frame=train)
  >>> gbm = aml.get_best_model("gbm")
docstr_tok: ["Get","best","model","of","a","given","family\/algorithm","for","a","given","criterion","from","an","AutoML","object",".",":","param","algorithm",":","One","of","``","basemodel","''",",","``","deeplearning","''",",","``","drf","''",",","``","gbm","''",",","``","glm","''",",","``","stackedensemble","''",",","``","xgboost","''",".","If","None",",","pick","the","best","model","regardless","of","the","algorithm",".",":","param","criterion",":","Criterion","can","be","one","of","the","metrics","reported","in","leaderboard",".","If","set","to","None",",","the","same","ordering","as","in","the","leaderboard","will","be","used",".","Avaliable","criteria",":","-","Regression","metrics",":","deviance",",","rmse",",","mse",",","mae",",","rmsle","-","Binomial","metrics",":","auc",",","logloss",",","aucpr",",","mean_per_class_error",",","rmse",",","mse","-","Multinomial","metrics",":","mean_per_class_error",",","logloss",",","rmse",",","mse","The","following","additional","leaderboard","information","can","be","also","used","as","a","criterion",":","-","'training_time_ms","'",":","column","providing","the","training","time","of","each","model","in","milliseconds","(","does","n't","include","the","training","of","cross","validation","models",")",".","-","'predict_time_per_row_ms","`",":","column","providing","the","average","prediction","time","by","the","model","for","a","single","row",".",":","return",":","An","H2OModel","or","None","if","no","model","of","a","given","family","is","present",":","examples",":",">",">",">","#","Set","up","an","H2OAutoML","object",">",">",">","aml","=","H2OAutoML","(","max_runtime_secs=30",")",">",">",">","#","Launch","an","AutoML","run",">",">",">","aml.train","(","y=y",",","training_frame=train",")",">",">",">","gbm","=","aml.get_best_model","(","``","gbm","''",")"]
code: def get_best_model(self, algorithm=None, criterion=None):
      """
      Get best model of a given family/algorithm for a given criterion from an AutoML object.
  
      :param algorithm: One of "basemodel", "deeplearning", "drf", "gbm", "glm", "stackedensemble", "xgboost".
                        If None, pick the best model regardless of the algorithm.
      :param criterion: Criterion can be one of the metrics reported in leaderboard. If set to None, the same ordering
                        as in the leaderboard will be used.
                        Avaliable criteria:
                          - Regression metrics: deviance, rmse, mse, mae, rmsle
                          - Binomial metrics: auc, logloss, aucpr, mean_per_class_error, rmse, mse
                          - Multinomial metrics: mean_per_class_error, logloss, rmse, mse
                        The following additional leaderboard information can be also used as a criterion:
                          - 'training_time_ms': column providing the training time of each model in milliseconds (doesn't include the training of cross validation models).
                          - 'predict_time_per_row_ms`: column providing the average prediction time by the model for a single row.
      :return: An H2OModel or None if no model of a given family is present
  
      :examples:
  
      >>> # Set up an H2OAutoML object
      >>> aml = H2OAutoML(max_runtime_secs=30)
      >>> # Launch an AutoML run
      >>> aml.train(y=y, training_frame=train)
      >>> gbm = aml.get_best_model("gbm")
      """
      from h2o.exceptions import H2OValueError
  
      def _get_models(leaderboard):
          return [
              m[0]
              for m in leaderboard["model_id"].as_data_frame(
                  use_pandas=False, header=False
              )
          ]
  
      higher_is_better = ["auc", "aucpr"]
  
      assert_is_type(algorithm, None, str)
      assert_is_type(criterion, None, str)
  
      if criterion is not None:
          criterion = criterion.lower()
  
      if "deviance" == criterion:
          criterion = "mean_residual_deviance"
  
      if algorithm is not None:
          if algorithm.lower() not in (
              "basemodel",
              "deeplearning",
              "drf",
              "gbm",
              "glm",
              "stackedensemble",
              "xgboost",
          ):
              raise H2OValueError(
                  'Algorithm "{}" is not supported!'.format(algorithm)
              )
          algorithm = algorithm.lower()
  
      extra_cols = ["algo"]
      if criterion in ("training_time_ms", "predict_time_per_row_ms"):
          extra_cols.append(criterion)
  
      leaderboard = h2o.automl.get_leaderboard(
          self, extra_columns=extra_cols
      )
      leaderboard = (
          leaderboard
          if algorithm is None
          else (
              leaderboard[leaderboard["algo"].tolower() == algorithm, :]
              if algorithm != "basemodel"
              else leaderboard[
                  leaderboard["algo"].tolower() != "stackedensemble", :
              ]
          )
      )
  
      if leaderboard.nrow == 0:
          return None
  
      if criterion is None:
          return h2o.get_model(leaderboard[0, "model_id"])
  
      if criterion not in leaderboard.columns:
          raise H2OValueError(
              'Criterion "{}" is not present in the leaderboard!'.format(
                  criterion
              )
          )
  
      models_in_default_order = _get_models(leaderboard)
      sorted_lb = leaderboard.sort(
          by=criterion, ascending=criterion not in higher_is_better
      )
      selected_models = _get_models(
          sorted_lb[sorted_lb[criterion] == sorted_lb[0, criterion]]
      )
      picked_model = [
          model
          for model in models_in_default_order
          if model in selected_models
      ][0]
  
      return h2o.get_model(picked_model)
  
imports: import h2o
  from h2o.base import Keyed
  from h2o.exceptions import H2OValueError
  from h2o.job import H2OJob
  from h2o.model import ModelBase
  from h2o.utils.compatibility import *
  from h2o.utils.typechecks import assert_is_type, is_type
label_desc: Use image node_id 10 for calling the H2OAutoMLBaseMixin obj's underlying member method code with example usage: obj.get_best_model(algorithm, criterion) and returns: h2o, unknown, None, h2o