H2O::Client
Raku-H2O-Client
Raku REST client for the open-source, distributed in-memory machine-learning platform H2O-3.
Installation
From Zef ecosystem:
zef install H20::ClientFrom GitHub:
zef install https://github.com/antononcube/Raku-H2O-Client.gitSetup
1. Download the latest H20 version.
2. Start in a OS-terminal application the H2O cluster with the shell command:
java -jar h2o.jar3. In case that command give the message:
Only Java versions 8-17 are supported, system version is 22.0.2
3.1. Check the available Java distributions with:
/usr/libexec/java_home -V3.2. Pick one with a version between 8-17 or download a one with one of these versions:
3.3. Setup JAVA_HOME and run the command java -jar h2o.jar again. For example, on macOS:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home
java -jar h2o.jar Usage examples
use H2O::Client;
my $h2o = H2O::Client.new('http://localhost:54321');
my $frame = $h2o.upload(
[%(x => 1, group => 'a'), %(x => 2, group => 'b')],
destination-frame => 'example.hex'
).wait.result;
say $frame.shape; # (2 2)
say $frame.names;
say $frame<group>.type; # column proxy
say $frame.head(2); # explicitly download a small preview# (2 2)
# [group x]
# string
# [{group => a, x => 1} {group => b, x => 2}]H2O::Client::Frame is a lightweight handle to a server-side frame. Its
identity is the H2O frame key; metadata is fetched lazily and cached. Use
refresh after external changes. H2O::Client::Column exposes column type,
domain, and summary statistics. Long-running parse, model-build, and export
operations return H2O::Client::Job; call wait before consuming result.
Rapids transformations
Frame transformations are explicit, composable Rapids expressions. They do not
run until materialize is called with a destination key:
use Data::ExampleDatasets;
my @data = example-dataset(/'dplyr::starwars'/);
$h2o.upload(@data, destination-frame => 'starwars');
my $frame = $h2o.frame('starwars');
my $heavy = $frame
.where($frame<mass>.expression.greater-than(60))
.select(<name mass homeworld>)
.materialize('starwars-heavy3.hex');# H2O::Frame<starwars-heavy3.hex>[42 Ć 3]The initial layer supports column selection, row filtering, arithmetic,
comparisons, boolean operations, cbind, rbind, sum, and mean. It opens
an H2O Rapids session lazily; call $h2o.close when retaining a connection for
a long-running process is no longer necessary.
To start a local cluster:
my $h2o = H2O::Client.new;
$h2o.init(jar-path => '/path/to/h2o.jar', jvm-opts => <-Xmx4g>);
$h2o.shutdown;shutdown stops only a process started by this client. Shutting down a cluster
connected to externally requires the explicit :cluster option.
Workflows
For fully programmed workflows see the example Raku scripts:
Or the Jupyter notebooks:
References
Documentation, downloads
[H2O1] H20.ai, H2O-3 Documentation.
[H2O2] H20.ai, H20 Latest Stable Release.
Packages
[AAp1] Anton Antonov, Data::ExampleDatasets, Raku package, (2021-2025), GitHub/antononcube.
[AAp2] Anton Antonov, Data::Importers, Raku package, (2024-2026), GitHub/antononcube.