@SuppressWarnings("unused") // called through reflection by RequestServer
  public ModelMetricsListSchemaV3 predict(int version, ModelMetricsListSchemaV3 s) {
    // parameters checking:
    if (s.model == null) throw new H2OIllegalArgumentException("model", "predict", null);
    if (DKV.get(s.model.name) == null) throw new H2OKeyNotFoundArgumentException("model", "predict", s.model.name);

    // Aggregator doesn't need a Frame to 'predict'
    if (s.exemplar_index < 0) {
      if (s.frame == null) throw new H2OIllegalArgumentException("frame", "predict", null);
      if (DKV.get(s.frame.name) == null) throw new H2OKeyNotFoundArgumentException("frame", "predict", s.frame.name);
    }

    ModelMetricsList parms = s.createAndFillImpl();

    Frame predictions;
    Frame deviances = null;
    if (!s.reconstruction_error && !s.reconstruction_error_per_feature && s.deep_features_hidden_layer < 0 &&
        !s.project_archetypes && !s.reconstruct_train && !s.leaf_node_assignment && !s.predict_staged_proba && !s.predict_contributions && s.exemplar_index < 0) {
      if (null == parms._predictions_name)
        parms._predictions_name = "predictions" + Key.make().toString().substring(0,5) + "_" + parms._model._key.toString() + "_on_" + parms._frame._key.toString();
      String customMetricFunc = s.custom_metric_func;
      if (customMetricFunc == null) {
        customMetricFunc = parms._model._parms._custom_metric_func;
      }
      predictions = parms._model.score(parms._frame, parms._predictions_name, null, true, CFuncRef.from(customMetricFunc));
      if (s.deviances) {
        if (!parms._model.isSupervised())
          throw new H2OIllegalArgumentException("Deviances can only be computed for supervised models.");
        if (null == parms._deviances_name)
          parms._deviances_name = "deviances" + Key.make().toString().substring(0, 5) + "_" + parms._model._key.toString() + "_on_" + parms._frame._key.toString();
        deviances = parms._model.computeDeviances(parms._frame, predictions, parms._deviances_name);
      }
    } else {
      if (s.deviances)
        throw new H2OIllegalArgumentException("Cannot compute deviances in combination with other special predictions.");
      if (Model.DeepFeatures.class.isAssignableFrom(parms._model.getClass())) {
        if (s.reconstruction_error || s.reconstruction_error_per_feature) {
          if (s.deep_features_hidden_layer >= 0)
            throw new H2OIllegalArgumentException("Can only compute either reconstruction error OR deep features.", "");
          if (null == parms._predictions_name)
            parms._predictions_name = "reconstruction_error" + Key.make().toString().substring(0,5) + "_" + parms._model._key.toString() + "_on_" + parms._frame._key.toString();
          predictions = ((Model.DeepFeatures) parms._model).scoreAutoEncoder(parms._frame, Key.make(parms._predictions_name), parms._reconstruction_error_per_feature);
        } else {
          if (s.deep_features_hidden_layer < 0)
            throw new H2OIllegalArgumentException("Deep features hidden layer index must be >= 0.", "");
          if (null == parms._predictions_name)
            parms._predictions_name = "deep_features" + Key.make().toString().substring(0,5) + "_" + parms._model._key.toString() + "_on_" + parms._frame._key.toString();
          predictions = ((Model.DeepFeatures) parms._model).scoreDeepFeatures(parms._frame, s.deep_features_hidden_layer);
        }
        predictions = new Frame(Key.<Frame>make(parms._predictions_name), predictions.names(), predictions.vecs());
        DKV.put(predictions._key, predictions);
      } else if(Model.GLRMArchetypes.class.isAssignableFrom(parms._model.getClass())) {
        if(s.project_archetypes) {
          if (parms._predictions_name == null)
            parms._predictions_name = "reconstructed_archetypes_" + Key.make().toString().substring(0, 5) + "_" + parms._model._key.toString() + "_of_" + parms._frame._key.toString();
          predictions = ((Model.GLRMArchetypes) parms._model).scoreArchetypes(parms._frame, Key.<Frame>make(parms._predictions_name), s.reverse_transform);
        } else {
          assert s.reconstruct_train;
          if (parms._predictions_name == null)
            parms._predictions_name = "reconstruction_" + Key.make().toString().substring(0, 5) + "_" + parms._model._key.toString() + "_of_" + parms._frame._key.toString();
          predictions = ((Model.GLRMArchetypes) parms._model).scoreReconstruction(parms._frame, Key.<Frame>make(parms._predictions_name), s.reverse_transform);
        }
      } else if(s.leaf_node_assignment) {
        assert(Model.LeafNodeAssignment.class.isAssignableFrom(parms._model.getClass()));
        if (null == parms._predictions_name)
          parms._predictions_name = "leaf_node_assignment" + Key.make().toString().substring(0, 5) + "_" + parms._model._key.toString() + "_on_" + parms._frame._key.toString();
        Model.LeafNodeAssignment.LeafNodeAssignmentType type = null == s.leaf_node_assignment_type ? Model.LeafNodeAssignment.LeafNodeAssignmentType.Path : s.leaf_node_assignment_type;
        predictions = ((Model.LeafNodeAssignment) parms._model).scoreLeafNodeAssignment(parms._frame, type, Key.<Frame>make(parms._predictions_name));
      } else if(s.predict_staged_proba) {
        if (! (parms._model instanceof Model.StagedPredictions)) {
          throw new H2OIllegalArgumentException("Model type " + parms._model._parms.algoName() + " doesn't support Staged Predictions.");
        }
        if (null == parms._predictions_name)
          parms._predictions_name = "staged_proba_" + Key.make().toString().substring(0, 5) + "_" + parms._model._key.toString() + "_on_" + parms._frame._key.toString();
        predictions = ((Model.StagedPredictions) parms._model).scoreStagedPredictions(parms._frame, Key.<Frame>make(parms._predictions_name));
      } else if(s.predict_contributions) {
        if (! (parms._model instanceof Model.Contributions)) {
          throw new H2OIllegalArgumentException("Model type " + parms._model._parms.algoName() + " doesn't support calculating Feature Contributions.");
        }
        if (null == parms._predictions_name)
          parms._predictions_name = "contributions_" + Key.make().toString().substring(0, 5) + "_" + parms._model._key.toString() + "_on_" + parms._frame._key.toString();
        predictions = ((Model.Contributions) parms._model).scoreContributions(parms._frame, Key.<Frame>make(parms._predictions_name));
      } else if(s.exemplar_index >= 0) {
        assert(Model.ExemplarMembers.class.isAssignableFrom(parms._model.getClass()));
        if (null == parms._predictions_name)
          parms._predictions_name = "members_" + parms._model._key.toString() + "_for_exemplar_" + parms._exemplar_index;
        predictions = ((Model.ExemplarMembers) parms._model).scoreExemplarMembers(Key.<Frame>make(parms._predictions_name), parms._exemplar_index);
      }
      else throw new H2OIllegalArgumentException("Requires a Deep Learning, GLRM, DRF or GBM model.", "Model must implement specific methods.");
    }

    ModelMetricsListSchemaV3 mm = this.fetch(version, s);

    // TODO: for now only binary predictors write an MM object.
    // For the others cons one up here to return the predictions frame.
    if (null == mm)
      mm = new ModelMetricsListSchemaV3();

    mm.predictions_frame = new KeyV3.FrameKeyV3(predictions._key);
    if (parms._leaf_node_assignment) //don't show metrics in leaf node assignments are made
      mm.model_metrics = null;
    if (deviances !=null)
      mm.deviances_frame = new KeyV3.FrameKeyV3(deviances._key);

    if (null == mm.model_metrics || 0 == mm.model_metrics.length) {
      // There was no response in the test set -> cannot make a model_metrics object
    } else {
      mm.model_metrics[0].predictions = new FrameV3(predictions, 0, 100); // TODO: Should call schema(version)
    }
    return mm;
  }
@ SuppressWarnings ( "unused" ) public ModelMetricsListSchemaV3 predict ( int version , ModelMetricsListSchemaV3 s ) { if ( s . model == null ) throw new H2OIllegalArgumentException ( "model" , "predict" , null ) ; if ( DKV . get ( s . model . name ) == null ) throw new H2OKeyNotFoundArgumentException ( "model" , "predict" , s . model . name ) ; if ( s . exemplar_index < 0 ) { if ( s . frame == null ) throw new H2OIllegalArgumentException ( "frame" , "predict" , null ) ; if ( DKV . get ( s . frame . name ) == null ) throw new H2OKeyNotFoundArgumentException ( "frame" , "predict" , s . frame . name ) ; } ModelMetricsList parms = s . createAndFillImpl ( ) ; Frame predictions ; Frame deviances = null ; if ( ! s . reconstruction_error && ! s . reconstruction_error_per_feature && s . deep_features_hidden_layer < 0 && ! s . project_archetypes && ! s . reconstruct_train && ! s . leaf_node_assignment && ! s . predict_staged_proba && ! s . predict_contributions && s . exemplar_index < 0 ) { if ( null == parms . _predictions_name ) parms . _predictions_name = "predictions" + Key . make ( ) . toString ( ) . substring ( 0 , 5 ) + "_" + parms . _model . _key . toString ( ) + "_on_" + parms . _frame . _key . toString ( ) ; String customMetricFunc = s . custom_metric_func ; if ( customMetricFunc == null ) { customMetricFunc = parms . _model . _parms . _custom_metric_func ; } predictions = parms . _model . score ( parms . _frame , parms . _predictions_name , null , true , CFuncRef . from ( customMetricFunc ) ) ; if ( s . deviances ) { if ( ! parms . _model . isSupervised ( ) ) throw new H2OIllegalArgumentException ( "Deviances can only be computed for supervised models." ) ; if ( null == parms . _deviances_name ) parms . _deviances_name = "deviances" + Key . make ( ) . toString ( ) . substring ( 0 , 5 ) + "_" + parms . _model . _key . toString ( ) + "_on_" + parms . _frame . _key . toString ( ) ; deviances = parms . _model . computeDeviances ( parms . _frame , predictions , parms . _deviances_name ) ; } } else { if ( s . deviances ) throw new H2OIllegalArgumentException ( "Cannot compute deviances in combination with other special predictions." ) ; if ( Model . DeepFeatures . class . isAssignableFrom ( parms . _model . getClass ( ) ) ) { if ( s . reconstruction_error || s . reconstruction_error_per_feature ) { if ( s . deep_features_hidden_layer >= 0 ) throw new H2OIllegalArgumentException ( "Can only compute either reconstruction error OR deep features." , "" ) ; if ( null == parms . _predictions_name ) parms . _predictions_name = "reconstruction_error" + Key . make ( ) . toString ( ) . substring ( 0 , 5 ) + "_" + parms . _model . _key . toString ( ) + "_on_" + parms . _frame . _key . toString ( ) ; predictions = ( ( Model . DeepFeatures ) parms . _model ) . scoreAutoEncoder ( parms . _frame , Key . make ( parms . _predictions_name ) , parms . _reconstruction_error_per_feature ) ; } else { if ( s . deep_features_hidden_layer < 0 ) throw new H2OIllegalArgumentException ( "Deep features hidden layer index must be >= 0." , "" ) ; if ( null == parms . _predictions_name ) parms . _predictions_name = "deep_features" + Key . make ( ) . toString ( ) . substring ( 0 , 5 ) + "_" + parms . _model . _key . toString ( ) + "_on_" + parms . _frame . _key . toString ( ) ; predictions = ( ( Model . DeepFeatures ) parms . _model ) . scoreDeepFeatures ( parms . _frame , s . deep_features_hidden_layer ) ; } predictions = new Frame ( Key . < Frame > make ( parms . _predictions_name ) , predictions . names ( ) , predictions . vecs ( ) ) ; DKV . put ( predictions . _key , predictions ) ; } else if ( Model . GLRMArchetypes . class . isAssignableFrom ( parms . _model . getClass ( ) ) ) { if ( s . project_archetypes ) { if ( parms . _predictions_name == null ) parms . _predictions_name = "reconstructed_archetypes_" + Key . make ( ) . toString ( ) . substring ( 0 , 5 ) + "_" + parms . _model . _key . toString ( ) + "_of_" + parms . _frame . _key . toString ( ) ; predictions = ( ( Model . GLRMArchetypes ) parms . _model ) . scoreArchetypes ( parms . _frame , Key . < Frame > make ( parms . _predictions_name ) , s . reverse_transform ) ; } else { assert s . reconstruct_train ; if ( parms . _predictions_name == null ) parms . _predictions_name = "reconstruction_" + Key . make ( ) . toString ( ) . substring ( 0 , 5 ) + "_" + parms . _model . _key . toString ( ) + "_of_" + parms . _frame . _key . toString ( ) ; predictions = ( ( Model . GLRMArchetypes ) parms . _model ) . scoreReconstruction ( parms . _frame , Key . < Frame > make ( parms . _predictions_name ) , s . reverse_transform ) ; } } else if ( s . leaf_node_assignment ) { assert ( Model . LeafNodeAssignment . class . isAssignableFrom ( parms . _model . getClass ( ) ) ) ; if ( null == parms . _predictions_name ) parms . _predictions_name = "leaf_node_assignment" + Key . make ( ) . toString ( ) . substring ( 0 , 5 ) + "_" + parms . _model . _key . toString ( ) + "_on_" + parms . _frame . _key . toString ( ) ; Model . LeafNodeAssignment . LeafNodeAssignmentType type = null == s . leaf_node_assignment_type ? Model . LeafNodeAssignment . LeafNodeAssignmentType . Path : s . leaf_node_assignment_type ; predictions = ( ( Model . LeafNodeAssignment ) parms . _model ) . scoreLeafNodeAssignment ( parms . _frame , type , Key . < Frame > make ( parms . _predictions_name ) ) ; } else if ( s . predict_staged_proba ) { if ( ! ( parms . _model instanceof Model . StagedPredictions ) ) { throw new H2OIllegalArgumentException ( "Model type " + parms . _model . _parms . algoName ( ) + " doesn't support Staged Predictions." ) ; } if ( null == parms . _predictions_name ) parms . _predictions_name = "staged_proba_" + Key . make ( ) . toString ( ) . substring ( 0 , 5 ) + "_" + parms . _model . _key . toString ( ) + "_on_" + parms . _frame . _key . toString ( ) ; predictions = ( ( Model . StagedPredictions ) parms . _model ) . scoreStagedPredictions ( parms . _frame , Key . < Frame > make ( parms . _predictions_name ) ) ; } else if ( s . predict_contributions ) { if ( ! ( parms . _model instanceof Model . Contributions ) ) { throw new H2OIllegalArgumentException ( "Model type " + parms . _model . _parms . algoName ( ) + " doesn't support calculating Feature Contributions." ) ; } if ( null == parms . _predictions_name ) parms . _predictions_name = "contributions_" + Key . make ( ) . toString ( ) . substring ( 0 , 5 ) + "_" + parms . _model . _key . toString ( ) + "_on_" + parms . _frame . _key . toString ( ) ; predictions = ( ( Model . Contributions ) parms . _model ) . scoreContributions ( parms . _frame , Key . < Frame > make ( parms . _predictions_name ) ) ; } else if ( s . exemplar_index >= 0 ) { assert ( Model . ExemplarMembers . class . isAssignableFrom ( parms . _model . getClass ( ) ) ) ; if ( null == parms . _predictions_name ) parms . _predictions_name = "members_" + parms . _model . _key . toString ( ) + "_for_exemplar_" + parms . _exemplar_index ; predictions = ( ( Model . ExemplarMembers ) parms . _model ) . scoreExemplarMembers ( Key . < Frame > make ( parms . _predictions_name ) , parms . _exemplar_index ) ; } else throw new H2OIllegalArgumentException ( "Requires a Deep Learning, GLRM, DRF or GBM model." , "Model must implement specific methods." ) ; } ModelMetricsListSchemaV3 mm = this . fetch ( version , s ) ; if ( null == mm ) mm = new ModelMetricsListSchemaV3 ( ) ; mm . predictions_frame = new KeyV3 . FrameKeyV3 ( predictions . _key ) ; if ( parms . _leaf_node_assignment ) mm . model_metrics = null ; if ( deviances != null ) mm . deviances_frame = new KeyV3 . FrameKeyV3 ( deviances . _key ) ; if ( null == mm . model_metrics || 0 == mm . model_metrics . length ) { } else { mm . model_metrics [ 0 ] . predictions = new FrameV3 ( predictions , 0 , 100 ) ; } return mm ; }
Score a frame with the given model and return the metrics AND the prediction frame.