Skip to content

Commit

Permalink
GH-15937: Expose parameter gainslift_bins for DeepLearning, GAM, GL…
Browse files Browse the repository at this point in the history
…M, and StackedEnsemble (#15938)

* Propagate gainslift_bins

* update docs

* fix test formatting
  • Loading branch information
tomasfryda authored Dec 11, 2023
1 parent 79d8f67 commit 7b5041a
Show file tree
Hide file tree
Showing 17 changed files with 260 additions and 7 deletions.
1 change: 1 addition & 0 deletions h2o-algos/src/main/java/hex/ensemble/Metalearner.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ protected void setCommonParams(P parms) {
parms._offset_column = _model._parms._offset_column;
parms._main_model_time_budget_factor = _model._parms._main_model_time_budget_factor;
parms._custom_metric_func = _model._parms._custom_metric_func;
parms._gainslift_bins = _model._parms._gainslift_bins;
}

protected void setCrossValidationParams(P parms) {
Expand Down
1 change: 1 addition & 0 deletions h2o-algos/src/main/java/hex/gam/MetricBuilderGAM.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public ModelMetrics makeModelMetrics(Model m, Frame f, Frame adaptedFrame, Frame
Vec weights = f.vec(gamM._parms._weights_column);
if (resp != null && fractionalbinomial != _glmf._family) {
gl = new GainsLift(preds.lastVec(), resp, weights);
gl._groups = m._parms._gainslift_bins;
gl.exec(gamM._output._job);
}
}
Expand Down
1 change: 1 addition & 0 deletions h2o-algos/src/main/java/hex/glm/GLMMetricBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ protected void computeAIC(GLMModel gm) {
Vec weights = f.vec(m._parms._weights_column);
if (resp != null && Family.fractionalbinomial != _glmf._family) { // don't calculate for frac binomial
gl = new GainsLift(preds.lastVec(), resp, weights);
gl._groups = m._parms._gainslift_bins;
gl.exec(m._output._job);
}
}
Expand Down
1 change: 1 addition & 0 deletions h2o-algos/src/main/java/hex/schemas/DeepLearningV3.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public static final class DeepLearningParametersV3 extends ModelParametersSchema
"export_checkpoints_dir",
"auc_type",
"custom_metric_func",
"gainslift_bins",
};


Expand Down
3 changes: 2 additions & 1 deletion h2o-algos/src/main/java/hex/schemas/GAMV3.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public static final class GAMParametersV3 extends ModelParametersSchemaV3<GAMMod
"scale", // array, smoothing parameter for GAM,
"keep_gam_cols",
"store_knot_locations",
"auc_type"
"auc_type",
"gainslift_bins",
};

@API(help = "Seed for pseudo random number generator (if applicable)", gridable = true)
Expand Down
3 changes: 2 additions & 1 deletion h2o-algos/src/main/java/hex/schemas/GLMV3.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public static final class GLMParametersV3 extends ModelParametersSchemaV3<GLMPar
"generate_variable_inflation_factors",
"fix_tweedie_variance_power",
"dispersion_learning_rate",
"influence"
"influence",
"gainslift_bins",
};

@API(help = "Seed for pseudo random number generator (if applicable)", gridable = true)
Expand Down
3 changes: 2 additions & 1 deletion h2o-algos/src/main/java/hex/schemas/StackedEnsembleV99.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public static final class StackedEnsembleParametersV99 extends ModelParametersSc
"score_training_samples",
"keep_levelone_frame",
"export_checkpoints_dir",
"auc_type"
"auc_type",
"gainslift_bins",
};

public static class AlgorithmValuesProvider extends EnumValuesProvider<Algorithm> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
``gainslift_bins``
------------------

- Available in: GBM, DRF, Naïve-Bayes, XGBoost
- Available in: Deeplearning, DRF, GAM, GBM, GLM, Naïve-Bayes, Stacked Ensemble, XGBoost
- Hyperparameter: no

Description
Expand Down
20 changes: 20 additions & 0 deletions h2o-py/h2o/estimators/deeplearning.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def __init__(self,
export_checkpoints_dir=None, # type: Optional[str]
auc_type="auto", # type: Literal["auto", "none", "macro_ovr", "weighted_ovr", "macro_ovo", "weighted_ovo"]
custom_metric_func=None, # type: Optional[str]
gainslift_bins=-1, # type: int
):
"""
:param model_id: Destination id for this model; auto-generated if not specified.
Expand Down Expand Up @@ -437,6 +438,10 @@ def __init__(self,
:param custom_metric_func: Reference to custom evaluation function, format: `language:keyName=funcName`
Defaults to ``None``.
:type custom_metric_func: str, optional
: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(H2ODeepLearningEstimator, self).__init__()
self._parms = {}
Expand Down Expand Up @@ -530,6 +535,7 @@ def __init__(self,
self.export_checkpoints_dir = export_checkpoints_dir
self.auc_type = auc_type
self.custom_metric_func = custom_metric_func
self.gainslift_bins = gainslift_bins

@property
def training_frame(self):
Expand Down Expand Up @@ -3239,6 +3245,20 @@ def custom_metric_func(self, custom_metric_func):
assert_is_type(custom_metric_func, None, str)
self._parms["custom_metric_func"] = custom_metric_func

@property
def gainslift_bins(self):
"""
Gains/Lift table number of bins. 0 means disabled.. Default value -1 means automatic binning.
Type: ``int``, defaults to ``-1``.
"""
return self._parms.get("gainslift_bins")

@gainslift_bins.setter
def gainslift_bins(self, gainslift_bins):
assert_is_type(gainslift_bins, None, int)
self._parms["gainslift_bins"] = gainslift_bins



class H2OAutoEncoderEstimator(H2ODeepLearningEstimator):
Expand Down
20 changes: 20 additions & 0 deletions h2o-py/h2o/estimators/gam.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def __init__(self,
keep_gam_cols=False, # type: bool
store_knot_locations=False, # type: bool
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.
Expand Down Expand Up @@ -373,6 +374,10 @@ def __init__(self,
: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(H2OGeneralizedAdditiveEstimator, self).__init__()
self._parms = {}
Expand Down Expand Up @@ -445,6 +450,7 @@ def __init__(self,
self.keep_gam_cols = keep_gam_cols
self.store_knot_locations = store_knot_locations
self.auc_type = auc_type
self.gainslift_bins = gainslift_bins

@property
def training_frame(self):
Expand Down Expand Up @@ -1444,6 +1450,20 @@ def auc_type(self, auc_type):
assert_is_type(auc_type, None, Enum("auto", "none", "macro_ovr", "weighted_ovr", "macro_ovo", "weighted_ovo"))
self._parms["auc_type"] = auc_type

@property
def gainslift_bins(self):
"""
Gains/Lift table number of bins. 0 means disabled.. Default value -1 means automatic binning.
Type: ``int``, defaults to ``-1``.
"""
return self._parms.get("gainslift_bins")

@gainslift_bins.setter
def gainslift_bins(self, gainslift_bins):
assert_is_type(gainslift_bins, None, int)
self._parms["gainslift_bins"] = gainslift_bins

Lambda = deprecated_property('Lambda', lambda_)

def _additional_used_columns(self, parms):
Expand Down
20 changes: 20 additions & 0 deletions h2o-py/h2o/estimators/glm.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def __init__(self,
fix_tweedie_variance_power=True, # type: bool
dispersion_learning_rate=0.5, # type: float
influence=None, # type: Optional[Literal["dfbetas"]]
gainslift_bins=-1, # type: int
):
"""
:param model_id: Destination id for this model; auto-generated if not specified.
Expand Down Expand Up @@ -411,6 +412,10 @@ def __init__(self,
excluded in the dataset.
Defaults to ``None``.
:type influence: Literal["dfbetas"], optional
: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(H2OGeneralizedLinearEstimator, self).__init__()
self._parms = {}
Expand Down Expand Up @@ -491,6 +496,7 @@ def __init__(self,
self.fix_tweedie_variance_power = fix_tweedie_variance_power
self.dispersion_learning_rate = dispersion_learning_rate
self.influence = influence
self.gainslift_bins = gainslift_bins

@property
def training_frame(self):
Expand Down Expand Up @@ -2379,6 +2385,20 @@ def influence(self, influence):
assert_is_type(influence, None, Enum("dfbetas"))
self._parms["influence"] = influence

@property
def gainslift_bins(self):
"""
Gains/Lift table number of bins. 0 means disabled.. Default value -1 means automatic binning.
Type: ``int``, defaults to ``-1``.
"""
return self._parms.get("gainslift_bins")

@gainslift_bins.setter
def gainslift_bins(self, gainslift_bins):
assert_is_type(gainslift_bins, None, int)
self._parms["gainslift_bins"] = gainslift_bins

Lambda = deprecated_property('Lambda', lambda_)

def get_regression_influence_diagnostics(self):
Expand Down
20 changes: 20 additions & 0 deletions h2o-py/h2o/estimators/stackedensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def __init__(self,
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.
Expand Down Expand Up @@ -173,6 +174,10 @@ def __init__(self,
: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 = {}
Expand All @@ -197,6 +202,7 @@ def __init__(self,
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

@property
Expand Down Expand Up @@ -905,6 +911,20 @@ def auc_type(self, auc_type):
assert_is_type(auc_type, None, Enum("auto", "none", "macro_ovr", "weighted_ovr", "macro_ovo", "weighted_ovo"))
self._parms["auc_type"] = auc_type

@property
def gainslift_bins(self):
"""
Gains/Lift table number of bins. 0 means disabled.. Default value -1 means automatic binning.
Type: ``int``, defaults to ``-1``.
"""
return self._parms.get("gainslift_bins")

@gainslift_bins.setter
def gainslift_bins(self, gainslift_bins):
assert_is_type(gainslift_bins, None, int)
self._parms["gainslift_bins"] = gainslift_bins


def metalearner(self):
"""Print the metalearner of an H2OStackedEnsembleEstimator.
Expand Down
Loading

0 comments on commit 7b5041a

Please sign in to comment.