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

Function test_feature_importance

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

Source from the content-addressed store, hash-verified

4245
4246
4247def test_feature_importance(task_type):
4248 pool = Pool(TRAIN_FILE, column_description=CD_FILE)
4249 pool_querywise = Pool(QUERYWISE_TRAIN_FILE, column_description=QUERYWISE_CD_FILE)
4250 fimp_npy_path = test_output_path(FIMP_NPY_PATH)
4251
4252 model = CatBoostRanker(iterations=5, learning_rate=0.03, task_type=task_type, gpu_ram_part=TEST_GPU_RAM_PART, devices="0", loss_function="QueryRMSE")
4253 model.fit(pool_querywise)
4254
4255 assert len(model.feature_importances_.shape) == 0
4256 model.get_feature_importance(type=EFstrType.LossFunctionChange, data=pool_querywise)
4257
4258 model = CatBoostClassifier(iterations=5, learning_rate=0.03, task_type=task_type, gpu_ram_part=TEST_GPU_RAM_PART, devices='0')
4259 model.fit(pool)
4260 assert (model.get_feature_importance() == model.get_feature_importance(type=EFstrType.PredictionValuesChange)).all()
4261 failed = False
4262 try:
4263 model.get_feature_importance(type=EFstrType.LossFunctionChange)
4264 except CatBoostError:
4265 failed = True
4266 assert failed
4267 np.save(fimp_npy_path, np.array(model.feature_importances_))
4268 assert len(model.feature_importances_.shape)
4269 return local_canonical_file(fimp_npy_path)
4270
4271
4272def test_feature_importance_interaction_asymmetric_grow_policy():

Callers

nothing calls this directly

Calls 11

fitMethod · 0.95
PoolClass · 0.90
CatBoostRankerClass · 0.90
CatBoostClassifierClass · 0.90
test_output_pathFunction · 0.85
lenFunction · 0.85
local_canonical_fileFunction · 0.50
allMethod · 0.45
saveMethod · 0.45
arrayMethod · 0.45

Tested by

no test coverage detected