<jupyter_start><jupyter_text>Evaluate Virtual Ensemble Uncertainty using internal Catboost functions<jupyter_code>xx, yy = get_grid(600, 200)
ext=600
inputs = np.stack((xx.ravel(), yy.ravel()), axis=1)

inputs_ext = np.array([make_new_coordinates(x,y) for x, y in np.stack((xx.ravel(), yy.ravel()), axis=1)])

preds = ens.ensemble[1].virtual_ensembles_predict(inputs_ext, prediction_type='TotalUncertainty', virtual_ensembles_count=10)

know = preds[:,1]-preds[:,0]

xi = np.linspace(-ext, ext, 1000)
yi = np.linspace(-ext, ext, 1000)
levels = 20

zi_entropy = np.clip(griddata(inputs, preds[:,0], (xi[None, :], yi[:, None]), method='cubic'), 0.0, None)
zi_mutual_information = np.clip(griddata(inputs,  preds[:,1], (xi[None, :], yi[:, None]), method='cubic'), 0.0, None)


# Print All figures

# Total Uncertainty
plt.contourf(xi, yi, zi_entropy, cmap=cm.Blues, alpha=0.9, levels=levels)
plt.xlim(-ext, ext)
plt.ylim(-ext, ext)
plt.colorbar()
#plt.savefig('total_uncertainty.png', bbox_inches='tight', dpi=500)
plt.show()
plt.close()

# Data Uncertainty
plt.contourf(xi, yi, zi_mutual_information, cmap=cm.Blues, alpha=0.9, levels=levels)
plt.xlim(-ext, ext)
plt.ylim(-ext, ext)
plt.colorbar()
plt.show()
plt.close()

# Knowledge Uncertainty
zi_know = np.clip(griddata(inputs,  know, (xi[None, :], yi[:, None]), method='cubic'), 0.0, None)
plt.contourf(xi, yi, zi_know, cmap=cm.Blues, alpha=0.9, levels=levels)
plt.xlim(-ext, ext)
plt.ylim(-ext, ext)
plt.colorbar()
plt.show()
plt.close()<jupyter_output><empty_output><jupyter_text>Evaluate Virtual Ensemble uncertainties manually<jupyter_code>from scipy.special import softmax
xx, yy = get_grid(600, 200)
ext=600
inputs = np.stack((xx.ravel(), yy.ravel()), axis=1)
#print(inputs)

inputs_ext = np.array([make_new_coordinates(x,y) for x, y in np.stack((xx.ravel(), yy.ravel()), axis=1)])

preds = ens.ensemble[1].virtual_ensembles_predict(inputs_ext, prediction_type='VirtEnsembles', virtual_ensembles_count=100)
probs = softmax(preds,axis=2)

unks = ensemble_uncertainties(probs.transpose([1,0,2]))
xi = np.linspace(-ext, ext, 1000)
yi = np.linspace(-ext, ext, 1000)
levels = 20

zi_entropy = np.clip(griddata(inputs, unks['entropy_of_expected'], (xi[None, :], yi[:, None]), method='cubic'), 0.0, None)
zi_mutual_information = np.clip(griddata(inputs, unks['mutual_information'], (xi[None, :], yi[:, None]), method='cubic'), 0.0, None)
zi_data_uncertainty = np.clip(griddata(inputs, unks['expected_entropy'], (xi[None, :], yi[:, None]), method='cubic'), 0.0,
                              None)

# Print All figures

# Total Uncertainty
plt.contourf(xi, yi, zi_entropy, cmap=cm.Blues, alpha=0.9, levels=levels)
plt.xlim(-ext, ext)
plt.ylim(-ext, ext)
plt.colorbar()
#plt.savefig('total_uncertainty.png', bbox_inches='tight', dpi=500)
plt.show()
plt.close()

# Data Uncertainty
plt.contourf(xi, yi, zi_data_uncertainty, cmap=cm.Blues, alpha=0.9, levels=levels)
plt.xlim(-ext, ext)
plt.ylim(-ext, ext)
plt.colorbar()
plt.show()
#plt.savefig('data_uncertainty.png', bbox_inches='tight', dpi=500, levels=levels)
plt.close()

# Knowledge Uncertainty
plt.contourf(xi, yi, zi_mutual_information, cmap=cm.Blues, alpha=0.9, levels=levels)
plt.xlim(-ext, ext)
plt.ylim(-ext, ext)
plt.colorbar()
plt.show()
plt.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18546670720583763, 'fraction_numerical': 0.027363940407418668, 'mean_word_length': 6.494305239179955, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '658525', 'license': 'Apache-2.0', 'n_tokens_mistral': 1451, 'n_tokens_neox': 1346, 'n_words': 245, 'path': 'synthetic_classification.ipynb', 'repo_name': 'yandex-research/GBDT-uncertainty', 'size': '3289'}