def calibration(prob, outcome, n_bins=10):
 prob = np.array(prob)
 outcome = np.array(outcome)
 c = 0.0
 judgement_bins = (np.arange((n_bins + 1)) / n_bins)
 bin_num = np.digitize(prob, judgement_bins)
 for j_bin in np.unique(bin_num):
  in_bin = (bin_num == j_bin)
  predicted_prob = np.mean(prob[in_bin])
  true_bin_prob = np.mean(outcome[in_bin])
  c += (np.sum(in_bin) * ((predicted_prob - true_bin_prob) ** 2))
 return (c / len(prob))

def calibration ( prob , outcome , n_bins = 10 ) : prob = np . array ( prob ) outcome = np . array ( outcome ) c = 0.0 judgement_bins = ( np . arange ( ( n_bins + 1 ) ) / n_bins ) bin_num = np . digitize ( prob , judgement_bins ) for j_bin in np . unique ( bin_num ) : in_bin = ( bin_num == j_bin ) predicted_prob = np . mean ( prob [ in_bin ] ) true_bin_prob = np . mean ( outcome [ in_bin ] ) c += ( np . sum ( in_bin ) * ( ( predicted_prob - true_bin_prob ) ** 2 ) ) return ( c / len ( prob ) )
calibration measurement for a set of predictions .