(task_type)
| 5947 | |
| 5948 | |
| 5949 | def 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 | |
| 5983 | def test_loading_pool_with_numpy_int(): |
nothing calls this directly
no test coverage detected