Java prediction method for Autoencoder POJO missing

113 views
Skip to first unread message

Roberto Rösler

unread,
Aug 26, 2016, 12:18:47 PM8/26/16
to H2O Open Source Scalable Machine Learning - h2ostream

Hi,

I exported a trained autoencoder model as POJO and now want to use it to predict new cases. However, it seems there is no implementation for a prediction method


Exception in thread "main" java.lang.RuntimeException: Unimplemented 55  at
hex
.genmodel.easy.EasyPredictModelWrapper.predictAutoEncoder(EasyPredictModelWrapper.java:103)
at
main
.main(main.java:71)

or see https://github.com/h2oai/h2o-3/blob/master/h2o-genmodel/src/main/java/hex/genmodel/easy/EasyPredictModelWrapper.java).


I'm really curious about that because which value has the POJO if I'm not able to make any predictions with it?

 

Best regards,

 

Roberto

Tom Kraljevic

unread,
Aug 26, 2016, 2:11:14 PM8/26/16
to Roberto Rösler, H2O Open Source Scalable Machine Learning - h2ostream

Hi Roberto,


The generated Deep Learning POJO does have the autoencoder inside.
There just isn’t an Easy wrapper for it yet.  Users of it so far used the low-level POJO directly.

We would be interested in your feedback in terms of what that Easy API should look like.
(Basically, I’d love to see you write some code using the imaginary results of predictAutoEncoder().)


Thanks,
Tom


--
You received this message because you are subscribed to the Google Groups "H2O Open Source Scalable Machine Learning - h2ostream" group.
To unsubscribe from this group and stop receiving emails from it, send an email to h2ostream+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Roberto Rösler

unread,
Aug 28, 2016, 10:04:36 AM8/28/16
to H2O Open Source Scalable Machine Learning - h2ostream, roesler...@googlemail.com

Hi Tom,

 

your right, the POJO contains a score method, but I was hoping that there will be also an Easy-API wrapper that can be used with it. Would result in a more comfortable and unified API.

I'm not a Java programmer, but I would expect that the resulting "AutoEncoderModelPrediction" object afterwards give me access on (1) the reconstructed values (like with the predict function from the R and Python API), (2) the per-feature reconstruction error and (3) the average reconstruction error ( (2) and (3) in a similar way like the anomaly method from the R/Python-API).


So I edited my test code on the "AutoEncoderModelPrediction" class like this:

public class AutoEncoderModelPrediction extends AbstractPrediction {
   
public double[] predictions;
   
public double[] feature;
   
public double[] reconstrunctionError;
   
public double averageReconstructionError;
}

and on EasyPredictModelWrapper (just update the predictAutoEncoder method) like this:

  public AutoEncoderModelPrediction  predictAutoEncoder(RowData data) throws PredictException {
   
double[] preds = preamble(ModelCategory.AutoEncoder, data);
   
   
// save predictions
   
AutoEncoderModelPrediction  p = new AutoEncoderModelPrediction();
    p
.predictions = preds;
   
   
// save raw data
   
double[] rawData = new double[m.nfeatures()];
    setToNaN
(rawData);
    fillRawData
(data, rawData);
    p
.feature = rawData;
   
   
//calculate and reconstruction error
   
double[] reconstrunctionError = new double [rawData.length];
   
for (int i = 0; i < reconstrunctionError.length; i++) {
        reconstrunctionError
[i] = Math.pow(rawData[i] - preds[i],2);
   
}
    p
.reconstrunctionError = reconstrunctionError;
   
   
//calculate mean squared error
   
double sum = 0;
   
for (int i = 0; i < reconstrunctionError.length; i++) {
        sum
= sum + reconstrunctionError[i];
   
}
    p
.averageReconstructionError = sum/reconstrunctionError.length;
   
   
return p;
 
}

Now I can use something like this inside my little test program (the main java from your POJO documentation) to get the result for a specific feature vector:

        AutoEncoderModelPrediction p = model.predictAutoEncoder(row);
       
System.out.println("Got predictions ...");
       
System.out.println(Arrays.toString(p.predictions));
       
       
System.out.println("\nRaw data ...");
       
System.out.println(Arrays.toString(p.feature));
       
       
System.out.println("\nReconstruction error ...");
       
System.out.println(Arrays.toString(p.reconstrunctionError));
       
       
System.out.println("\nAverage reconstruction error ...");
       
System.out.println(p.averageReconstructionError);

Will similar functionality find their way into your product? 


Best


Roberto

Tom Kraljevic

unread,
Aug 28, 2016, 2:26:43 PM8/28/16
to Roberto Rösler, H2O Open Source Scalable Machine Learning - h2ostream, Venkatesh Yadav

Thanks for the feedback Roberto.
This jira captures the request.


Tom
Reply all
Reply to author
Forward
0 new messages