ml_grid.model_classes.H2OStackedEnsembleClassifier ================================================== .. py:module:: ml_grid.model_classes.H2OStackedEnsembleClassifier Attributes ---------- .. autoapisummary:: ml_grid.model_classes.H2OStackedEnsembleClassifier.logger Classes ------- .. autoapisummary:: ml_grid.model_classes.H2OStackedEnsembleClassifier.H2OStackedEnsembleEstimator ml_grid.model_classes.H2OStackedEnsembleClassifier.H2OStackedEnsembleClassifier Module Contents --------------- .. py:class:: H2OStackedEnsembleEstimator .. py:data:: logger .. py:class:: H2OStackedEnsembleClassifier(base_models: List[ml_grid.model_classes.H2OBaseClassifier.H2OBaseClassifier] = None, **kwargs) Bases: :py:obj:`ml_grid.model_classes.H2OBaseClassifier.H2OBaseClassifier` Initializes the H2OStackedEnsembleClassifier. :param base_models: A list of *unfitted* H2O classifier wrapper instances that will be trained as base learners. These models *must* be trained with `nfolds > 1` and `keep_cross_validation_predictions=True`. :type base_models: List[H2OBaseClassifier], optional :param \*\*kwargs: Keyword arguments passed to the H2OStackedEnsembleEstimator. Common arguments include `metalearner_algorithm`, `seed`, etc. .. py:method:: set_params(**kwargs) Overrides set_params to correctly handle the `base_models` list. This is critical for scikit-learn's `clone` function to work correctly during cross-validation. :returns: The instance with updated parameters. :rtype: H2OStackedEnsembleClassifier .. py:method:: get_params(deep: bool = True) -> dict Overrides get_params to ensure `base_models` is included. This allows scikit-learn's `clone` to work correctly. :returns: A dictionary of the estimator's parameters. :rtype: dict which is critical for scikit-learn's `clone` function. .. py:method:: score(X: pandas.DataFrame, y: pandas.Series, sample_weight=None) -> float Returns the mean accuracy on the given test data and labels. This method is required for scikit-learn compatibility, especially for use with tools like GridSearchCV when no `scoring` is specified. :param X: Test samples. :type X: pd.DataFrame :param y: True labels for X. :type y: pd.Series :param sample_weight: Sample weights (ignored, for API compatibility). :returns: The mean accuracy of the model. :rtype: float .. py:method:: fit(X: pandas.DataFrame, y: pandas.Series, **kwargs) -> H2OStackedEnsembleClassifier Fits the H2O Stacked Ensemble model, making it compatible with scikit-learn's CV tools. This method encapsulates the entire two-stage fitting process: 1. It first fits each of the base models on the provided training data, ensuring they are trained with cross-validation to generate predictions for the metalearner. 2. It then collects the model IDs of the fitted base models. 3. Finally, it trains the metalearner (the stacked ensemble model) using these base models. :param X: The feature matrix. :type X: pd.DataFrame :param y: The target vector. :type y: pd.Series :param \*\*kwargs: Additional keyword arguments (not used). :returns: The fitted classifier instance. :rtype: H2OStackedEnsembleClassifier :raises ValueError: If `base_models` is empty or not provided.