Search code examples
rh2osvdsparklyr

How to access to U & V matrices from SVD


I'm trying to run h2o.svd in spark cluster via sparkling water & h2o. The process went well and I could get the SVD object from h2o command but I could only see the result below.

#Exclude ID column in h2o data frame
my_svd <- h2o.svd(my_h2o_df[,2:138], nv = 10)

my_svd

Model Details:
==============

H2ODimReductionModel: svd
Model ID:  SVD_model_R_1537868492645_2
Singular values:

      sval1     sval2     sval3     sval4     sval5     sval6     sval7
1 80.821459 53.024006 40.153390 38.508806 36.984611 35.530345 33.960273
      sval8     sval9    sval10
1 33.189426 27.904307 27.607862

NULL

Basically, in base R I can use svd and it'll provide the result of $d, $u, $v simultaneously in the model object.

Since I'm new to h2o workflow, I assume that the the result from above h2o object return only $d only compare to base R. How could I get the matrices $u and $v?

My Environment

  • Azure Databricks cloud cluster, Latest stable (Scala 2.11)
  • Spark 2.3.1
  • SparklyR 0.2.8
  • sparkling-water-assembly_2.11-2.3.13-all
  • R-h2o 3.20.0.7
  • rsparkling 0.2.8

Solution

  • you can get your D, V, and U as follows:

    # singular values (D)
    my_svd@model$d
    
    # singular vectors (U)
    h2o.getFrame(my_svd@model$u_key$name)
    
    # # singular vectors (V):
    h2o.getFrame(my_svd@model$v_key$name)