"PDTP metric only supports classifiers that output logits or probabilities."
)
// divide into 100 bins and return center of bin
pred_bin = (np.floor(pred * 100) / 100).round(decimals=2) + 0.005
pred_bin[pred_bin > 1] = 0.995
if not indexes:
indexes = range(x.shape[0])
After Change
"PDTP metric only supports classifiers that output logits or probabilities."
)
// divide into 100 bins and return center of bin
bins = np.array(np.arange(0.0, 1.01, 0.01).round(decimals=2))
pred_bin_indexes = np.digitize(pred, bins)
pred_bin = bins[pred_bin_indexes] - 0.005
if not indexes:
indexes = range(x.shape[0])
for row in indexes:
// create new model without sample in training data
alt_x = np.delete(x, row, 0)
alt_y = np.delete(y, row, 0)
try:
extra_estimator.reset()
except NotImplementedError:
raise ValueError(
"PDTP metric can only be applied to classifiers that implement the reset method."
)
extra_estimator.fit(alt_x, alt_y)
// get probabilities from new model
alt_pred = extra_estimator.predict(x)
if not is_probability(alt_pred):
alt_pred = scipy.special.softmax(alt_pred, axis=1)
// divide into 100 bins and return center of bin
alt_pred_bin_indexes = np.digitize(alt_pred, bins)
alt_pred_bin = bins[alt_pred_bin_indexes] - 0.005
ratio_1 = pred_bin / alt_pred_bin
ratio_2 = alt_pred_bin / pred_bin
// get max value
max_value = max(ratio_1.max(), ratio_2.max())