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

Function test_shap_feature_rmse

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

Source from the content-addressed store, hash-verified

4728
4729
4730def test_shap_feature_rmse(task_type):
4731 def rmse(yt, yp):
4732 return np.absolute(yt - yp)
4733
4734 train_pool = Pool(TRAIN_FILE, column_description=CD_FILE)
4735 test_pool = Pool(TEST_FILE, column_description=CD_FILE)
4736 reference_data = make_reference_data(train_pool, "IndependentTreeSHAP")
4737 model = CatBoostRegressor(iterations=10, loss_function='RMSE')
4738 model.fit(train_pool)
4739 label = test_pool.get_label()
4740 shap_values = model.get_feature_importance(type=EFstrType.ShapValues, data=test_pool, reference_data=reference_data, model_output="LossFunction")
4741 predictions = model.predict(test_pool)
4742 for doc_idx in range(len(shap_values)):
4743 assert abs(sum(shap_values[doc_idx]) - rmse(float(label[doc_idx]), float(predictions[doc_idx]))) < 1e-6
4744
4745
4746def test_feature_importance_sage_basic():

Callers

nothing calls this directly

Calls 12

fitMethod · 0.95
predictMethod · 0.95
PoolClass · 0.90
CatBoostRegressorClass · 0.90
make_reference_dataFunction · 0.85
lenFunction · 0.85
rmseFunction · 0.85
get_labelMethod · 0.80
rangeFunction · 0.50
absFunction · 0.50
floatFunction · 0.50

Tested by

no test coverage detected