Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-6723 AdaBoost API #15732

Merged
merged 9 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion h2o-algos/src/main/java/hex/api/RegisterAlgos.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public void registerEndPoints(RestApiContext context) {
new hex.tree.uplift.UpliftDRF (true),
new hex.modelselection.ModelSelection (true),
new hex.isotonic .IsotonicRegression(true),
new hex.tree.dt .DT (true)
new hex.tree.dt .DT (true),
new hex.adaboost. AdaBoost (true)
};

// "Word2Vec", "Example", "Grep"
Expand Down
30 changes: 30 additions & 0 deletions h2o-algos/src/main/java/hex/schemas/AdaBoostModelV3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package hex.schemas;

import hex.adaboost.AdaBoostModel;
import water.api.schemas3.ModelOutputSchemaV3;
import water.api.schemas3.ModelSchemaV3;

public class AdaBoostModelV3 extends ModelSchemaV3<AdaBoostModel,
AdaBoostModelV3,
AdaBoostModel.AdaBoostParameters,
AdaBoostV3.AdaBoostParametersV3,
AdaBoostModel.AdaBoostOutput,
AdaBoostModelV3.AdaBoostModelOutputV3> {

public static final class AdaBoostModelOutputV3 extends ModelOutputSchemaV3<AdaBoostModel.AdaBoostOutput, AdaBoostModelOutputV3> {
// nothing
}

public AdaBoostV3.AdaBoostParametersV3 createParametersSchema() { return new AdaBoostV3.AdaBoostParametersV3(); }
public AdaBoostModelOutputV3 createOutputSchema() { return new AdaBoostModelOutputV3(); }

//==========================
// Custom adapters go here

// Version&Schema-specific filling into the impl
@Override public AdaBoostModel createImpl() {
AdaBoostV3.AdaBoostParametersV3 p = this.parameters;
AdaBoostModel.AdaBoostParameters parms = p.createImpl();
return new AdaBoostModel( model_id.key(), parms, new AdaBoostModel.AdaBoostOutput(null) );
}
}
41 changes: 41 additions & 0 deletions h2o-algos/src/main/java/hex/schemas/AdaBoostV3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package hex.schemas;

import hex.adaboost.AdaBoost;
import hex.adaboost.AdaBoostModel;
import water.api.API;
import water.api.schemas3.ModelParametersSchemaV3;

public class AdaBoostV3 extends ModelBuilderSchema<
AdaBoost,
AdaBoostV3,
AdaBoostV3.AdaBoostParametersV3> {

public static final class AdaBoostParametersV3 extends ModelParametersSchemaV3<AdaBoostModel.AdaBoostParameters, AdaBoostParametersV3> {
static public String[] fields = new String[]{
"model_id",
"training_frame",
"ignored_columns",
"ignore_const_cols",
"categorical_encoding",
"weights_column",

// AdaBoost specific
"nlearners",
"weak_learner",
"learn_rate",
"seed",
};

@API(help = "Number of AdaBoost weak learners.", gridable = true)
public int nlearners;

@API(help = "Choose a weak learner type. Defaults to AUTO, which means DRF.", gridable = true, values = {"AUTO", "DRF", "GLM", "GBM"})
public AdaBoostModel.Algorithm weak_learner;

@API(help="Learning rate (from 0.0 to 1.0)", gridable = true)
public double learn_rate;

@API(help = "Seed for pseudo random number generator (if applicable)", gridable = true)
public long seed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,7 @@ hex.schemas.UpliftDRFModelV3
hex.schemas.UpliftDRFModelV3$UpliftDRFModelOutputV3
hex.schemas.UpliftDRFV3
hex.schemas.UpliftDRFV3$UpliftDRFParametersV3
hex.schemas.AdaBoostModelV3
hex.schemas.AdaBoostModelV3$AdaBoostModelOutputV3
hex.schemas.AdaBoostV3
hex.schemas.AdaBoostV3$AdaBoostParametersV3
41 changes: 41 additions & 0 deletions h2o-bindings/bin/custom/R/gen_adaboost.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
extensions = dict(
skip_default_set_params_for=['training_frame', 'ignored_columns', 'response_column',
'max_confusion_matrix_size', 'distribution', 'offset_column'],
set_required_params="""
parms$training_frame <- training_frame
args <- .verify_dataxy(training_frame, x, y)
parms$ignored_columns <- args$x_ignore
parms$response_column <- args$y
""",
)


doc = dict(
preamble="""
Build an AdaBoost model

Builds an AdaBoost model on an H2OFrame.
""",
returns="""
Creates a \linkS4class{H2OModel} object of the right type.
""",
seealso="""
\code{\link{predict.H2OModel}} for prediction
""",
examples="""
library(h2o)
h2o.init()

# Import the airlines dataset
f <- "https://s3.amazonaws.com/h2o-public-test-data/smalldata/prostate/prostate.csv"
data <- h2o.importFile(f)

# Set predictors and response; set response as a factor
data["CAPSULE"] <- as.factor(data["CAPSULE"])
predictors <- c("AGE","RACE","DPROS","DCAPS","PSA","VOL","GLEASON")
response <- "CAPSULE"

# Train the AdaBoost model
h2o_adaboost <- h2o.adaBoost(x = predictors, y = response, training_frame = data, seed = 1234)
"""
)
8 changes: 8 additions & 0 deletions h2o-bindings/bin/custom/python/gen_adaboost.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
options = dict(
)

doc = dict(
__class__="""
Builds an AdaBoost model
"""
)
2 changes: 2 additions & 0 deletions h2o-bindings/bin/gen_R.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ def algo_to_modelname(algo):
if algo == "gam": return "Generalized Additive Model"
if algo == "modelselection": return "Model Selection"
if algo == "infogram": return "Infogram"
if algo == "adaboost": return "AdaBoost Model"
return algo


Expand Down Expand Up @@ -347,6 +348,7 @@ def main():
if name == "stackedensemble": module = "stackedEnsemble"
if name == "pca": module = "prcomp"
if name == "modelselection": module = "modelSelection"
if name == "adaboost": module = "adaBoost"
bi.vprint("Generating model: " + name)
bi.write_to_file("%s.R" % file_name, gen_module(mb, name, module))

Expand Down
1 change: 1 addition & 0 deletions h2o-bindings/bin/gen_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ def algo_to_classname(algo):
if algo == "rulefit": return "H2ORuleFitEstimator"
if algo == "modelselection": return "H2OModelSelectionEstimator"
if algo == "isotonicregression": return "H2OIsotonicRegressionEstimator"
if algo == "adaboost": return "H2OAdaBoostEstimator"
return "H2O" + algo.capitalize() + "Estimator"


Expand Down
6 changes: 6 additions & 0 deletions h2o-py/docs/modeling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Modeling In H2O
Supervised
++++++++++

:mod:`H2OAdaBoostEstimator`
---------------------------
.. autoclass:: h2o.estimators.adaboost.H2OAdaBoostEstimator
:show-inheritance:
:members:

:mod:`H2OANOVAGLMEstimator`
---------------------------
.. autoclass:: h2o.estimators.anovaglm.H2OANOVAGLMEstimator
Expand Down
18 changes: 10 additions & 8 deletions h2o-py/h2o/estimators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import inspect
import sys

from .adaboost import H2OAdaBoostEstimator
from .aggregator import H2OAggregatorEstimator
from .anovaglm import H2OANOVAGLMEstimator
from .coxph import H2OCoxProportionalHazardsEstimator
Expand Down Expand Up @@ -60,12 +61,13 @@ def create_estimator(algo, **params):

__all__ = (
"create_estimator",
"H2OAggregatorEstimator", "H2OANOVAGLMEstimator", "H2OCoxProportionalHazardsEstimator", "H2ODecisionTreeEstimator",
"H2OAutoEncoderEstimator", "H2ODeepLearningEstimator", "H2OEstimator", "H2OExtendedIsolationForestEstimator",
"H2OGeneralizedAdditiveEstimator", "H2OGradientBoostingEstimator", "H2OGenericEstimator",
"H2OGeneralizedLinearEstimator", "H2OGeneralizedLowRankEstimator", "H2OInfogram", "H2OIsolationForestEstimator",
"H2OIsotonicRegressionEstimator", "H2OKMeansEstimator", "H2OModelSelectionEstimator", "H2ONaiveBayesEstimator",
"H2OPrincipalComponentAnalysisEstimator", "H2OSupportVectorMachineEstimator", "H2ORandomForestEstimator",
"H2ORuleFitEstimator", "H2OStackedEnsembleEstimator", "H2OSingularValueDecompositionEstimator",
"H2OTargetEncoderEstimator", "H2OUpliftRandomForestEstimator", "H2OWord2vecEstimator", "H2OXGBoostEstimator"
"H2OAdaBoostEstimator", "H2OAggregatorEstimator", "H2OANOVAGLMEstimator", "H2OCoxProportionalHazardsEstimator",
"H2ODecisionTreeEstimator", "H2OAutoEncoderEstimator", "H2ODeepLearningEstimator", "H2OEstimator",
"H2OExtendedIsolationForestEstimator", "H2OGeneralizedAdditiveEstimator", "H2OGradientBoostingEstimator",
"H2OGenericEstimator", "H2OGeneralizedLinearEstimator", "H2OGeneralizedLowRankEstimator", "H2OInfogram",
"H2OIsolationForestEstimator", "H2OIsotonicRegressionEstimator", "H2OKMeansEstimator", "H2OModelSelectionEstimator",
"H2ONaiveBayesEstimator", "H2OPrincipalComponentAnalysisEstimator", "H2OSupportVectorMachineEstimator",
"H2ORandomForestEstimator", "H2ORuleFitEstimator", "H2OStackedEnsembleEstimator",
"H2OSingularValueDecompositionEstimator", "H2OTargetEncoderEstimator", "H2OUpliftRandomForestEstimator",
"H2OWord2vecEstimator", "H2OXGBoostEstimator"
)
Loading