@ Override protected Frame predictScoreImpl ( Frame fr , Frame adaptFrm , String destination_key , Job j , boolean computeMetrics , CFuncRef customMetricFunc ) { Frame levelOneFrame = new Frame ( Key . < Frame > make ( "preds_levelone_" + this . _key . toString ( ) + fr . _key ) ) ; // TODO: don't score models that have 0 coefficients / aren't used by the metalearner. // also we should be able to parallelize scoring of base models for ( Key < Model > baseKey : this . _parms . _base_models ) { Model base = baseKey . get ( ) ; Frame basePreds = base . score ( fr , "preds_base_" + this . _key . toString ( ) + fr . _key , j , false ) ; StackedEnsemble . addModelPredictionsToLevelOneFrame ( base , basePreds , levelOneFrame ) ; DKV . remove ( basePreds . _key ) ; //Cleanup Frame . deleteTempFrameAndItsNonSharedVecs ( basePreds , levelOneFrame ) ; } // Add response column to level one frame levelOneFrame . add ( this . responseColumn , adaptFrm . vec ( this . responseColumn ) ) ; // TODO: what if we're running multiple in parallel and have a name collision? Log . info ( "Finished creating \"level one\" frame for scoring: " + levelOneFrame . toString ( ) ) ; // Score the dataset, building the class distribution & predictions Model metalearner = this . _output . _metalearner ; Frame predictFr = metalearner . score ( levelOneFrame , destination_key , j , computeMetrics , CFuncRef . from ( _parms . _custom_metric_func ) ) ; if ( computeMetrics ) { // #score has just stored a ModelMetrics object for the (metalearner, preds_levelone) Model/Frame pair. // We need to be able to look it up by the (this, fr) pair. // The ModelMetrics object for the metalearner will be removed when the metalearner is removed. Key < ModelMetrics > [ ] mms = metalearner . _output . getModelMetrics ( ) ; ModelMetrics lastComputedMetric = mms [ mms . length - 1 ] . get ( ) ; ModelMetrics mmStackedEnsemble = lastComputedMetric . deepCloneWithDifferentModelAndFrame ( this , fr ) ; this . addModelMetrics ( mmStackedEnsemble ) ; } Frame . deleteTempFrameAndItsNonSharedVecs ( levelOneFrame , adaptFrm ) ; return predictFr ; }
For StackedEnsemble we call score on all the base_models and then combine the results with the metalearner to create the final predictions frame .