#NEWLINE# def groups_based_ks( y_pred , mask , sample_weight , groups_indices ) : #NEWLINE# #INDENT# 'Kolmogorov-Smirnov flatness on groups ' #NEWLINE# assert ( len ( y_pred ) == len ( sample_weight ) == len ( mask ) ) #NEWLINE# group_weights = compute_group_weights ( groups_indices , sample_weight = sample_weight ) #NEWLINE# ( prepared_data , prepared_weight , prep_F ) = prepare_distibution ( y_pred [ mask ] , weights = sample_weight [ mask ] ) #NEWLINE# result = 0.0 #NEWLINE# for ( group_weight , group_indices ) in zip ( group_weights , groups_indices ) : #NEWLINE# #INDENT# local_distribution = y_pred [ group_indices ] #NEWLINE# local_weights = sample_weight [ group_indices ] #NEWLINE# result += ( group_weight * _ks_2samp_fast ( prepared_data , local_distribution , prepared_weight , local_weights , prep_F ) ) #NEWLINE# #UNINDENT# return result