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

Function _test_generated_metrics

catboost/python-package/ut/medium/test.py:2672–2688  ·  view source on GitHub ↗
(loss_function, train_pool, test_pool, metrics, task)

Source from the content-addressed store, hash-verified

2670
2671
2672def _test_generated_metrics(loss_function, train_pool, test_pool, metrics, task):
2673 model = CatBoost({'loss_function': loss_function, 'iterations': 50})
2674 model.fit(train_pool, eval_set=test_pool)
2675
2676 # text description metrics
2677 td_results = model.eval_metrics(test_pool, list(metrics.keys()))
2678 # instances of autogenerated metric classes
2679 ag_results = model.eval_metrics(test_pool, list(metrics.values()))
2680
2681 for metric in metrics:
2682 assert np.allclose(td_results[metric], ag_results[metric]), "Different results for {}".format(metric)
2683
2684 if task not in ("ranking", "multiclassification", "multiregression", "survival_regression"):
2685 preds = model.predict(test_pool, prediction_type='RawFormulaVal')
2686 for metric, metric_obj in metrics.items():
2687 score = metric_obj.eval(test_pool.get_label(), preds)[0]
2688 assert np.abs(td_results[metric][-1] - score) < 1e-6, "Eval metric results differ for {}".format(metric)
2689
2690
2691def test_f1_vs_fbeta():

Calls 9

fitMethod · 0.95
eval_metricsMethod · 0.95
predictMethod · 0.95
CatBoostClass · 0.90
get_labelMethod · 0.80
absMethod · 0.80
listClass · 0.50
formatMethod · 0.45
evalMethod · 0.45

Tested by

no test coverage detected