Basic implementation of H2O using R
The R programming language is a very popular language in the field of ML and data science because of its extensive support for statistical and data manipulation operations. It is widely used by data scientists and data miners for developing analytical software.
We will start by installing the R programming language and then installing H2O using R.
Installing R
An international team of developers maintains the R programming language. They have a dedicated web page for the R programming language called The Comprehensive R Archive Network (CRAN): https://cran.r-project.org/. There are different ways of installing R, depending on what operating system you use:
- On Linux (Ubuntu, Mint, Debian):
Execute the following command in the system Terminal:
sudo apt-get install r-base
- On macOS: To install R, go to https://cran.r-project.org/, go to the Download R for macOS hyperlink, and download the latest release of R for macOS.
- On Windows: Similar to how you install R on macOS, you can download the
.exe
file from https://cran.r-project.org/, go to the Download R for Windows hyperlink, and download the latest release of R for Windows.
Another great way of installing R on macOS and Windows is through RStudio. RStudio simplifies the installation of R-supported software and is also a very good IDE for R programming in general. You can download R studio from https://www.rstudio.com/.
Now that you know how to install the correct version of R, let’s download and install the H2O R package using the R programming language.
Installing H2O using R
Similar to Python, H2O provide support for the R programming language as well.
To install the R packages, follow these steps:
- First, we need to download the H2O R package dependencies. For this, execute the following command in your R Terminal:
install.packages(c("RCurl", "jsonlite"))
- Then, to install the actual
h2o
package, execute the following command in your R Terminal:install.packages("h2o")
And you are done.
- To test if it has been successfully downloaded and installed, open your R Terminal, import the
h2o
library, and execute theh2o.init()
command. This will spin up a local H2O server.
The results can be seen in the following screenshot:
Figure 1.2 – H2O execution using R
Let’s have a quick look at the output we got.
After executing h2o.init()
, the H2O client will check if there is an H2O server instance already running on the system. The H2O server is usually run locally on port 54321 by default. If it had found an already existing local H2O instance on the port, then it would have reused the same instance. However, in this scenario, there wasn’t any H2O server instance running on port 54321, which is why H2O attempted to start a local server on the same port.
Next, you will see the location of the JVM logs. Once the server is up and running, the H2O client tries to connect to it and the status of the connection to the server is displayed. Lastly, you will see some basic metadata regarding the server’s configuration. This metadata may be slightly different from what you see in your execution as it depends a lot on the specifications of your system. For example, by default, H2O will use all the cores available on your system for processing. So, if you have an 8-core system, then the H2O_cluster_allowed_cores
property value will be 8
. Alternatively, if you decide to use only four cores, then you can execute the h2o.init(nthreads=4)
command to use only four cores, thus reflecting the same in the server configuration output.
Now that you know how to implement H2O using Python and R, let’s create our very first ML model and make predictions on it using H2O AutoML.