title: How to use fit and transform for PCA on H2O
body: <p>I want to use PCA on H2O. In sklearn, we can apply <code>fit</code> on train set and then <code>transform</code> can be applied on test set. Here I am trying to follow the same logic in H2O. In the FAQ, it says:</p>
  
  <blockquote>
    <p>After the PCA model has been built using h2o.prcomp, use h2o.predict
    on the original data frame and the PCA model to produce the
    dimensionality-reduced representation. Use cbind to add the predictor
    column from the original data frame to the data frame produced by the
    output of h2o.predict. At this point, you can build supervised
    learning models on the new data frame.</p>
  </blockquote>
  
  <p>Based on this I tried the below:</p>
  
  <pre><code>from h2o.transforms.decomposition import H2OPCA
  
  trbb_pca = H2OPCA(k = 5, transform = "NORMALIZE", pca_method="GramSVD",
                     use_all_factor_levels=True, impute_missing=True,seed=24)
  
  trbb_pca.train(x=trbb_cols, training_frame=train_h2o)
  
  train_h2o_pca = train_h2o.cbind(trbb_pca.predict(train_h2o))
  test_h2o_pca = test_h2o.cbind(trbb_pca.predict(test_h2o))
  </code></pre>
  
  <p>Is it the way to implement PCA on train and test set in H2O?</p>