From 5d552ebc9434b2acb1fe182b430093111662d6a4 Mon Sep 17 00:00:00 2001 From: jih147 Date: Fri, 12 May 2023 10:19:59 -0700 Subject: [PATCH] return empty prediction interval if mojo response frame does not present interval columns --- .../MojoFrameToScoreResponseConverter.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/MojoFrameToScoreResponseConverter.java b/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/MojoFrameToScoreResponseConverter.java index 92a6856d..5be163da 100644 --- a/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/MojoFrameToScoreResponseConverter.java +++ b/common/transform/src/main/java/ai/h2o/mojos/deploy/common/transform/MojoFrameToScoreResponseConverter.java @@ -94,17 +94,20 @@ private void fillOutputRows( */ private void fillWithPredictionInterval( MojoFrame mojoFrame, ScoreRequest scoreRequest, ScoreResponse scoreResponse) { - if (Boolean.TRUE.equals(scoreRequest.isRequestPredictionIntervals()) - && mojoFrame.getNcols() > 1) { + if (Boolean.TRUE.equals(scoreRequest.isRequestPredictionIntervals())) { if (!supportPredictionInterval) { throw new IllegalStateException( "Unexpected error, prediction interval should be supported, but actually not"); } - int targetIdx = getTargetColIdx(Arrays.asList(mojoFrame.getColumnNames())); - PredictionInterval predictionInterval = new PredictionInterval(); - predictionInterval.setFields(getPredictionIntervalFields(mojoFrame, targetIdx)); - predictionInterval.setRows(getPredictionIntervalRows(mojoFrame, targetIdx)); - scoreResponse.setPredictionIntervals(predictionInterval); + if (mojoFrame.getNcols() > 1) { + int targetIdx = getTargetColIdx(Arrays.asList(mojoFrame.getColumnNames())); + PredictionInterval predictionInterval = new PredictionInterval(); + predictionInterval.setFields(getPredictionIntervalFields(mojoFrame, targetIdx)); + predictionInterval.setRows(getPredictionIntervalRows(mojoFrame, targetIdx)); + scoreResponse.setPredictionIntervals(predictionInterval); + } else { + scoreResponse.setPredictionIntervals(new PredictionInterval()); + } } }