install.packages("h2o")
Installing package into ‘/cloud/lib/x86_64-pc-linux-gnu-library/4.4’
(as ‘lib’ is unspecified)
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/h2o_3.44.0.3.tar.gz'
Content type 'application/x-gzip' length 266595032 bytes (254.2 MB)
==================================================
downloaded 254.2 MB

* installing *binary* package ‘h2o’ ...
* DONE (h2o)

The downloaded source packages are in
    ‘/tmp/Rtmp1TQvdy/downloaded_packages’
library(h2o)

----------------------------------------------------------------------

Your next step is to start H2O:
    > h2o.init()

For H2O package documentation, ask for help:
    > ??h2o

After starting H2O, you can use the Web UI at http://localhost:54321
For more information visit https://docs.h2o.ai

----------------------------------------------------------------------


Attaching package: ‘h2o’

The following objects are masked from ‘package:stats’:

    cor, sd, var

The following objects are masked from ‘package:base’:

    &&, %*%, %in%, ||, apply, as.factor, as.numeric, colnames, colnames<-, ifelse,
    is.character, is.factor, is.numeric, log, log10, log1p, log2, round, signif, trunc
h2o.init()
 Connection successful!

R is connected to the H2O cluster: 
    H2O cluster uptime:         15 minutes 15 seconds 
    H2O cluster timezone:       UTC 
    H2O data parsing timezone:  UTC 
    H2O cluster version:        3.44.0.3 
    H2O cluster version age:    1 year, 2 months and 6 days 
    H2O cluster name:           H2O_started_from_R_r2782235_eph084 
    H2O cluster total nodes:    1 
    H2O cluster total memory:   0.18 GB 
    H2O cluster total cores:    1 
    H2O cluster allowed cores:  1 
    H2O cluster healthy:        TRUE 
    H2O Connection ip:          localhost 
    H2O Connection port:        54321 
    H2O Connection proxy:       NA 
    H2O Internal Security:      FALSE 
    R Version:                  R version 4.4.2 (2024-10-31) 
Warning in h2o.clusterInfo() : 
Your H2O cluster version is (1 year, 2 months and 6 days) old. There may be a newer version available.
Please download and install the latest version from: https://h2o-release.s3.amazonaws.com/h2o/latest_stable.html
# Initialize the H2O instance
# Display connection details for the H2O cluster
h2o.init(nthreads = -1)
 Connection successful!

R is connected to the H2O cluster: 
    H2O cluster uptime:         15 minutes 15 seconds 
    H2O cluster timezone:       UTC 
    H2O data parsing timezone:  UTC 
    H2O cluster version:        3.44.0.3 
    H2O cluster version age:    1 year, 2 months and 6 days 
    H2O cluster name:           H2O_started_from_R_r2782235_eph084 
    H2O cluster total nodes:    1 
    H2O cluster total memory:   0.18 GB 
    H2O cluster total cores:    1 
    H2O cluster allowed cores:  1 
    H2O cluster healthy:        TRUE 
    H2O Connection ip:          localhost 
    H2O Connection port:        54321 
    H2O Connection proxy:       NA 
    H2O Internal Security:      FALSE 
    R Version:                  R version 4.4.2 (2024-10-31) 
Warning in h2o.clusterInfo() : 
Your H2O cluster version is (1 year, 2 months and 6 days) old. There may be a newer version available.
Please download and install the latest version from: https://h2o-release.s3.amazonaws.com/h2o/latest_stable.html
# Define the URL for the dataset
datasets <- "https://raw.githubusercontent.com/DarrenCook/h2o/bk/datasets/"
# Import the dataset from the URL
data <- h2o.importFile(paste0(datasets, "iris_wheader.csv"))

  |                                                                                                    
  |                                                                                              |   0%
  |                                                                                                    
  |==============================================================================================| 100%
# Specify the target variable (the column to predict)
y <- "class"

# Predictor variables (all columns except the target)
x <- setdiff(names(data), y)

# Split the data into training (80%) and test (20%) sets
parts <- h2o.splitFrame(data, ratios = 0.8)
train <- parts[[1]]
test <- parts[[2]]
# Train a deep learning model
m <- h2o.deeplearning(x = x, y = y, training_frame = train)

  |                                                                                                    
  |                                                                                              |   0%
  |                                                                                                    
  |==============================================================================================| 100%
# Make predictions on the test set
p <- h2o.predict(m, test)

  |                                                                                                    
  |                                                                                              |   0%
  |                                                                                                    
  |==============================================================================================| 100%
#Now check the model's performance using metrics like mean squared error (MSE) and a confusion matrix
# Mean squared error
h2o.mse(m)
[1] 0.1782797
# Confusion matrix
h2o.confusionMatrix(m)
Confusion Matrix: Row labels: Actual class; Column labels: Predicted class
#It is very evident that this model STRUGGLES PREDICTING IRIS-VERSICOLOR!!
# Convert predictions to a data frame
as.data.frame(h2o.cbind(p$predict,test$class))
# Calculate the accuracy of the model by comparing predicted and actual classes
mean(p$predict == test$class)
[1] 0.8333333
# Evaluate the model's performance on the test set and display metrics
h2o.performance(m, test)
H2OMultinomialMetrics: deeplearning

Test Set Metrics: 
=====================

MSE: (Extract with `h2o.mse`) 0.1395668
RMSE: (Extract with `h2o.rmse`) 0.3735863
Logloss: (Extract with `h2o.logloss`) 0.4840161
Mean Per-Class Error: 0.2
AUC: (Extract with `h2o.auc`) NaN
AUCPR: (Extract with `h2o.aucpr`) NaN
Confusion Matrix: Extract with `h2o.confusionMatrix(<model>, <data>)`)
=========================================================================
Confusion Matrix: Row labels: Actual class; Column labels: Predicted class

Hit Ratio Table: Extract with `h2o.hit_ratio_table(<model>, <data>)`
=======================================================================
Top-3 Hit Ratios: 
#The output provides key metrics for evaluating the deep learning model’s performance on the test set. The Mean Squared Error (MSE) of 0.2239 and the Root Mean Squared Error (RMSE) of 0.4732 indicate the average error in predictions, with lower values suggesting better accuracy. The log loss of 0.9359 measures how well the model’s predicted probabilities align with actual classes, where lower values indicate better calibration. The mean per-class error of 0.1875 shows the average misclassification rate across all classes. The absence of AUC and AUCPR values suggests that the dataset may not have a binary classification structure. The confusion matrix provides a detailed breakdown of classification performance for each class, helping to identify misclassifications. Overall, the model performs well, but further tuning or alternative approaches may be explored to improve accuracy and reduce error.
LS0tCnRpdGxlOiAiQ2xhc3MgQWN0aXZpdHkgNSIKb3V0cHV0OiBodG1sX25vdGVib29rCi0tLQoKYGBge3J9Cmluc3RhbGwucGFja2FnZXMoImgybyIpCmxpYnJhcnkoaDJvKQpoMm8uaW5pdCgpCiMgSW5pdGlhbGl6ZSB0aGUgSDJPIGluc3RhbmNlCiMgRGlzcGxheSBjb25uZWN0aW9uIGRldGFpbHMgZm9yIHRoZSBIMk8gY2x1c3RlcgpoMm8uaW5pdChudGhyZWFkcyA9IC0xKQojIERlZmluZSB0aGUgVVJMIGZvciB0aGUgZGF0YXNldApkYXRhc2V0cyA8LSAiaHR0cHM6Ly9yYXcuZ2l0aHVidXNlcmNvbnRlbnQuY29tL0RhcnJ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