#NEWLINE# def fit( self , preds , train_true ) : #NEWLINE# #INDENT# N = len ( preds ) #NEWLINE# print ( ( 'combine # predictions:' + ',' . join ( [ str ( len ( x ) ) for x in preds ] ) ) ) #NEWLINE# self . p0 = ( np . ones ( N ) * np . sqrt ( N ) ) #NEWLINE# X = np . zeros ( ( ( train_true . shape [ 0 ] * 2 ) , ( N * 2 ) ) ) #NEWLINE# X [ : ] = np . nan #NEWLINE# y = [ ] #NEWLINE# i = 0 #NEWLINE# for ( idx , row ) in train_true . iterrows ( ) : #NEWLINE# #INDENT# case = row [ 'Id' ] #NEWLINE# y . extend ( [ row [ 'Systole' ] , row [ 'Diastole' ] ] ) #NEWLINE# for j in range ( N ) : #NEWLINE# #INDENT# sede = preds [ j ] . get ( case ) #NEWLINE# if ( sede is not None ) : #NEWLINE# #INDENT# X [ ( i * 2 ) , ( 2 * j ) : ( ( 2 * j ) + 2 ) ] = sede [ 0 : 2 ] #NEWLINE# X [ ( ( i * 2 ) + 1 ) , ( 2 * j ) : ( ( 2 * j ) + 2 ) ] = sede [ 2 : 4 ] #NEWLINE# #UNINDENT# #UNINDENT# i += 1 #NEWLINE# #UNINDENT# y = np . asarray ( y ) #NEWLINE# print ( 'init score :{}' . format ( analysis . crps_score ( self . _get_result ( X , self . p0 ) , y ) ) ) #NEWLINE# ff = minimize ( ( lambda p : ( analysis . crps_score ( self . _get_result ( X , p ) , y ) + ( self . ll * np . var ( p ) ) ) ) , self . p0 , options = { #NEWLINE# #INDENT# 'gtol' : 1e-05 , #NEWLINE# 'eps' : 0.0001 , #NEWLINE# 'maxiter' : 500 , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . p = ff . x #NEWLINE# print ( ( 'fitting parameters ' + str ( row . p ) ) ) #NEWLINE# print ( ( 'fitting score ' + str ( ff . fun ) ) )