### Start Standalone H2O with SPNEGO Authentication Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/security.html This example shows how to start a standalone H2O instance with SPNEGO authentication. It requires specifying the SPNEGO login service, username, and paths to the SPNEGO configuration and properties files. ```bash java -jar h2o.jar \ -spnego_login -user_name pricipal@DOMAIN \ -login_conf /path/to/spnego.conf \ -spnego_properties /path/to/spnego.properties ``` -------------------------------- ### Launch Standalone H2O with LDAP Authentication Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/security.html Command-line examples for starting a standalone H2O instance with LDAP authentication enabled using a specified configuration file. ```bash java -jar h2o.jar -ldap_login -login_conf ldap.conf java -jar h2o.jar -ldap_login -login_conf ldap.conf -user_name myLDAPusername ``` -------------------------------- ### Start Standalone H2O with Kerberos Authentication Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/security.html These examples demonstrate how to start a standalone H2O instance with Kerberos authentication enabled. It includes options for specifying the login configuration file, username, and optionally Kerberos realm and KDC. ```bash java -jar h2o.jar -kerberos_login -login_conf kerb.conf -user_name kerb_principal ``` ```bash java -Djava.security.krb5.realm="0XDATA.LOC" -Djava.security.krb5.kdc="ldap.0xdata.loc" -jar h2o.jar -kerberos_login -login_conf kerb.conf -user_name kerb_principal ``` -------------------------------- ### Install and Initialize H2O-3 in R Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/downloading.html Steps to clean existing installations, install required dependencies, and install the H2O-3 package from the official H2O.ai repository. ```r if ("package:h2o" %in% search()) { detach("package:h2o", unload=TRUE) } if ("h2o" %in% rownames(installed.packages())) { remove.packages("h2o") } pkgs <- c("RCurl","jsonlite") for (pkg in pkgs) { if (! (pkg %in% rownames(installed.packages()))) { install.packages(pkg) } } install.packages("h2o", type="source", repos=(c("http://h2o-release.s3.amazonaws.com/h2o/latest_stable_R"))) library(h2o) localH2O = h2o.init() demo(h2o.kmeans) ``` -------------------------------- ### Install H2O on Kubernetes using Helm Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/cloud-integration/kubernetes.html These commands demonstrate the process of adding the H2O Helm chart repository, installing a basic H2O cluster, and optionally testing the installation. The `helm install` command deploys H2O to Kubernetes, and further customization is possible by inspecting chart values. ```bash helm repo add h2o https://charts.h2o.ai --version |version| helm install basic-h2o h2o/h2o helm test basic-h2o ``` -------------------------------- ### Start H2O on Hadoop with Kerberos Authentication Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/security.html This example shows how to launch H2O on a Hadoop cluster with Kerberos authentication enabled. It requires specifying the login configuration file and the username. ```bash hadoop jar h2odriver.jar -n 3 -mapperXmx 10g -kerberos_login -login_conf kerb.conf -output hdfsOutputDirectory -user_name kerb_principal ``` -------------------------------- ### Install and Initialize H2O-3 in Python Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/downloading.html Commands to install Python dependencies, remove existing H2O modules, install the latest stable H2O-3 package via pip, and initialize the client. ```bash pip install requests pip install tabulate pip install future pip install matplotlib pip uninstall h2o pip install -f http://h2o-release.s3.amazonaws.com/h2o/latest_stable_Py.html h2o ``` ```python import h2o h2o.init() h2o.demo("glm") ``` -------------------------------- ### Start H2O Instance with Specific Port Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/faq/tunneling.html This command starts an H2O instance on a remote server. It requires Java to be installed and the h2o.jar file to be present. The command specifies the port on which H2O will listen for HTTP and REST traffic. ```bash java -jar h2o.jar -port 55599 ``` -------------------------------- ### Python Example: Building and Predicting with Isolation Forest Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-science/if.html Provides a complete example in Python demonstrating how to import data, build an Isolation Forest model, and perform predictions. ```APIDOC ## Python Example: Building and Predicting with Isolation Forest ### Description This example demonstrates the usage of the H2O Isolation Forest algorithm in Python. It covers data import, model training, and prediction. ### Code Example ```python import h2o from h2o.estimators import H2OIsolationForestEstimator h2o.init() # Import the prostate dataset h2o_df = h2o.import_file("https://raw.githubusercontent.com/h2oai/h2o-3/master/smalldata/logreg/prostate.csv") # Split the data giving the training dataset 75% of the data train,test = h2o_df.split_frame(ratios=[0.75]) # Build an Isolation forest model model = H2OIsolationForestEstimator(sample_rate = 0.1, max_depth = 20, ntrees = 50) model.train(training_frame=train) # Calculate score score = model.predict(test) result_pred = score["predict"] # Predict the leaf node assignment ln_pred = model.predict_leaf_node_assignment(test, "Path") ``` ``` -------------------------------- ### Stacked Ensemble Python Example Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-science/algo-params/metalearner_algorithm.html Example of initializing H2O and setting up base models for a stacked ensemble in Python. ```APIDOC ## Stacked Ensemble Python Example ```python import h2o from h2o.estimators.random_forest import H2ORandomForestEstimator from h2o.estimators.gbm import H2OGradientBoostingEstimator from h2o.estimators.stackedensemble import H2OStackedEnsembleEstimator h2o.init() # (Further Python code for importing data, training base models, and training stacked ensemble would follow here) ``` ``` -------------------------------- ### Configure Naïve-Bayes with eps_sdev Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-science/algo-params/eps_sdev.html This example demonstrates how to initialize H2O and import a dataset for a Naïve-Bayes model building exercise. ```R library(h2o) h2o.init() # import the cars dataset cars <- h2o.importFile("https://s3.amazonaws.com/h2o-public-test-data/smalldata/junit/cars_20mpg.csv") # Specify model-building exercise (1:binomial, 2:multinomial) problem <- sample(1:2, 1) ``` -------------------------------- ### Grid Search Example Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/grid-search.html Demonstrates how to launch a grid search job using the Java API, including setting up hyperparameters and search criteria. ```APIDOC ## Example ```java HashMap hyperParms = new HashMap<>(); hyperParms.put("_ntrees", new Integer[]{1, 2}); hyperParms.put("_distribution", new DistributionFamily[]{DistributionFamily.multinomial}); hyperParms.put("_max_depth", new Integer[]{1, 2, 5}); hyperParms.put("_learn_rate", new Float[]{0.01f, 0.1f, 0.3f}); // Setup common model parameters GBMModel.GBMParameters params = new GBMModel.GBMParameters(); params._train = fr._key; params._response_column = "cylinders"; // Trigger new grid search job, block for results and get the resulting grid object GridSearch gs = GridSearch.startGridSearch(params, hyperParms, GBM_MODEL_FACTORY, new HyperSpaceSearchCriteria.CartesianSearchCriteria()); Grid grid = (Grid) gs.get(); ``` ``` -------------------------------- ### Configure build_tree_one_node in H2O-3 Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-science/algo-params/build_tree_one_node.html Example demonstrating how to initialize H2O and prepare for model training with the build_tree_one_node parameter. ```R library(h2o) h2o.init() # import the cars dataset: # this dataset is used to classify whether or not a car is economical based on ``` -------------------------------- ### Generating MOJO Model Visualization with PrintMojo Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/productionizing.html This command-line example shows how to use the PrintMojo tool to convert an H2O MOJO model file into a PNG image. It requires Graphviz to be installed and specifies input, output, and format options. The example first downloads a MOJO and then executes the PrintMojo command. ```Bash # In another terminal window, download and extract the # latest stable h2o.jar from http://www.h2o.ai/download/ cd ~/Downloads unzip h2o-3.42.0.2.zip cd h2o-3.42.0.2 # Run the PrintMojo tool from the command line. java -cp "h2o-genmodel.jar:." water.droplet.PrintMojo -i "/path/to/your/model.mojo" -o "output.png" -f png ``` -------------------------------- ### Setup Docker Directory and Dockerfile Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/getting-started/docker-users.html Commands to create a local directory for the H2O-3 Docker configuration and download the official Dockerfile template. ```bash mkdir -p /data/h2o-{{branch_name}} cd /data/h2o- wget https://raw.githubusercontent.com/h2oai/h2o-3/master/Dockerfile ``` -------------------------------- ### H2O Startup Log Output Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/faq/tunneling.html This is an example of the output generated when an H2O instance starts. It includes build information, Java details, and the ports used for internal communication and external access. This output is useful for verifying the H2O instance is running correctly. ```log irene@mr-0x3:~/target$ java -jar h2o.jar -port 55599 04:48:58.053 main INFO WATER: ----- H2O started ----- 04:48:58.055 main INFO WATER: Build git branch: master 04:48:58.055 main INFO WATER: Build git hash: 64fe68c59ced5875ac6bac26a784ce210ef9f7a0 04:48:58.055 main INFO WATER: Build git describe: 64fe68c 04:48:58.055 main INFO WATER: Build project version: 1.7.0.99999 04:48:58.055 main INFO WATER: Built by: 'Irene' 04:48:58.055 main INFO WATER: Built on: 'Wed Sep 4 07:30:45 PDT 2013' 04:48:58.055 main INFO WATER: Java availableProcessors: 4 04:48:58.059 main INFO WATER: Java heap totalMemory: 0.47 gb 04:48:58.059 main INFO WATER: Java heap maxMemory: 6.96 gb 04:48:58.060 main INFO WATER: ICE root: '/tmp' 04:48:58.081 main INFO WATER: Internal communication uses port: 55600 + Listening for HTTP and REST traffic on + http://192.168.1.173:55599/ 04:48:58.109 main INFO WATER: H2O cloud name: 'irene' 04:48:58.109 main INFO WATER: (v1.7.0.99999) 'irene' on /192.168.1.173:55599, discovery address /230 .252.255.19:59132 04:48:58.111 main INFO WATER: Cloud of size 1 formed [/192.168.1.173:55599] 04:48:58.247 main INFO WATER: Log dir: '/tmp/h2ologs' ``` -------------------------------- ### Advanced MOJO Initialization with Generic Model in R/Python Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/save-and-load-model.html Illustrates advanced MOJO model initialization by importing MOJO bytes directly using a generic model. This avoids re-uploading MOJO data if it's already available. ```R data <- h2o.importFile(path = 'training_dataset.csv') cols <- c("Some column", "Another column") original_model <- h2o.glm(x = cols, y = "response", training_frame = data) path <- "/path/to/model/directory" mojo_destination <- h2o.download_mojo(model = original_model, path = path) # Only import or upload MOJO model data, do not initialize the generic model yet imported_mojo_key <- h2o.importFile(mojo_destination, parse = FALSE) # Build the generic model later, when needed generic_model <- h2o.generic(model_key = imported_mojo_key) new_observations <- h2o.importFile(path = 'new_observations.csv') h2o.predict(generic_model, new_observations) ``` ```Python data = h2o.import_file(path='training_dataset.csv') original_model = H2OGeneralizedLinearEstimator() original_model.train(x = ["Some column", "Another column"], y = "response", training_frame=data) path = '/path/to/model/directory/model.zip' original_model.download_mojo(path) imported_mojo_key = h2o.lazy_import(file) generic_model = H2OGenericEstimator(model_key = get_frame(model_key[0])) new_observations = h2o.import_file(path='new_observations.csv') predictions = generic_model.predict(new_observations) ``` -------------------------------- ### Train GBM Model with Checkpointing (Python) Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-science/algo-params/in_training_checkpoints_dir.html This Python code illustrates training a GBM model with H2O, utilizing the 'in_training_checkpoints_dir' for saving intermediate model states. It covers data import, feature preparation, checkpoint directory setup, and model training. The example also demonstrates loading a specific checkpoint and retraining a model from that point, ensuring the restarted model is equivalent to the original. ```Python # import necessary modules: import h2o from h2o.estimators.gbm import H2OGradientBoostingEstimator import tempfile from os import listdir, path # start h2o: h2o.init() # import the prostate dataset: prostate = h2o.import_file(path="http://s3.amazonaws.com/h2o-public-test-data/smalldata/prostate/prostate.csv") # set the predictors, response, and categorical features: prostate["CAPSULE"] = prostate["CAPSULE"].asfactor() prostate["RACE"] = prostate["RACE"].asfactor() predictors = ["ID", "AGE", "RACE", "DPROS", "DCAPS", "PSA", "VOL", "GLEASON"] response = "CAPSULE" # specify directory for training checkpoints: checkpoints_dir = tempfile.mkdtemp() # train the model and export checkpoints in training process: pros_gbm = H2OGradientBoostingEstimator(model_id="gbm_model", ntrees=10, seed=1111, in_training_checkpoints_dir=checkpoints_dir) pros_gbm.train(x=predictors, y=response, training_frame=prostate) # retrieve the number of files in the exported checkpoints directory: checkpoints = listdir(checkpoints_dir) print(checkpoints) num_files = len(listdir(checkpoints_dir)) print(num_files) # 9 # load checkpoint containing 3. trees: checkpoint = h2o.load_model(path.join(checkpoints_dir, pros_gbm.model_id + ".ntrees_3")) display("Checkpoint:", checkpoint) # restart from checkpoint containing 3. trees: pros_gbm_restarted = H2OGradientBoostingEstimator(model_id="gbm_model", ntrees=10, seed=1111, checkpoint=checkpoint, in_training_checkpoints_dir=checkpoints_dir) pros_gbm_restarted.train(x=predictors, y=response, training_frame=prostate) pros_gbm_restarted # this model is equal to pros_gbm ``` -------------------------------- ### Enable compute_metrics in H2O-3 Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-science/algo-params/compute_metrics.html This example demonstrates how to initialize the H2O cluster and import a dataset, which is the prerequisite for using model parameters like compute_metrics. ```R library(h2o) h2o.init() # import the prostate dataset: prostate <- h2o.importFile("http://s3.amazonaws.com/h2o-public-test-data/smalldata/prostate/prostate.csv.zip") ``` -------------------------------- ### Install H2O Python Dependencies Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/faq/python.html Commands to install necessary system and Python dependencies for H2O-3, including numpy, scipy, and scikit-learn, to resolve common installation errors. ```bash easy_install pip pip install numpy brew install gcc pip install scipy pip install scikit-learn ``` -------------------------------- ### GET /3/Jobs/{job_id} Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/rest-api-reference.html Gets the status of a specific H2O Job. ```APIDOC ## GET /3/Jobs/{job_id} ### Description Get the status of the given H2O Job (long-running action). ### Method GET ### Endpoint /3/Jobs/{job_id} ### Parameters #### Path Parameters - **job_id** (string) - Required - The ID of the job to retrieve. ### Response #### Success Response (200) - **job** (JobsV3) - The status of the specified H2O Job. ### Response Example ```json { "job": {} } ``` ``` -------------------------------- ### Configure H2O Server with Java Keystore Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/security.html Examples of launching H2O with a Java Keystore for HTTPS support across different deployment modes. ```Bash java -jar h2o.jar -jks h2o.jks hadoop jar h2odriver.jar -n 3 -mapperXmx 10g -jks h2o.jks -output hdfsOutputDirectory $SPARK_HOME/bin/spark-submit --class water.SparklingWaterDriver --conf spark.ext.h2o.jks=/path/to/h2o.jks sparkling-water-assembly-0.2.17-SNAPSHOT-all.jar ``` -------------------------------- ### Build and Train a Deep Learning Model in H2O Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-science/deep-learning.html Demonstrates how to initialize H2O, import data, preprocess features, train a Deep Learning model with Tweedie distribution, and evaluate performance. ```R library(h2o) h2o.init() insurance <- h2o.importFile("https://s3.amazonaws.com/h2o-public-test-data/smalldata/glm_test/insurance.csv") offset = log(insurance$Holders) insurance$Holders <- as.factor(insurance$Holders) insurance$Age <- as.factor(insurance$Age) insurance$Group <- as.factor(insurance$Group) insurance$District <- as.factor(insurance$District) dl <- h2o.deeplearning(x = 1:3, y = "Claims", distribution = "tweedie", hidden = c(1), epochs = 1000, train_samples_per_iteration = -1, reproducible = TRUE, activation = "Tanh", single_node_mode = FALSE, balance_classes = FALSE, force_load_balance = FALSE, seed = 23123, tweedie_power = 1.5, score_training_samples = 0, score_validation_samples = 0, training_frame = insurance, stopping_rounds = 0) perf <- h2o.performance(dl) pred <- h2o.predict(dl, newdata = insurance) ``` ```Python import h2o from h2o.estimators import H2ODeepLearningEstimator h2o.init() insurance = h2o.import_file("https://s3.amazonaws.com/h2o-public-test-data/smalldata/glm_test/insurance.csv") insurance["offset"] = insurance["Holders"].log() insurance["Group"] = insurance["Group"].asfactor() insurance["Age"] = insurance["Age"].asfactor() insurance["District"] = insurance["District"].asfactor() dl = H2ODeepLearningEstimator(distribution="tweedie", hidden=[1], epochs=1000, train_samples_per_iteration=-1, reproducible=True, activation="Tanh", single_node_mode=False, balance_classes=False, force_load_balance=False, seed=23123, tweedie_power=1.5, score_training_samples=0, score_validation_samples=0, stopping_rounds=0) dl.train(x=list(range(3)), y="Claims", training_frame=insurance) perf = dl.model_performance() ``` -------------------------------- ### Build GBM Model in Scala (Sparkling Water) Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-science/gbm.html This Scala code snippet demonstrates how to build a Gradient Boosting Machine (GBM) model using Sparkling Water, which integrates H2O with Apache Spark. It shows the setup of the H2O context, importing data, defining GBM parameters, and training the model. This example focuses on model training and does not explicitly show the calculation of H statistics, but it provides the foundation for it. ```Scala import org.apache.spark.h2o._ import water.Key import java.io.File val h2oContext = H2OContext.getOrCreate(sc) import h2oContext._ import h2oContext.implicits._ // Import data from the local file system as an H2O DataFrame val prostateData = new H2OFrame(new File("/Users/jsmith/src/github.com/h2oai/sparkling-water/examples/smalldata/prostate.csv")) // Build a GBM model import _root_.hex.tree.gbm.GBM import _root_.hex.tree.gbm.GBMModel.GBMParameters val gbmParams = new GBMParameters() gbmParams._train = prostateData gbmParams._response_column = 'CAPSULE gbmParams._nfolds = 5 gbmParams._seed = 1111 gbmParams._keep_cross_validation_predictions = true; val gbm = new GBM(gbmParams,Key.make("gbmRegModel.hex")) val gbmModel = gbm.trainModel().get() ``` -------------------------------- ### Install R Dependencies Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/getting-started/getting-started.html Checks for and installs required R packages for H2O functionality. ```r pkgs <- c("methods", "statmod", "stats", "graphics", "RCurl", "jsonlite", "tools", "utils") for (pkg in pkgs) {if (! (pkg %in% rownames(installed.packages()))) { install.packages(pkg) }} ``` -------------------------------- ### Initialize H2O and Load Data for CoxPH Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-science/algo-params/start_column.html This snippet demonstrates how to initialize the H2O cluster and import a dataset suitable for CoxPH analysis, which is a prerequisite for using the start_column parameter. ```R library(h2o) h2o.init() # import the heart dataset heart <- h2o.importFile("http://s3.amazonaws.com/h2o-public-test-data/smalldata/coxph_test/heart.csv") # set the predictor name and response column x <- "age" y <- "event" ``` -------------------------------- ### H2O GLM Example (Python) Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-science/algo-params/solver.html Example of using the `H2OGeneralizedLinearEstimator` in Python with the `solver` parameter. ```Python import h2o from h2o.estimators.glm import H2OGeneralizedLinearEstimator h2o.init() # import the boston dataset: # this dataset looks at features of the boston suburbs and predicts median housing prices # the original dataset can be found at https://archive.ics.uci.edu/ml/datasets/Housing boston = h2o.import_file("https://s3.amazonaws.com/h2o-public-test-data/smalldata/gbm_test/BostonHousing.csv") # set the predictor names and the response column name predictors = boston.columns[:-1] # set the response column to "medv", the median value of owner-occupied homes in $1000's response = "medv" # convert the chas column to a factor (chas = Charles River dummy variable (= 1 if tract bounds river; 0 otherwise)) boston['chas'] = boston['chas'].asfactor() # split into train and validation sets train, valid = boston.split_frame(ratios = [.8]) # try using the `solver` parameter: # initialize the estimator then train the model boston_glm = H2OGeneralizedLinearEstimator(solver = 'irlsm') boston_glm.train(x = predictors, y = response, training_frame = train, validation_frame = valid) ``` -------------------------------- ### Build and Evaluate K-Means Model Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-science/k-means.html Demonstrates how to initialize H2O, import data, split the dataset, train a K-Means model with specific predictors, and generate predictions. ```R library(h2o) h2o.init() iris <- h2o.importFile("http://h2o-public-test-data.s3.amazonaws.com/smalldata/iris/iris_wheader.csv") predictors <- c("sepal_len", "sepal_wid", "petal_len", "petal_wid") iris_split <- h2o.splitFrame(data = iris, ratios = 0.8, seed = 1234) train <- iris_split[[1]] valid <- iris_split[[2]] iris_kmeans <- h2o.kmeans(k = 10, estimate_k = TRUE, standardize = FALSE, seed = 1234, x = predictors, training_frame = train, validation_frame = valid) perf <- h2o.performance(iris_kmeans) pred <- h2o.predict(iris_kmeans, newdata = valid) ``` ```Python import h2o from h2o.estimators import H2OKMeansEstimator h2o.init() iris = h2o.import_file("http://h2o-public-test-data.s3.amazonaws.com/smalldata/iris/iris_wheader.csv") predictors = ["sepal_len", "sepal_wid", "petal_len", "petal_wid"] train, valid = iris.split_frame(ratios=[.8], seed=1234) model = H2OKMeansEstimator(k=10, seed=1234) model.train(x=predictors, training_frame=train, validation_frame=valid) pred = model.predict(valid) ``` -------------------------------- ### H2O GLM Example (R) Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-science/algo-params/solver.html Example of using the `h2o.glm` function in R with the `solver` parameter. ```R library(h2o) h2o.init() # import the boston dataset: # this dataset looks at features of the boston suburbs and predicts median housing prices # the original dataset can be found at https://archive.ics.uci.edu/ml/datasets/Housing boston <- h2o.importFile("https://s3.amazonaws.com/h2o-public-test-data/smalldata/gbm_test/BostonHousing.csv") # set the predictor names and the response column name predictors <- colnames(boston)[1:13] # set the response column to "medv", the median value of owner-occupied homes in $1000's response <- "medv" # convert the chas column to a factor (chas = Charles River dummy variable (= 1 if tract bounds river; 0 otherwise)) boston["chas"] <- as.factor(boston["chas"]) # split into train and validation sets boston_splits <- h2o.splitFrame(data = boston, ratios = 0.8) train <- boston_splits[[1]] valid <- boston_splits[[2]] # try using the `solver` parameter: boston_glm <- h2o.glm(x = predictors, y = response, training_frame = train, validation_frame = valid, solver = 'IRLSM') # print the mse for the validation data print(h2o.mse(boston_glm, valid = TRUE)) ``` -------------------------------- ### Configuring H2O GBM with Histogram Types Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-science/algo-params/histogram_type.html This example demonstrates how to initialize H2O, import a dataset, prepare factors, and split data for training, which serves as the foundation for applying histogram-based model configurations. ```R library(h2o) h2o.init() # import the airlines dataset airlines <- h2o.importFile("http://s3.amazonaws.com/h2o-public-test-data/smalldata/airlines/allyears2k_headers.zip") # convert columns to factors airlines["Year"] <- as.factor(airlines["Year"]) airlines["Month"] <- as.factor(airlines["Month"]) airlines["DayOfWeek"] <- as.factor(airlines["DayOfWeek"]) airlines["Cancelled"] <- as.factor(airlines["Cancelled"]) airlines['FlightNum'] <- as.factor(airlines['FlightNum']) # set the predictor names and the response column name predictors <- c("Origin", "Dest", "Year", "UniqueCarrier", "DayOfWeek", "Month", "Distance", "FlightNum") response <- "IsDepDelayed" # split into train and validation airlines_splits <- h2o.splitFrame(data = airlines, ratios = 0.8, seed = 1234) train <- airlines_splits[[1]] valid <- airlines_splits[[2]] ``` -------------------------------- ### Install libcurl on CentOS Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/getting-started/r-users.html Installs the libcurl development package on CentOS systems, which is required for H2O-3 to communicate with R. ```bash yum install libcurl-devel ``` -------------------------------- ### Build and Train an AdaBoost Model Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-science/adaboost.html Demonstrates how to initialize H2O, import a dataset, train an AdaBoost model with specific hyperparameters, and generate predictions. ```R library(h2o) h2o.init() # Import the prostate dataset into H2O: prostate <- h2o.importFile("https://s3.amazonaws.com/h2o-public-test-data/smalldata/prostate/prostate.csv") predictors <- c("AGE","RACE","DPROS","DCAPS","PSA","VOL","GLEASON") response <- "CAPSULE" prostate[response] <- as.factor(prostate[response]) # Build and train the model: adaboost_model <- h2o.adaBoost(nlearners=50, learn_rate = 0.5, weak_learner = "DRF", x = predictors, y = response, training_frame = prostate) # Generate predictions: h2o.predict(adaboost_model, prostate) ``` ```Python import h2o from h2o.estimators import H2OAdaBoostEstimator h2o.init() # Import the prostate dataset into H2O: prostate = h2o.import_file("http://h2o-public-test-data.s3.amazonaws.com/smalldata/prostate/prostate.csv") prostate["CAPSULE"] = prostate["CAPSULE"].asfactor() # Build and train the model: adaboost_model = H2OAdaBoostEstimator(nlearners=50, learn_rate = 0.8, weak_learner = "DRF", seed=0xBEEF) adaboost_model.train(y = "CAPSULE", training_frame = prostate) # Generate predictions: pred = adaboost_model.predict(prostate) pred ``` -------------------------------- ### Install libcurl on Ubuntu Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/getting-started/r-users.html Installs the libcurl development package on Ubuntu systems, which is required for H2O-3 to communicate with R. ```bash apt-get install libcurl4-openssl-dev ``` -------------------------------- ### Run H2O Demos Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/getting-started/getting-started.html Executes built-in H2O algorithm demonstrations to verify installation and functionality. ```python h2o.demo("glm") h2o.demo("gbm") h2o.demo("deeplearning") ``` -------------------------------- ### Configure export_checkpoints_dir in H2O-3 Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-science/algo-params/export_checkpoints_dir.html This example demonstrates how to initialize the H2O cluster and import a dataset, which serves as the prerequisite for setting up model checkpointing via the export_checkpoints_dir parameter. ```R library(h2o) h2o.init() # import the airlines dataset airlines = h2o.importFile("http://s3.amazonaws.com/h2o-public-test-data/smalldata/airlines/allyears2k_headers.zip", destination_frame="air.hex") ``` -------------------------------- ### Installing H2O Dependencies on Linux Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/faq/r.html Provides commands for installing the `libcurl` dependency required for H2O to communicate with R on Ubuntu and CentOS systems. ```Shell apt-get install libcurl4-openssl-dev ``` ```Shell yum install libcurl-devel ``` -------------------------------- ### Upgrade Python Environment for H2O Installation Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/faq/python.html Procedure to update setuptools and pip to resolve installation errors related to wheel and egg distributions. ```bash wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python sudo apt-get install python-pip pip install pip --upgrade ``` -------------------------------- ### Launch H2O with S3 Configuration Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/cloud-integration/ec2-and-s3.html Command line instruction to start the H2O standalone Java process while referencing an external configuration file for S3 access. ```bash java -jar h2o.jar -hdfs_config core-site.xml ``` -------------------------------- ### Start H2O JAR for Hive Import Source: https://docs.h2o.ai/h2o/latest-stable/h2o-docs/getting-data-into-h2o.html Starts the H2O JAR with the Hive JDBC driver in the classpath, preparing for data import. This command is executed in the terminal. ```bash hadoop jar h2odriver.jar -libjars hive-jdbc-standalone.jar -nodes 3 -mapperXmx 6g ```