MCPcopy Create free account
hub / github.com/catboost/catboost / test_shap_multiclass

Function test_shap_multiclass

catboost/python-package/ut/medium/test.py:5949–5980  ·  view source on GitHub ↗
(task_type)

Source from the content-addressed store, hash-verified

5947
5948
5949def test_shap_multiclass(task_type):
5950 pool = Pool(CLOUDNESS_TRAIN_FILE, column_description=CLOUDNESS_CD_FILE)
5951 classifier = CatBoostClassifier(
5952 iterations=50,
5953 loss_function='MultiClass',
5954 thread_count=8,
5955 task_type=task_type,
5956 gpu_ram_part=TEST_GPU_RAM_PART,
5957 devices='0',
5958 random_strength=0,
5959 bootstrap_type='No',
5960 has_time=True
5961 )
5962 classifier.fit(pool)
5963 pred = classifier.predict(pool, prediction_type='Probability')
5964
5965 shap_values = classifier.get_feature_importance(
5966 type=EFstrType.ShapValues,
5967 data=pool,
5968 thread_count=8
5969 )
5970 features_count = pool.num_col()
5971 classes_count = 3
5972 assert pred.shape == (len(pred), classes_count)
5973 assert shap_values.shape == (len(pred), classes_count, features_count + 1)
5974 fimp_txt_path = test_output_path(FIMP_TXT_PATH)
5975 np.savetxt(fimp_txt_path, shap_values.reshape(len(pred), -1), fmt='%.9f')
5976 shap_values = np.sum(shap_values, axis=2)
5977 for doc_id in range(len(pred)):
5978 shap_probas = np.exp(shap_values[doc_id]) / np.sum(np.exp(shap_values[doc_id]))
5979 assert np.allclose(shap_probas, pred[doc_id])
5980 return local_canonical_file(fimp_txt_path)
5981
5982
5983def test_loading_pool_with_numpy_int():

Callers

nothing calls this directly

Calls 11

fitMethod · 0.95
predictMethod · 0.95
PoolClass · 0.90
CatBoostClassifierClass · 0.90
lenFunction · 0.85
test_output_pathFunction · 0.85
reshapeMethod · 0.80
rangeFunction · 0.50
local_canonical_fileFunction · 0.50
sumMethod · 0.45

Tested by

no test coverage detected