#NEWLINE# def create_ensemble_segment( self , sub_model_indexes , weights ) : #NEWLINE# #INDENT# "\n        Create ensemble for a certain segment, from the given sub models using average weights.\n        Sub_model_indexes is a list of indexes to use for the sub_models list.\n        Weights is a list of dictionaries with given averages for each target, its ordering must correspond to\n        the order of sub_model_indexes.\n        Ex. -   >>>  weights = [{'target1':.5,'target2':.5},{'target1':.25,'target2':.75}]\n        " #NEWLINE# if ( len ( sub_model_indexes ) != len ( weights ) ) : #NEWLINE# #INDENT# raise ( Exception ( 'Ensemble failed. Number of sub models, %d, is not equal to number of weights, %d.' ) % ( len ( sub_model_indexes ) , len ( weights ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . df_ensemble_segment = self . sub_models_segment [ 0 ] . copy ( ) #NEWLINE# for target in self . targets : #NEWLINE# #INDENT# self . df_ensemble_segment [ target ] = 0 #NEWLINE# for submodel in sub_model_indexes : #NEWLINE# #INDENT# self . df_ensemble_segment [ target ] += ( self . sub_models_segment [ submodel ] [ target ] * weights [ submodel ] [ target ] )