#NEWLINE# def fit( self , results , train_true ) : #NEWLINE# #INDENT# x = [ ] #NEWLINE# y = [ ] #NEWLINE# count = 0 #NEWLINE# missing = [ ] #NEWLINE# for ( idx , row ) in train_true . iterrows ( ) : #NEWLINE# #INDENT# res = results . get ( row [ 'Id' ] ) #NEWLINE# if ( ( res is None ) or ( res [ 1 ] < 40 ) ) : #NEWLINE# #INDENT# missing . append ( row [ 'Id' ] ) #NEWLINE# continue #NEWLINE# #UNINDENT# count += 1 #NEWLINE# x . extend ( res ) #NEWLINE# y . extend ( [ row [ 'Systole' ] , row [ 'Diastole' ] ] ) #NEWLINE# #UNINDENT# print ( '{} cases are used to fit the model' . format ( count ) ) #NEWLINE# if ( len ( missing ) > 0 ) : #NEWLINE# #INDENT# print ( ( 'cases are missing in train: ' + ',' . join ( [ str ( int ( m ) ) for m in missing ] ) ) ) #NEWLINE# #UNINDENT# x = np . asarray ( x ) #NEWLINE# y = np . asarray ( y ) #NEWLINE# ff = minimize ( ( lambda p : analysis . crps_score ( self . _get_result ( x , p ) , y ) ) , res . p0 , bounds = self . bounds , options = { #NEWLINE# #INDENT# 'gtol' : 1e-05 , #NEWLINE# 'maxiter' : 500 , #NEWLINE# 'eps' : 0.001 , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . p = ff . x #NEWLINE# print ( ( 'fitting parameters ' + str ( self . p ) ) ) #NEWLINE# print ( ( 'fitting score ' + str ( ff . fun ) ) )