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

Function test_shap_complex_ctr

catboost/python-package/ut/medium/test.py:5108–5119  ·  view source on GitHub ↗
(task_type, calc_shap_mode)

Source from the content-addressed store, hash-verified

5106
5107@pytest.mark.parametrize('calc_shap_mode', ['TreeSHAP', 'IndependentTreeSHAP'])
5108def test_shap_complex_ctr(task_type, calc_shap_mode):
5109 pool = Pool([[0, 0, 0], [0, 1, 0], [1, 0, 1], [1, 1, 2]], [0, 0, 5, 8], cat_features=[0, 1, 2])
5110 reference_data = make_reference_data(pool, calc_shap_mode)
5111 model = train(pool, {'random_seed': 12302113, 'iterations': 100, 'task_type': task_type, 'gpu_ram_part': TEST_GPU_RAM_PART, 'devices': '0'})
5112 shap_values = model.get_feature_importance(type=EFstrType.ShapValues, data=pool, reference_data=reference_data)
5113 predictions = model.predict(pool)
5114 assert (len(predictions) == len(shap_values))
5115 for pred_idx in range(len(predictions)):
5116 assert (abs(sum(shap_values[pred_idx]) - predictions[pred_idx]) < 1e-9)
5117 fimp_txt_path = test_output_path(FIMP_TXT_PATH)
5118 np.savetxt(fimp_txt_path, np.around(np.array(shap_values), 9))
5119 return local_canonical_file(fimp_txt_path)
5120
5121
5122def test_shap_interaction_feature_importance(task_type):

Callers

nothing calls this directly

Calls 11

PoolClass · 0.90
trainFunction · 0.90
make_reference_dataFunction · 0.85
lenFunction · 0.85
test_output_pathFunction · 0.85
rangeFunction · 0.50
absFunction · 0.50
local_canonical_fileFunction · 0.50
predictMethod · 0.45
arrayMethod · 0.45

Tested by

no test coverage detected