class_docstr: Stacked Ensemble
  
  Builds a stacked ensemble (aka "super learner") machine learning method that uses two
  or more H2O learning algorithms to improve predictive performance. It is a loss-based
  supervised learning method that finds the optimal combination of a collection of prediction
  algorithms.This method supports regression and binary classification.
  
  :examples:
  
  >>> import h2o
  >>> h2o.init()
  >>> from h2o.estimators.random_forest import H2ORandomForestEstimator
  >>> from h2o.estimators.gbm import H2OGradientBoostingEstimator
  >>> from h2o.estimators.stackedensemble import H2OStackedEnsembleEstimator
  >>> col_types = ["numeric", "numeric", "numeric", "enum",
  ...              "enum", "numeric", "numeric", "numeric", "numeric"]
  >>> data = h2o.import_file("http://h2o-public-test-data.s3.amazonaws.com/smalldata/prostate/prostate.csv", col_types=col_types)
  >>> train, test = data.split_frame(ratios=[.8], seed=1)
  >>> x = ["CAPSULE","GLEASON","RACE","DPROS","DCAPS","PSA","VOL"]
  >>> y = "AGE"
  >>> nfolds = 5
  >>> gbm = H2OGradientBoostingEstimator(nfolds=nfolds,
  ...                                    fold_assignment="Modulo",
  ...                                    keep_cross_validation_predictions=True)
  >>> gbm.train(x=x, y=y, training_frame=train)
  >>> rf = H2ORandomForestEstimator(nfolds=nfolds,
  ...                               fold_assignment="Modulo",
  ...                               keep_cross_validation_predictions=True)
  >>> rf.train(x=x, y=y, training_frame=train)
  >>> stack = H2OStackedEnsembleEstimator(model_id="ensemble",
  ...                                     training_frame=train,
  ...                                     validation_frame=test,
  ...                                     base_models=[gbm.model_id, rf.model_id])
  >>> stack.train(x=x, y=y, training_frame=train, validation_frame=test)
  >>> stack.model_performance()
class_docstr_tok: ["Stacked","Ensemble","Builds","a","stacked","ensemble","(","aka","``","super","learner","''",")","machine","learning","method","that","uses","two","or","more","H2O","learning","algorithms","to","improve","predictive","performance",".","It","is","a","loss-based","supervised","learning","method","that","finds","the","optimal","combination","of","a","collection","of","prediction","algorithms.This","method","supports","regression","and","binary","classification",".",":","examples",":",">",">",">","import","h2o",">",">",">","h2o.init","(",")",">",">",">","from","h2o.estimators.random_forest","import","H2ORandomForestEstimator",">",">",">","from","h2o.estimators.gbm","import","H2OGradientBoostingEstimator",">",">",">","from","h2o.estimators.stackedensemble","import","H2OStackedEnsembleEstimator",">",">",">","col_types","=","[","``","numeric","''",",","``","numeric","''",",","``","numeric","''",",","``","enum","''",",","...","``","enum","''",",","``","numeric","''",",","``","numeric","''",",","``","numeric","''",",","``","numeric","''","]",">",">",">","data","=","h2o.import_file","(","``","http",":","\/\/h2o-public-test-data.s3.amazonaws.com\/smalldata\/prostate\/prostate.csv","''",",","col_types=col_types",")",">",">",">","train",",","test","=","data.split_frame","(","ratios=","[",".8","]",",","seed=1",")",">",">",">","x","=","[","``","CAPSULE","''",",","''","GLEASON","''",",","''","RACE","''",",","''","DPROS","''",",","''","DCAPS","''",",","''","PSA","''",",","''","VOL","''","]",">",">",">","y","=","``","AGE","''",">",">",">","nfolds","=","5",">",">",">","gbm","=","H2OGradientBoostingEstimator","(","nfolds=nfolds",",","...","fold_assignment=","''","Modulo","''",",","...","keep_cross_validation_predictions=True",")",">",">",">","gbm.train","(","x=x",",","y=y",",","training_frame=train",")",">",">",">","rf","=","H2ORandomForestEstimator","(","nfolds=nfolds",",","...","fold_assignment=","''","Modulo","''",",","...","keep_cross_validation_predictions=True",")",">",">",">","rf.train","(","x=x",",","y=y",",","training_frame=train",")",">",">",">","stack","=","H2OStackedEnsembleEstimator","(","model_id=","''","ensemble","''",",","...","training_frame=train",",","...","validation_frame=test",",","...","base_models=","[","gbm.model_id",",","rf.model_id","]",")",">",">",">","stack.train","(","x=x",",","y=y",",","training_frame=train",",","validation_frame=test",")",">",">",">","stack.model_performance","(",")"]
docstr: :param model_id: Destination id for this model; auto-generated if not specified.
         Defaults to ``None``.
  :type model_id: Union[None, str, H2OEstimator], optional
  :param training_frame: Id of the training data frame.
         Defaults to ``None``.
  :type training_frame: Union[None, str, H2OFrame], optional
  :param response_column: Response variable column.
         Defaults to ``None``.
  :type response_column: str, optional
  :param validation_frame: Id of the validation data frame.
         Defaults to ``None``.
  :type validation_frame: Union[None, str, H2OFrame], optional
  :param blending_frame: Frame used to compute the predictions that serve as the training frame for the
         metalearner (triggers blending mode if provided)
         Defaults to ``None``.
  :type blending_frame: Union[None, str, H2OFrame], optional
  :param base_models: List of models or grids (or their ids) to ensemble/stack together. Grids are expanded to
         individual models. If not using blending frame, then models must have been cross-validated using nfolds >
         1, and folds must be identical across models.
         Defaults to ``[]``.
  :type base_models: List[str]
  :param metalearner_algorithm: Type of algorithm to use as the metalearner. Options include 'AUTO' (GLM with non
         negative weights; if validation_frame is present, a lambda search is performed), 'deeplearning' (Deep
         Learning with default parameters), 'drf' (Random Forest with default parameters), 'gbm' (GBM with default
         parameters), 'glm' (GLM with default parameters), 'naivebayes' (NaiveBayes with default parameters), or
         'xgboost' (if available, XGBoost with default parameters).
         Defaults to ``"auto"``.
  :type metalearner_algorithm: Literal["auto", "deeplearning", "drf", "gbm", "glm", "naivebayes", "xgboost"]
  :param metalearner_nfolds: Number of folds for K-fold cross-validation of the metalearner algorithm (0 to
         disable or >= 2).
         Defaults to ``0``.
  :type metalearner_nfolds: int
  :param metalearner_fold_assignment: Cross-validation fold assignment scheme for metalearner cross-validation.
         Defaults to AUTO (which is currently set to Random). The 'Stratified' option will stratify the folds
         based on the response variable, for classification problems.
         Defaults to ``None``.
  :type metalearner_fold_assignment: Literal["auto", "random", "modulo", "stratified"], optional
  :param metalearner_fold_column: Column with cross-validation fold index assignment per observation for cross-
         validation of the metalearner.
         Defaults to ``None``.
  :type metalearner_fold_column: str, optional
  :param metalearner_params: Parameters for metalearner algorithm
         Defaults to ``None``.
  :type metalearner_params: dict, optional
  :param metalearner_transform: Transformation used for the level one frame.
         Defaults to ``"none"``.
  :type metalearner_transform: Literal["none", "logit"]
  :param max_runtime_secs: Maximum allowed runtime in seconds for model training. Use 0 to disable.
         Defaults to ``0.0``.
  :type max_runtime_secs: float
  :param weights_column: Column with observation weights. Giving some observation a weight of zero is equivalent
         to excluding it from the dataset; giving an observation a relative weight of 2 is equivalent to repeating
         that row twice. Negative weights are not allowed. Note: Weights are per-row observation weights and do
         not increase the size of the data frame. This is typically the number of times a row is repeated, but
         non-integer values are supported as well. During training, rows with higher weights matter more, due to
         the larger loss function pre-factor. If you set weight = 0 for a row, the returned prediction frame at
         that row is zero and this is incorrect. To get an accurate prediction, remove all rows with weight == 0.
         Defaults to ``None``.
  :type weights_column: str, optional
  :param offset_column: Offset column. This will be added to the combination of columns before applying the link
         function.
         Defaults to ``None``.
  :type offset_column: str, optional
  :param custom_metric_func: Reference to custom evaluation function, format: `language:keyName=funcName`
         Defaults to ``None``.
  :type custom_metric_func: str, optional
  :param seed: Seed for random numbers; passed through to the metalearner algorithm. Defaults to -1 (time-based
         random number)
         Defaults to ``-1``.
  :type seed: int
  :param score_training_samples: Specify the number of training set samples for scoring. The value must be >= 0.
         To use all training samples, enter 0.
         Defaults to ``10000``.
  :type score_training_samples: int
  :param keep_levelone_frame: Keep level one frame used for metalearner training.
         Defaults to ``False``.
  :type keep_levelone_frame: bool
  :param export_checkpoints_dir: Automatically export generated models to this directory.
         Defaults to ``None``.
  :type export_checkpoints_dir: str, optional
  :param auc_type: Set default multinomial AUC type.
         Defaults to ``"auto"``.
  :type auc_type: Literal["auto", "none", "macro_ovr", "weighted_ovr", "macro_ovo", "weighted_ovo"]
  :param gainslift_bins: Gains/Lift table number of bins. 0 means disabled.. Default value -1 means automatic
         binning.
         Defaults to ``-1``.
  :type gainslift_bins: int
code: def __init__(
      self,
      model_id=None,  # type: Optional[Union[None, str, H2OEstimator]]
      training_frame=None,  # type: Optional[Union[None, str, H2OFrame]]
      response_column=None,  # type: Optional[str]
      validation_frame=None,  # type: Optional[Union[None, str, H2OFrame]]
      blending_frame=None,  # type: Optional[Union[None, str, H2OFrame]]
      base_models=[],  # type: List[str]
      metalearner_algorithm="auto",  # type: Literal["auto", "deeplearning", "drf", "gbm", "glm", "naivebayes", "xgboost"]
      metalearner_nfolds=0,  # type: int
      metalearner_fold_assignment=None,  # type: Optional[Literal["auto", "random", "modulo", "stratified"]]
      metalearner_fold_column=None,  # type: Optional[str]
      metalearner_params=None,  # type: Optional[dict]
      metalearner_transform="none",  # type: Literal["none", "logit"]
      max_runtime_secs=0.0,  # type: float
      weights_column=None,  # type: Optional[str]
      offset_column=None,  # type: Optional[str]
      custom_metric_func=None,  # type: Optional[str]
      seed=-1,  # type: int
      score_training_samples=10000,  # type: int
      keep_levelone_frame=False,  # type: bool
      export_checkpoints_dir=None,  # type: Optional[str]
      auc_type="auto",  # type: Literal["auto", "none", "macro_ovr", "weighted_ovr", "macro_ovo", "weighted_ovo"]
      gainslift_bins=-1,  # type: int
  ):
      """
      :param model_id: Destination id for this model; auto-generated if not specified.
             Defaults to ``None``.
      :type model_id: Union[None, str, H2OEstimator], optional
      :param training_frame: Id of the training data frame.
             Defaults to ``None``.
      :type training_frame: Union[None, str, H2OFrame], optional
      :param response_column: Response variable column.
             Defaults to ``None``.
      :type response_column: str, optional
      :param validation_frame: Id of the validation data frame.
             Defaults to ``None``.
      :type validation_frame: Union[None, str, H2OFrame], optional
      :param blending_frame: Frame used to compute the predictions that serve as the training frame for the
             metalearner (triggers blending mode if provided)
             Defaults to ``None``.
      :type blending_frame: Union[None, str, H2OFrame], optional
      :param base_models: List of models or grids (or their ids) to ensemble/stack together. Grids are expanded to
             individual models. If not using blending frame, then models must have been cross-validated using nfolds >
             1, and folds must be identical across models.
             Defaults to ``[]``.
      :type base_models: List[str]
      :param metalearner_algorithm: Type of algorithm to use as the metalearner. Options include 'AUTO' (GLM with non
             negative weights; if validation_frame is present, a lambda search is performed), 'deeplearning' (Deep
             Learning with default parameters), 'drf' (Random Forest with default parameters), 'gbm' (GBM with default
             parameters), 'glm' (GLM with default parameters), 'naivebayes' (NaiveBayes with default parameters), or
             'xgboost' (if available, XGBoost with default parameters).
             Defaults to ``"auto"``.
      :type metalearner_algorithm: Literal["auto", "deeplearning", "drf", "gbm", "glm", "naivebayes", "xgboost"]
      :param metalearner_nfolds: Number of folds for K-fold cross-validation of the metalearner algorithm (0 to
             disable or >= 2).
             Defaults to ``0``.
      :type metalearner_nfolds: int
      :param metalearner_fold_assignment: Cross-validation fold assignment scheme for metalearner cross-validation.
             Defaults to AUTO (which is currently set to Random). The 'Stratified' option will stratify the folds
             based on the response variable, for classification problems.
             Defaults to ``None``.
      :type metalearner_fold_assignment: Literal["auto", "random", "modulo", "stratified"], optional
      :param metalearner_fold_column: Column with cross-validation fold index assignment per observation for cross-
             validation of the metalearner.
             Defaults to ``None``.
      :type metalearner_fold_column: str, optional
      :param metalearner_params: Parameters for metalearner algorithm
             Defaults to ``None``.
      :type metalearner_params: dict, optional
      :param metalearner_transform: Transformation used for the level one frame.
             Defaults to ``"none"``.
      :type metalearner_transform: Literal["none", "logit"]
      :param max_runtime_secs: Maximum allowed runtime in seconds for model training. Use 0 to disable.
             Defaults to ``0.0``.
      :type max_runtime_secs: float
      :param weights_column: Column with observation weights. Giving some observation a weight of zero is equivalent
             to excluding it from the dataset; giving an observation a relative weight of 2 is equivalent to repeating
             that row twice. Negative weights are not allowed. Note: Weights are per-row observation weights and do
             not increase the size of the data frame. This is typically the number of times a row is repeated, but
             non-integer values are supported as well. During training, rows with higher weights matter more, due to
             the larger loss function pre-factor. If you set weight = 0 for a row, the returned prediction frame at
             that row is zero and this is incorrect. To get an accurate prediction, remove all rows with weight == 0.
             Defaults to ``None``.
      :type weights_column: str, optional
      :param offset_column: Offset column. This will be added to the combination of columns before applying the link
             function.
             Defaults to ``None``.
      :type offset_column: str, optional
      :param custom_metric_func: Reference to custom evaluation function, format: `language:keyName=funcName`
             Defaults to ``None``.
      :type custom_metric_func: str, optional
      :param seed: Seed for random numbers; passed through to the metalearner algorithm. Defaults to -1 (time-based
             random number)
             Defaults to ``-1``.
      :type seed: int
      :param score_training_samples: Specify the number of training set samples for scoring. The value must be >= 0.
             To use all training samples, enter 0.
             Defaults to ``10000``.
      :type score_training_samples: int
      :param keep_levelone_frame: Keep level one frame used for metalearner training.
             Defaults to ``False``.
      :type keep_levelone_frame: bool
      :param export_checkpoints_dir: Automatically export generated models to this directory.
             Defaults to ``None``.
      :type export_checkpoints_dir: str, optional
      :param auc_type: Set default multinomial AUC type.
             Defaults to ``"auto"``.
      :type auc_type: Literal["auto", "none", "macro_ovr", "weighted_ovr", "macro_ovo", "weighted_ovo"]
      :param gainslift_bins: Gains/Lift table number of bins. 0 means disabled.. Default value -1 means automatic
             binning.
             Defaults to ``-1``.
      :type gainslift_bins: int
      """
      super(H2OStackedEnsembleEstimator, self).__init__()
      self._parms = {}
      self._id = self._parms["model_id"] = model_id
      self.training_frame = training_frame
      self.response_column = response_column
      self.validation_frame = validation_frame
      self.blending_frame = blending_frame
      self.base_models = base_models
      self.metalearner_algorithm = metalearner_algorithm
      self.metalearner_nfolds = metalearner_nfolds
      self.metalearner_fold_assignment = metalearner_fold_assignment
      self.metalearner_fold_column = metalearner_fold_column
      self.metalearner_params = metalearner_params
      self.metalearner_transform = metalearner_transform
      self.max_runtime_secs = max_runtime_secs
      self.weights_column = weights_column
      self.offset_column = offset_column
      self.custom_metric_func = custom_metric_func
      self.seed = seed
      self.score_training_samples = score_training_samples
      self.keep_levelone_frame = keep_levelone_frame
      self.export_checkpoints_dir = export_checkpoints_dir
      self.auc_type = auc_type
      self.gainslift_bins = gainslift_bins
      self._parms["_rest_version"] = 99
  
imports: import ast
  import json
  import warnings
  import h2o
  from h2o.base import Keyed
  from h2o.exceptions import H2OResponseError, H2ODeprecationWarning
  from h2o.grid import H2OGridSearch
  from h2o.job import H2OJob
  from h2o.utils.shared_utils import quoted
  from h2o.utils.typechecks import is_type
  from h2o.estimators.estimator_base import H2OEstimator
  from h2o.exceptions import H2OValueError
  from h2o.frame import H2OFrame
  from h2o.utils.typechecks import assert_is_type, Enum, numeric
label_desc: Use image node_id 1 to create a new H2OStackedEnsembleEstimator object from inherited base classes: H2OEstimator with example: obj = H2OStackedEnsembleEstimator(model_id, training_frame, response_column, validation_frame, blending_frame, base_models, metalearner_algorithm, metalearner_nfolds, metalearner_fold_assignment, metalearner_fold_column, metalearner_params, metalearner_transform, max_runtime_secs, weights_column, offset_column, custom_metric_func, seed, score_training_samples, keep_levelone_frame, export_checkpoints_dir, auc_type, gainslift_bins)