<jupyter_start><jupyter_text>Machine Learning with H2O - Tutorial 3a: Regression Models (Basics)**Objective**:- This tutorial explains how to build regression models with four different H2O algorithms.**Wine Quality Dataset:**- Source: https://archive.ics.uci.edu/ml/datasets/Wine+Quality- CSV (https://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-white.csv)    **Algorithms**:1. GLM2. DRF3. GBM4. DNN**Full Technical Reference:**- http://docs.h2o.ai/h2o/latest-stable/h2o-r/h2o_package.pdf<jupyter_code># Start and connect to a local H2O cluster
suppressPackageStartupMessages(library(h2o))
h2o.init(nthreads = -1)<jupyter_output>H2O is not running yet, starting it now...

Note:  In case of errors look at the following log files:
    /tmp/RtmpaW555p/h2o_joe_started_from_r.out
    /tmp/RtmpaW555p/h2o_joe_started_from_r.err


Starting H2O JVM and connecting: .. Connection successful!

R is connected to the H2O cluster: 
    H2O cluster uptime:         2 seconds 173 milliseconds 
    H2O cluster version:        3.10.4.4 
    H2O cluster version age:    5 days  
    H2O cluster name:           H2O_started_from_R_joe_emj663 
    H2O cluster total nodes:    1 
    H2O cluster total memory:   5.21 GB 
    H2O cluster total cores:    8 
    H2O cluster allowed cores:  8 
    H2O cluster healthy:        TRUE 
    H2O Connection ip:          localhost 
    H2O Connection port:        54321 
    H2O Connection proxy:       NA 
    H2O Internal Security:      FALSE 
    R Version:                  R version 3.3.2 (2016-10-31)<jupyter_text><jupyter_code># Import wine quality data from a local CSV file
wine = h2o.importFile("winequality-white.csv")
head(wine, 5)
# Define features (or predictors)
features = colnames(wine)  # we want to use all the information
features = setdiff(features, 'quality')    # we need to exclude the target 'quality'
features
# Split the H2O data frame into training/test sets
# so we can evaluate out-of-bag performance
wine_split = h2o.splitFrame(wine, ratios = 0.8, seed = 1234)

wine_train = wine_split[[1]] # using 80% for training
wine_test = wine_split[[2]]  # using the rest 20% for out-of-bag evaluation
dim(wine_train)
dim(wine_test)<jupyter_output><empty_output><jupyter_text>Generalized Linear Model<jupyter_code># Build a Generalized Linear Model (GLM) with default settings
glm_default = h2o.glm(x = features,
                      y = 'quality',
                      training_frame = wine_train,
                      family = 'gaussian', 
                      model_id = 'glm_default')
# Check the model performance on training dataset
glm_default
# Check the model performance on test dataset
h2o.performance(glm_default, wine_test)<jupyter_output><empty_output><jupyter_text>Distributed Random Forest<jupyter_code># Build a Distributed Random Forest (DRF) model with default settings
drf_default = h2o.randomForest(x = features,
                               y = 'quality',
                               training_frame = wine_train,
                               seed = 1234,
                               model_id = 'drf_default')
# Check the DRF model summary
drf_default
# Check the model performance on test dataset
h2o.performance(drf_default, wine_test)<jupyter_output><empty_output><jupyter_text>Gradient Boosting Machines<jupyter_code># Build a Gradient Boosting Machines (GBM) model with default settings
gbm_default = h2o.gbm(x = features,
                      y = 'quality',
                      training_frame = wine_train,
                      seed = 1234,
                      model_id = 'gbm_default')
# Check the GBM model summary
gbm_default
# Check the model performance on test dataset
h2o.performance(gbm_default, wine_test)<jupyter_output><empty_output><jupyter_text>H2O Deep Learning<jupyter_code># Build a Deep Learning (Deep Neural Networks, DNN) model with default settings
dnn_default = h2o.deeplearning(x = features,
                               y = 'quality',
                               training_frame = wine_train,
                               model_id = 'dnn_default')
# Check the DNN model summary
dnn_default
# Check the model performance on test dataset
h2o.performance(dnn_default, wine_test)<jupyter_output><empty_output><jupyter_text>Making Predictions<jupyter_code># Use GLM model to make predictions
yhat_test_glm = h2o.predict(glm_default, wine_test)
head(yhat_test_glm)
# Use DRF model to make predictions
yhat_test_drf = h2o.predict(drf_default, wine_test)
head(yhat_test_drf)
# Use GBM model to make predictions
yhat_test_gbm = h2o.predict(gbm_default, wine_test)
head(yhat_test_gbm)
# Use DNN model to make predictions
yhat_test_dnn = h2o.predict(dnn_default, wine_test)
head(yhat_test_dnn)<jupyter_output>|                                                                            
  |                                                                      |   0%
  |                                                                            
  |=============================================================         |  88%
  |                                                                            
  |======================================================================| 100%
{'fraction_non_alphanumeric': 0.09984697781178271, 'fraction_numerical': 0.0225707727620505, 'mean_word_length': 2.57172131147541, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 17, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '107798', 'license': 'MIT', 'n_tokens_mistral': 1642, 'n_tokens_neox': 1517, 'n_words': 420, 'path': 'introduction_to_machine_learning/r_03a_regression_basics.ipynb', 'repo_name': 'woobe/h2o_tutorials', 'size': '5228'}